Ability to save "sort order" in custom queries (#2899).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2572 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Vendored
+20
@@ -67,3 +67,23 @@ queries_004:
|
||||
|
||||
user_id: 2
|
||||
column_names:
|
||||
queries_005:
|
||||
id: 5
|
||||
project_id:
|
||||
is_public: true
|
||||
name: Open issues by priority and tracker
|
||||
filters: |
|
||||
status_id:
|
||||
:values:
|
||||
- "1"
|
||||
:operator: o
|
||||
|
||||
user_id: 1
|
||||
column_names:
|
||||
sort_criteria: |
|
||||
---
|
||||
- - priority
|
||||
- desc
|
||||
- - tracker
|
||||
- asc
|
||||
|
||||
@@ -111,6 +111,22 @@ class QueriesControllerTest < Test::Unit::TestCase
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_new_with_sort
|
||||
@request.session[:user_id] = 1
|
||||
post :new,
|
||||
:confirm => '1',
|
||||
:default_columns => '1',
|
||||
:operators => {"status_id" => "o"},
|
||||
:values => {"status_id" => ["1"]},
|
||||
:query => {:name => "test_new_with_sort",
|
||||
:is_public => "1",
|
||||
:sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
|
||||
|
||||
query = Query.find_by_name("test_new_with_sort")
|
||||
assert_not_nil query
|
||||
assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
|
||||
end
|
||||
|
||||
def test_get_edit_global_public_query
|
||||
@request.session[:user_id] = 1
|
||||
get :edit, :id => 4
|
||||
@@ -202,6 +218,19 @@ class QueriesControllerTest < Test::Unit::TestCase
|
||||
:disabled => 'disabled' }
|
||||
end
|
||||
|
||||
def test_get_edit_sort_criteria
|
||||
@request.session[:user_id] = 1
|
||||
get :edit, :id => 5
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
||||
:child => { :tag => 'option', :attributes => { :value => 'priority',
|
||||
:selected => 'selected' } }
|
||||
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
||||
:child => { :tag => 'option', :attributes => { :value => 'desc',
|
||||
:selected => 'selected' } }
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
post :destroy, :id => 1
|
||||
|
||||
@@ -195,6 +195,31 @@ class QueryTest < Test::Unit::TestCase
|
||||
assert q.has_column?(c)
|
||||
end
|
||||
|
||||
def test_default_sort
|
||||
q = Query.new
|
||||
assert_equal [], q.sort_criteria
|
||||
end
|
||||
|
||||
def test_set_sort_criteria_with_hash
|
||||
q = Query.new
|
||||
q.sort_criteria = {'0' => ['priority', 'desc'], '2' => ['tracker']}
|
||||
assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria
|
||||
end
|
||||
|
||||
def test_set_sort_criteria_with_array
|
||||
q = Query.new
|
||||
q.sort_criteria = [['priority', 'desc'], 'tracker']
|
||||
assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria
|
||||
end
|
||||
|
||||
def test_create_query_with_sort
|
||||
q = Query.new(:name => 'Sorted')
|
||||
q.sort_criteria = [['priority', 'desc'], 'tracker']
|
||||
assert q.save
|
||||
q.reload
|
||||
assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria
|
||||
end
|
||||
|
||||
def test_sort_by_string_custom_field_asc
|
||||
q = Query.new
|
||||
c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
|
||||
|
||||
Reference in New Issue
Block a user