Commit bfa264911a981947a47dcc17b1f67e5dc9136669
1 parent
d726e40e
Exists in
master
and in
29 other branches
cms_controller_test: use assert_select instead of assert_tag in certain tests
AI2762 Sadly, there is no way to use :checked in the css-like selectors used by assert_select, otherwise the new versions would be really neat.
Showing
1 changed file
with
49 additions
and
9 deletions
Show diff stats
test/functional/cms_controller_test.rb
@@ -600,8 +600,13 @@ class CmsControllerTest < ActionController::TestCase | @@ -600,8 +600,13 @@ class CmsControllerTest < ActionController::TestCase | ||
600 | article = profile.articles.create!(:name => 'test', :published => false) | 600 | article = profile.articles.create!(:name => 'test', :published => false) |
601 | 601 | ||
602 | get :edit, :profile => profile.identifier, :id => article.id | 602 | get :edit, :profile => profile.identifier, :id => article.id |
603 | - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'article[published]', :id => 'article_published_true' } | ||
604 | - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'article[published]', :id => 'article_published_false', :checked => 'checked' } | 603 | + assert_select 'input#article_published_true[name=?][type="radio"]', 'article[published]' |
604 | + assert_select 'input#article_published_false[name=?][type="radio"]', 'article[published]' do |elements| | ||
605 | + assert elements.length > 0 | ||
606 | + elements.each do |element| | ||
607 | + assert element["checked"] | ||
608 | + end | ||
609 | + end | ||
605 | end | 610 | end |
606 | 611 | ||
607 | should 'be able to add image with alignment' do | 612 | should 'be able to add image with alignment' do |
@@ -800,13 +805,23 @@ class CmsControllerTest < ActionController::TestCase | @@ -800,13 +805,23 @@ class CmsControllerTest < ActionController::TestCase | ||
800 | should 'display posts per page input with default value on edit blog' do | 805 | should 'display posts per page input with default value on edit blog' do |
801 | n = Blog.new.posts_per_page.to_s | 806 | n = Blog.new.posts_per_page.to_s |
802 | get :new, :profile => profile.identifier, :type => 'Blog' | 807 | get :new, :profile => profile.identifier, :type => 'Blog' |
803 | - assert_tag :tag => 'select', :attributes => { :name => 'article[posts_per_page]' }, :child => { :tag => 'option', :attributes => {:value => n, :selected => 'selected'} } | 808 | + assert_select 'select[name=?] option[value=?]', 'article[posts_per_page]', n do |elements| |
809 | + assert elements.length > 0 | ||
810 | + elements.each do |element| | ||
811 | + assert element["selected"] | ||
812 | + end | ||
813 | + end | ||
804 | end | 814 | end |
805 | 815 | ||
806 | should 'display options for blog visualization with default value on edit blog' do | 816 | should 'display options for blog visualization with default value on edit blog' do |
807 | format = Blog.new.visualization_format | 817 | format = Blog.new.visualization_format |
808 | get :new, :profile => profile.identifier, :type => 'Blog' | 818 | get :new, :profile => profile.identifier, :type => 'Blog' |
809 | - assert_tag :tag => 'select', :attributes => { :name => 'article[visualization_format]' }, :child => { :tag => 'option', :attributes => {:value => 'full', :selected => 'selected'} } | 819 | + assert_select 'select[name=?] option[value=full]', 'article[visualization_format]' do |elements| |
820 | + assert elements.length > 0 | ||
821 | + elements.each do |element| | ||
822 | + assert element["selected"] | ||
823 | + end | ||
824 | + end | ||
810 | end | 825 | end |
811 | 826 | ||
812 | should 'not offer to create special article types' do | 827 | should 'not offer to create special article types' do |
@@ -1028,7 +1043,12 @@ class CmsControllerTest < ActionController::TestCase | @@ -1028,7 +1043,12 @@ class CmsControllerTest < ActionController::TestCase | ||
1028 | profile.articles << Blog.new(:name => 'test blog', :profile => profile) | 1043 | profile.articles << Blog.new(:name => 'test blog', :profile => profile) |
1029 | profile.blog.create_external_feed(:address => 'address', :enabled => true) | 1044 | profile.blog.create_external_feed(:address => 'address', :enabled => true) |
1030 | get :edit, :profile => profile.identifier, :id => profile.blog.id | 1045 | get :edit, :profile => profile.identifier, :id => profile.blog.id |
1031 | - assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][enabled]', :checked => 'checked' } | 1046 | + assert_select 'input[type=checkbox][name=?]', 'article[external_feed_builder][enabled]' do |elements| |
1047 | + elements.length > 0 | ||
1048 | + elements.each do |element| | ||
1049 | + assert element["checked"] | ||
1050 | + end | ||
1051 | + end | ||
1032 | end | 1052 | end |
1033 | 1053 | ||
1034 | should "display 'Fetch posts from an external feed' unchecked if blog has disabled external feed" do | 1054 | should "display 'Fetch posts from an external feed' unchecked if blog has disabled external feed" do |
@@ -1046,7 +1066,12 @@ class CmsControllerTest < ActionController::TestCase | @@ -1046,7 +1066,12 @@ class CmsControllerTest < ActionController::TestCase | ||
1046 | 1066 | ||
1047 | should 'only_once option marked by default' do | 1067 | should 'only_once option marked by default' do |
1048 | get :new, :profile => profile.identifier, :type => 'Blog' | 1068 | get :new, :profile => profile.identifier, :type => 'Blog' |
1049 | - assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' } | 1069 | + assert_select 'input[name=?][value="true"]', 'article[external_feed_builder][only_once]' do |elements| |
1070 | + assert elements.length > 0 | ||
1071 | + elements.each do |element| | ||
1072 | + assert element['checked'] | ||
1073 | + end | ||
1074 | + end | ||
1050 | end | 1075 | end |
1051 | 1076 | ||
1052 | should 'display media listing when it is TinyMceArticle and enabled on environment' do | 1077 | should 'display media listing when it is TinyMceArticle and enabled on environment' do |
@@ -1202,7 +1227,12 @@ class CmsControllerTest < ActionController::TestCase | @@ -1202,7 +1227,12 @@ class CmsControllerTest < ActionController::TestCase | ||
1202 | should 'display posts per page input with default value on edit forum' do | 1227 | should 'display posts per page input with default value on edit forum' do |
1203 | n = Forum.new.posts_per_page.to_s | 1228 | n = Forum.new.posts_per_page.to_s |
1204 | get :new, :profile => profile.identifier, :type => 'Forum' | 1229 | get :new, :profile => profile.identifier, :type => 'Forum' |
1205 | - assert_tag :tag => 'select', :attributes => { :name => 'article[posts_per_page]' }, :child => { :tag => 'option', :attributes => {:value => n, :selected => 'selected'} } | 1230 | + assert_select 'select[name=?] option[value=?]', 'article[posts_per_page]', n do |elements| |
1231 | + assert elements.length > 0 | ||
1232 | + elements.each do |element| | ||
1233 | + assert element['selected'] | ||
1234 | + end | ||
1235 | + end | ||
1206 | end | 1236 | end |
1207 | 1237 | ||
1208 | should 'offer to edit a forum' do | 1238 | should 'offer to edit a forum' do |
@@ -1370,7 +1400,12 @@ class CmsControllerTest < ActionController::TestCase | @@ -1370,7 +1400,12 @@ class CmsControllerTest < ActionController::TestCase | ||
1370 | should 'display display posts in current language input checked when editing blog' do | 1400 | should 'display display posts in current language input checked when editing blog' do |
1371 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile, :display_posts_in_current_language => true) | 1401 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile, :display_posts_in_current_language => true) |
1372 | get :edit, :profile => profile.identifier, :id => profile.blog.id | 1402 | get :edit, :profile => profile.identifier, :id => profile.blog.id |
1373 | - assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[display_posts_in_current_language]', :checked => 'checked' } | 1403 | + assert_select 'input[type=checkbox][name=?]', 'article[display_posts_in_current_language]' do |elements| |
1404 | + assert elements.length > 0 | ||
1405 | + elements.each do |element| | ||
1406 | + assert element["checked"] | ||
1407 | + end | ||
1408 | + end | ||
1374 | end | 1409 | end |
1375 | 1410 | ||
1376 | should 'display display posts in current language input not checked on new blog' do | 1411 | should 'display display posts in current language input not checked on new blog' do |
@@ -1395,7 +1430,12 @@ class CmsControllerTest < ActionController::TestCase | @@ -1395,7 +1430,12 @@ class CmsControllerTest < ActionController::TestCase | ||
1395 | should 'be checked display posts in current language checkbox' do | 1430 | should 'be checked display posts in current language checkbox' do |
1396 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile, :display_posts_in_current_language => true) | 1431 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile, :display_posts_in_current_language => true) |
1397 | get :edit, :profile => profile.identifier, :id => profile.blog.id | 1432 | get :edit, :profile => profile.identifier, :id => profile.blog.id |
1398 | - assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[display_posts_in_current_language]', :checked => 'checked' } | 1433 | + assert_select 'input[type=checkbox][name=?]', 'article[display_posts_in_current_language]' do |elements| |
1434 | + assert elements.length > 0 | ||
1435 | + elements.each do |element| | ||
1436 | + assert element["checked"] | ||
1437 | + end | ||
1438 | + end | ||
1399 | end | 1439 | end |
1400 | 1440 | ||
1401 | should 'be unchecked display posts in current language checkbox' do | 1441 | should 'be unchecked display posts in current language checkbox' do |