Sort queries alphabetically

This commit is contained in:
Gerhard Schlager 2018-02-23 15:01:50 +01:00
parent dce36b5f4f
commit 4de3b1dcb9
2 changed files with 9 additions and 9 deletions

View File

@ -666,8 +666,8 @@ SQL
.where("key LIKE 'q:%'")
.where("key != 'q:_id'")
.map do |psr|
DataExplorer::Query.from_hash PluginStore.cast_value(psr.type_name, psr.value)
end
DataExplorer::Query.from_hash PluginStore.cast_value(psr.type_name, psr.value)
end.sort_by { |query| query.name }
end
def self.destroy_all

View File

@ -13,10 +13,10 @@ describe DataExplorer::QueryController do
let!(:admin) { log_in_user(Fabricate(:admin)) }
def make_query(sql = 'SELECT 1 as value')
def make_query(sql, opts = {})
q = DataExplorer::Query.new
q.id = Fabrication::Sequencer.sequence("query-id", 1)
q.name = "Query number #{q.id}"
q.name = opts[:name] || "Query number #{q.id}"
q.description = "A description for query number #{q.id}"
q.sql = sql
q.save
@ -62,15 +62,15 @@ describe DataExplorer::QueryController do
expect(response_json['queries']).to eq([])
end
it "shows all available queries" do
it "shows all available queries in alphabetical order" do
DataExplorer::Query.destroy_all
q1 = make_query
q2 = make_query
make_query('SELECT 1 as value', name: 'B')
make_query('SELECT 1 as value', name: 'A')
get :index, format: :json
expect(response).to be_success
expect(response_json['queries'].length).to eq(2)
expect(response_json['queries'][0]['name']).to eq(q1.name)
expect(response_json['queries'][1]['name']).to eq(q2.name)
expect(response_json['queries'][0]['name']).to eq('A')
expect(response_json['queries'][1]['name']).to eq('B')
end
end