diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-11-22 09:38:21 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-11-22 09:38:21 +0000 |
commit | f3e573b5f891c71f9395562a3f8747ecec801091 (patch) | |
tree | 7987fd3efa8ae985b532a03e7e0f529fa997258d /test/functional/wiki_controller_test.rb | |
parent | 3602cd637c9ece4e0caa42c335acb7dce719a20e (diff) | |
download | redmine-f3e573b5f891c71f9395562a3f8747ecec801091.tar.gz redmine-f3e573b5f891c71f9395562a3f8747ecec801091.zip |
Replaced remaining #assert_tag with #assert_select.
git-svn-id: http://svn.redmine.org/redmine/trunk@13624 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/wiki_controller_test.rb')
-rw-r--r-- | test/functional/wiki_controller_test.rb | 171 |
1 files changed, 64 insertions, 107 deletions
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 19bfa78e8..d16a1559c 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -31,31 +31,28 @@ class WikiControllerTest < ActionController::TestCase get :show, :project_id => 'ecookbook' assert_response :success assert_template 'show' - assert_tag :tag => 'h1', :content => /CookBook documentation/ + assert_select 'h1', :text => /CookBook documentation/ # child_pages macro - assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, - :child => { :tag => 'li', - :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, - :content => 'Page with an inline image' } } + assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', + :text => 'Page with an inline image' end def test_export_link Role.anonymous.add_permission! :export_wiki_pages get :show, :project_id => 'ecookbook' assert_response :success - assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'} + assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt' end def test_show_page_with_name get :show, :project_id => 1, :id => 'Another_page' assert_response :success assert_template 'show' - assert_tag :tag => 'h1', :content => /Another page/ + assert_select 'h1', :text => /Another page/ # Included page with an inline image - assert_tag :tag => 'p', :content => /This is an inline image/ - assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3/logo.gif', - :alt => 'This is a logo' } + assert_select 'p', :text => /This is an inline image/ + assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo' end def test_show_old_version @@ -118,40 +115,30 @@ class WikiControllerTest < ActionController::TestCase get :show, :project_id => 1, :id => 'Another_page' assert_response :success - assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, - :content => /Side bar content for test_show_with_sidebar/ + assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/ end def test_show_should_display_section_edit_links @request.session[:user_id] = 2 get :show, :project_id => 1, :id => 'Page with sections' - assert_no_tag 'a', :attributes => { - :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1' - } - assert_tag 'a', :attributes => { - :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' - } - assert_tag 'a', :attributes => { - :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' - } + + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0 + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' end def test_show_current_version_should_display_section_edit_links @request.session[:user_id] = 2 get :show, :project_id => 1, :id => 'Page with sections', :version => 3 - assert_tag 'a', :attributes => { - :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' - } + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' end def test_show_old_version_should_not_display_section_edit_links @request.session[:user_id] = 2 get :show, :project_id => 1, :id => 'Page with sections', :version => 2 - assert_no_tag 'a', :attributes => { - :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' - } + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0 end def test_show_unexistent_page_without_edit_right @@ -176,8 +163,7 @@ class WikiControllerTest < ActionController::TestCase get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' assert_response :success assert_template 'edit' - assert_tag 'select', :attributes => {:name => 'wiki_page[parent_id]'}, - :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}} + assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]' end def test_show_should_not_show_history_without_permission @@ -251,9 +237,8 @@ class WikiControllerTest < ActionController::TestCase assert_response :success assert_template 'edit' - assert_tag 'textarea', - :attributes => { :name => 'content[text]' }, - :content => "\n"+WikiPage.find_by_title('Another_page').content.text + assert_select 'textarea[name=?]', 'content[text]', + :text => WikiPage.find_by_title('Another_page').content.text end def test_edit_section @@ -266,13 +251,9 @@ class WikiControllerTest < ActionController::TestCase page = WikiPage.find_by_title('Page_with_sections') section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) - assert_tag 'textarea', - :attributes => { :name => 'content[text]' }, - :content => "\n"+section - assert_tag 'input', - :attributes => { :name => 'section', :type => 'hidden', :value => '2' } - assert_tag 'input', - :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash } + assert_select 'textarea[name=?]', 'content[text]', :text => section + assert_select 'input[name=section][type=hidden][value="2"]' + assert_select 'input[name=section_hash][type=hidden][value=?]', hash end def test_edit_invalid_section_should_respond_with_404 @@ -348,9 +329,9 @@ class WikiControllerTest < ActionController::TestCase assert_response :success assert_template 'edit' - assert_error_tag :descendant => {:content => /Comment is too long/} - assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => "\nedited" - assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} + assert_select_error /Comment is too long/ + assert_select 'textarea#content_text', :text => "edited" + assert_select 'input#content_version[value="1"]' end def test_update_page_with_parent_change_only_should_not_create_content_version @@ -418,14 +399,9 @@ class WikiControllerTest < ActionController::TestCase end assert_response :success assert_template 'edit' - assert_tag :div, - :attributes => { :class => /error/ }, - :content => /Data has been updated by another user/ - assert_tag 'textarea', - :attributes => { :name => 'content[text]' }, - :content => /Text should not be lost/ - assert_tag 'input', - :attributes => { :name => 'content[comments]', :value => 'My comments' } + assert_select 'div.error', :text => /Data has been updated by another user/ + assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ + assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' c.reload assert_equal 'Previous text', c.text @@ -512,14 +488,9 @@ class WikiControllerTest < ActionController::TestCase end assert_response :success assert_template 'edit' - assert_tag :div, - :attributes => { :class => /error/ }, - :content => /Data has been updated by another user/ - assert_tag 'textarea', - :attributes => { :name => 'content[text]' }, - :content => /Text should not be lost/ - assert_tag 'input', - :attributes => { :name => 'content[comments]', :value => 'My comments' } + assert_select 'div.error', :text => /Data has been updated by another user/ + assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ + assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' end def test_preview @@ -530,7 +501,7 @@ class WikiControllerTest < ActionController::TestCase :version => 3 } assert_response :success assert_template 'common/_preview' - assert_tag :tag => 'strong', :content => /previewed text/ + assert_select 'strong', :text => /previewed text/ end def test_preview_new_page @@ -541,7 +512,7 @@ class WikiControllerTest < ActionController::TestCase :version => 0 } assert_response :success assert_template 'common/_preview' - assert_tag :tag => 'h1', :content => /New page/ + assert_select 'h1', :text => /New page/ end def test_history @@ -607,22 +578,18 @@ class WikiControllerTest < ActionController::TestCase assert_template 'annotate' # Line 1 - assert_tag :tag => 'tr', :child => { - :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { - :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { - :tag => 'td', :content => /h1\. CookBook documentation/ - } - } - } + assert_select 'table.annotate tr:nth-child(1)' do + assert_select 'th.line-num', :text => '1' + assert_select 'td.author', :text => /John Smith/ + assert_select 'td', :text => /h1\. CookBook documentation/ + end # Line 5 - assert_tag :tag => 'tr', :child => { - :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { - :tag => 'td', :attributes => {:class => 'author'}, :content => /Redmine Admin/, :sibling => { - :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ - } - } - } + assert_select 'table.annotate tr:nth-child(5)' do + assert_select 'th.line-num', :text => '5' + assert_select 'td.author', :text => /Redmine Admin/ + assert_select 'td', :text => /Some updated \[\[documentation\]\] here/ + end end def test_annotate_with_invalid_version_should_respond_with_404 @@ -635,13 +602,11 @@ class WikiControllerTest < ActionController::TestCase get :rename, :project_id => 1, :id => 'Another_page' assert_response :success assert_template 'rename' - assert_tag 'option', - :attributes => {:value => ''}, - :content => '', - :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} - assert_no_tag 'option', - :attributes => {:selected => 'selected'}, - :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} + + assert_select 'select[name=?]', 'wiki_page[parent_id]' do + assert_select 'option[value=""]', :text => '' + assert_select 'option[selected=selected]', 0 + end end def test_get_rename_child_page @@ -649,17 +614,11 @@ class WikiControllerTest < ActionController::TestCase get :rename, :project_id => 1, :id => 'Child_1' assert_response :success assert_template 'rename' - assert_tag 'option', - :attributes => {:value => ''}, - :content => '', - :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} - assert_tag 'option', - :attributes => {:value => '2', :selected => 'selected'}, - :content => /Another page/, - :parent => { - :tag => 'select', - :attributes => {:name => 'wiki_page[parent_id]'} - } + + assert_select 'select[name=?]', 'wiki_page[parent_id]' do + assert_select 'option[value=""]', :text => '' + assert_select 'option[value="2"][selected=selected]', :text => /Another page/ + end end def test_rename_with_redirect @@ -771,20 +730,18 @@ class WikiControllerTest < ActionController::TestCase assert_equal Project.find(1).wiki.pages.size, pages.size assert_equal pages.first.content.updated_on, pages.first.updated_on - assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, - :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, - :content => 'CookBook documentation' }, - :child => { :tag => 'ul', - :child => { :tag => 'li', - :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, - :content => 'Page with an inline image' } } } }, - :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, - :content => 'Another page' } } + assert_select 'ul.pages-hierarchy' do + assert_select 'li' do + assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation' + assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image' + end + assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page' + end end def test_index_should_include_atom_link get :index, :project_id => 'ecookbook' - assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} + assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' end def test_export_to_html @@ -829,7 +786,7 @@ class WikiControllerTest < ActionController::TestCase assert_not_nil assigns(:pages) assert_not_nil assigns(:pages_by_date) - assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} + assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' end def test_not_found @@ -860,7 +817,7 @@ class WikiControllerTest < ActionController::TestCase get :show, :project_id => 1 assert_response :success assert_template 'show' - assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } + assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit' end def test_show_page_without_edit_link @@ -868,7 +825,7 @@ class WikiControllerTest < ActionController::TestCase get :show, :project_id => 1 assert_response :success assert_template 'show' - assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } + assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0 end def test_show_pdf @@ -889,7 +846,7 @@ class WikiControllerTest < ActionController::TestCase assert_equal 'text/html', @response.content_type assert_equal 'attachment; filename="CookBook_documentation.html"', @response.headers['Content-Disposition'] - assert_tag 'h1', :content => 'CookBook documentation' + assert_select 'h1', :text => /CookBook documentation/ end def test_show_versioned_html @@ -901,7 +858,7 @@ class WikiControllerTest < ActionController::TestCase assert_equal 'text/html', @response.content_type assert_equal 'attachment; filename="CookBook_documentation.html"', @response.headers['Content-Disposition'] - assert_tag 'h1', :content => 'CookBook documentation' + assert_select 'h1', :text => /CookBook documentation/ end def test_show_txt |