Tests cleanup, use #assert_select instead of #assert_tag.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10631 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-10-13 09:54:31 +00:00
parent 5d9bdf888a
commit 55dbd8886f
1 changed files with 112 additions and 85 deletions

View File

@ -655,10 +655,11 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal columns, session[:query][:column_names].map(&:to_s) assert_equal columns, session[:query][:column_names].map(&:to_s)
# ensure only these columns are kept in the selected columns list # ensure only these columns are kept in the selected columns list
assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' }, assert_select 'select#selected_columns option' do
:children => { :count => 3 } assert_select 'option', 3
assert_no_tag :tag => 'option', :attributes => { :value => 'project' }, assert_select 'option[value=tracker]'
:parent => { :tag => 'select', :attributes => { :id => "selected_columns" } } assert_select 'option[value=project]', 0
end
end end
def test_index_without_project_should_implicitly_add_project_column_to_default_columns def test_index_without_project_should_implicitly_add_project_column_to_default_columns
@ -692,9 +693,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_kind_of Query, query assert_kind_of Query, query
assert_equal columns, query.column_names.map(&:to_s) assert_equal columns, query.column_names.map(&:to_s)
assert_tag :td, assert_select 'table.issues td.cf_2.string'
:attributes => {:class => 'cf_2 string'},
:ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
end end
def test_index_with_multi_custom_field_column def test_index_with_multi_custom_field_column
@ -707,9 +706,7 @@ class IssuesControllerTest < ActionController::TestCase
get :index, :set_filter => 1, :c => %w(tracker subject cf_1) get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
assert_response :success assert_response :success
assert_tag :td, assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
:attributes => {:class => /cf_1/},
:content => 'MySQL, Oracle'
end end
def test_index_with_multi_user_custom_field_column def test_index_with_multi_user_custom_field_column
@ -722,17 +719,20 @@ class IssuesControllerTest < ActionController::TestCase
get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"] get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
assert_response :success assert_response :success
assert_tag :td, assert_select "table.issues td.cf_#{field.id}" do
:attributes => {:class => /cf_#{field.id}/}, assert_select 'a', 2
:child => {:tag => 'a', :content => 'John Smith'} assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
end
end end
def test_index_with_date_column def test_index_with_date_column
Issue.find(1).update_attribute :start_date, '1987-08-24'
with_settings :date_format => '%d/%m/%Y' do with_settings :date_format => '%d/%m/%Y' do
Issue.find(1).update_attribute :start_date, '1987-08-24'
get :index, :set_filter => 1, :c => %w(start_date) get :index, :set_filter => 1, :c => %w(start_date)
assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
assert_select "table.issues td.start_date", :text => '24/08/1987'
end end
end end
@ -740,32 +740,33 @@ class IssuesControllerTest < ActionController::TestCase
Issue.find(1).update_attribute :done_ratio, 40 Issue.find(1).update_attribute :done_ratio, 40
get :index, :set_filter => 1, :c => %w(done_ratio) get :index, :set_filter => 1, :c => %w(done_ratio)
assert_tag 'td', :attributes => {:class => /done_ratio/},
:child => {:tag => 'table', :attributes => {:class => 'progress'}, assert_select 'table.issues td.done_ratio' do
:descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}} assert_select 'table.progress' do
} assert_select 'td.closed[style=?]', 'width: 40%;'
end
end
end end
def test_index_with_spent_hours_column def test_index_with_spent_hours_column
get :index, :set_filter => 1, :c => %w(subject spent_hours) get :index, :set_filter => 1, :c => %w(subject spent_hours)
assert_tag 'tr', :attributes => {:id => 'issue-3'}, assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
:child => {
:tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
}
end end
def test_index_should_not_show_spent_hours_column_without_permission def test_index_should_not_show_spent_hours_column_without_permission
Role.anonymous.remove_permission! :view_time_entries Role.anonymous.remove_permission! :view_time_entries
get :index, :set_filter => 1, :c => %w(subject spent_hours) get :index, :set_filter => 1, :c => %w(subject spent_hours)
assert_no_tag 'td', :attributes => {:class => /spent_hours/} assert_select 'td.spent_hours', 0
end end
def test_index_with_fixed_version_column def test_index_with_fixed_version_column
get :index, :set_filter => 1, :c => %w(fixed_version) get :index, :set_filter => 1, :c => %w(fixed_version)
assert_tag 'td', :attributes => {:class => /fixed_version/},
:child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}} assert_select 'table.issues td.fixed_version' do
assert_select 'a[href=?]', '/versions/2', :text => '1.0'
end
end end
def test_index_with_relations_column def test_index_with_relations_column
@ -820,16 +821,17 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:issue)
assert_equal Issue.find(1), assigns(:issue) assert_equal Issue.find(1), assigns(:issue)
# anonymous role is allowed to add a note # anonymous role is allowed to add a note
assert_tag :tag => 'form', assert_select 'form#issue-form' do
:descendant => { :tag => 'fieldset', assert_select 'fieldset' do
:child => { :tag => 'legend', assert_select 'legend', :text => 'Notes'
:content => /Notes/ } } assert_select 'textarea[name=?]', 'issue[notes]'
assert_tag :tag => 'title', end
:content => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine" end
assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
end end
def test_show_by_manager def test_show_by_manager
@ -837,19 +839,22 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert_tag :tag => 'a', assert_select 'a', :text => /Quote/
:content => /Quote/
assert_tag :tag => 'form', assert_select 'form#issue-form' do
:descendant => { :tag => 'fieldset', assert_select 'fieldset' do
:child => { :tag => 'legend', assert_select 'legend', :text => 'Change properties'
:content => /Change properties/ } }, assert_select 'input[name=?]', 'issue[subject]'
:descendant => { :tag => 'fieldset', end
:child => { :tag => 'legend', assert_select 'fieldset' do
:content => /Log time/ } }, assert_select 'legend', :text => 'Log time'
:descendant => { :tag => 'fieldset', assert_select 'input[name=?]', 'time_entry[hours]'
:child => { :tag => 'legend', end
:content => /Notes/ } } assert_select 'fieldset' do
assert_select 'legend', :text => 'Notes'
assert_select 'textarea[name=?]', 'issue[notes]'
end
end
end end
def test_show_should_display_update_form def test_show_should_display_update_form
@ -939,29 +944,31 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert_no_tag 'form', :attributes => {:id => 'issue-form'} assert_select 'form#issue-form', 0
end end
def test_update_form_should_not_display_inactive_enumerations def test_update_form_should_not_display_inactive_enumerations
assert !IssuePriority.find(15).active?
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert ! IssuePriority.find(15).active? assert_select 'form#issue-form' do
assert_no_tag :option, :attributes => {:value => '15'}, assert_select 'select[name=?]', 'issue[priority_id]' do
:parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } assert_select 'option[value=4]'
assert_select 'option[value=15]', 0
end
end
end end
def test_update_form_should_allow_attachment_upload def test_update_form_should_allow_attachment_upload
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, :id => 1 get :show, :id => 1
assert_tag :tag => 'form', assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
:attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, assert_select 'input[type=file][name=?]', 'attachments[1][file]'
:descendant => { end
:tag => 'input',
:attributes => {:type => 'file', :name => 'attachments[1][file]'}
}
end end
def test_show_should_deny_anonymous_access_without_permission def test_show_should_deny_anonymous_access_without_permission
@ -1035,10 +1042,10 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert_tag :div, :attributes => { :id => 'relations' }, assert_select 'div#relations' do
:descendant => { :tag => 'a', :content => /#2$/ } assert_select 'a', :text => /#2$/
assert_no_tag :div, :attributes => { :id => 'relations' }, assert_select 'a', :text => /#4$/, :count => 0
:descendant => { :tag => 'a', :content => /#4$/ } end
end end
def test_show_should_list_subtasks def test_show_should_list_subtasks
@ -1046,8 +1053,10 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert_tag 'div', :attributes => {:id => 'issue_tree'},
:descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}} assert_select 'div#issue_tree' do
assert_select 'td.subject', :text => /Child Issue/
end
end end
def test_show_should_list_parents def test_show_should_list_parents
@ -1055,10 +1064,11 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => issue.id get :show, :id => issue.id
assert_response :success assert_response :success
assert_tag 'div', :attributes => {:class => 'subject'},
:descendant => {:tag => 'h3', :content => 'Child Issue'} assert_select 'div.subject' do
assert_tag 'div', :attributes => {:class => 'subject'}, assert_select 'h3', 'Child Issue'
:descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}} assert_select 'a[href=/issues/1]'
end
end end
def test_show_should_not_display_prev_next_links_without_query_in_session def test_show_should_not_display_prev_next_links_without_query_in_session
@ -1067,7 +1077,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_nil assigns(:prev_issue_id) assert_nil assigns(:prev_issue_id)
assert_nil assigns(:next_issue_id) assert_nil assigns(:next_issue_id)
assert_no_tag 'div', :attributes => {:class => /next-prev-links/} assert_select 'div.next-prev-links', 0
end end
def test_show_should_display_prev_next_links_with_query_in_session def test_show_should_display_prev_next_links_with_query_in_session
@ -1083,12 +1093,13 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 2, assigns(:prev_issue_id) assert_equal 2, assigns(:prev_issue_id)
assert_equal 5, assigns(:next_issue_id) assert_equal 5, assigns(:next_issue_id)
assert_tag 'div', :attributes => {:class => /next-prev-links/}
assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
count = Issue.open.visible.count count = Issue.open.visible.count
assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
assert_select 'div.next-prev-links' do
assert_select 'a[href=/issues/2]', :text => /Previous/
assert_select 'a[href=/issues/5]', :text => /Next/
assert_select 'span.position', :text => "3 of #{count}"
end
end end
def test_show_should_display_prev_next_links_with_saved_query_in_session def test_show_should_display_prev_next_links_with_saved_query_in_session
@ -1105,8 +1116,10 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 8, assigns(:prev_issue_id) assert_equal 8, assigns(:prev_issue_id)
assert_equal 12, assigns(:next_issue_id) assert_equal 12, assigns(:next_issue_id)
assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/ assert_select 'div.next-prev-links' do
assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/ assert_select 'a[href=/issues/8]', :text => /Previous/
assert_select 'a[href=/issues/12]', :text => /Next/
end
end end
def test_show_should_display_prev_next_links_with_query_and_sort_on_association def test_show_should_display_prev_next_links_with_query_and_sort_on_association
@ -1118,8 +1131,10 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 3 get :show, :id => 3
assert_response :success, "Wrong response status for #{assoc_sort} sort" assert_response :success, "Wrong response status for #{assoc_sort} sort"
assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/ assert_select 'div.next-prev-links' do
assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/ assert_select 'a', :text => /Previous/
assert_select 'a', :text => /Next/
end
end end
end end
@ -1136,8 +1151,10 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 2, assigns(:prev_issue_id) assert_equal 2, assigns(:prev_issue_id)
assert_equal 7, assigns(:next_issue_id) assert_equal 7, assigns(:next_issue_id)
assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/ assert_select 'div.next-prev-links' do
assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/ assert_select 'a[href=/issues/2]', :text => /Previous/
assert_select 'a[href=/issues/7]', :text => /Next/
end
end end
def test_show_should_not_display_prev_link_for_first_issue def test_show_should_not_display_prev_link_for_first_issue
@ -1152,8 +1169,10 @@ class IssuesControllerTest < ActionController::TestCase
assert_nil assigns(:prev_issue_id) assert_nil assigns(:prev_issue_id)
assert_equal 2, assigns(:next_issue_id) assert_equal 2, assigns(:next_issue_id)
assert_no_tag 'a', :content => /Previous/ assert_select 'div.next-prev-links' do
assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/ assert_select 'a', :text => /Previous/, :count => 0
assert_select 'a[href=/issues/2]', :text => /Next/
end
end end
def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
@ -1166,8 +1185,8 @@ class IssuesControllerTest < ActionController::TestCase
assert_nil assigns(:prev_issue_id) assert_nil assigns(:prev_issue_id)
assert_nil assigns(:next_issue_id) assert_nil assigns(:next_issue_id)
assert_no_tag 'a', :content => /Previous/ assert_select 'a', :text => /Previous/, :count => 0
assert_no_tag 'a', :content => /Next/ assert_select 'a', :text => /Next/, :count => 0
end end
def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
@ -1186,6 +1205,11 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 2, assigns(:prev_issue_id) assert_equal 2, assigns(:prev_issue_id)
assert_equal 1, assigns(:next_issue_id) assert_equal 1, assigns(:next_issue_id)
assert_select 'div.next-prev-links' do
assert_select 'a[href=/issues/2]', :text => /Previous/
assert_select 'a[href=/issues/1]', :text => /Next/
end
end end
def test_show_should_display_link_to_the_assignee def test_show_should_display_link_to_the_assignee
@ -1201,11 +1225,14 @@ class IssuesControllerTest < ActionController::TestCase
issue = project.issues.first issue = project.issues.first
issue.changeset_ids = [102] issue.changeset_ids = [102]
issue.save! issue.save!
# changesets from other projects should be displayed even if repository
# is disabled on issue's project
project.disable_module! :repository project.disable_module! :repository
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, :id => issue.id get :show, :id => issue.id
assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"}
assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
end end
def test_show_should_display_watchers def test_show_should_display_watchers
@ -1274,7 +1301,7 @@ class IssuesControllerTest < ActionController::TestCase
get :show, :id => 1 get :show, :id => 1
assert_response :success assert_response :success
assert_tag :td, :content => 'MySQL, Oracle' assert_select 'td', :text => 'MySQL, Oracle'
end end
def test_show_with_multi_user_custom_field def test_show_with_multi_user_custom_field
@ -1288,7 +1315,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_response :success assert_response :success
# TODO: should display links # TODO: should display links
assert_tag :td, :content => 'Dave Lopper, John Smith' assert_select 'td', :text => 'Dave Lopper, John Smith'
end end
def test_show_should_display_private_notes_with_permission_only def test_show_should_display_private_notes_with_permission_only