Commit c4affd13a72a6afcb0420d6e2dde5411b8792ef4
Committed by
Daniela Feitosa
1 parent
3f54dc4f
Exists in
master
and in
28 other branches
Moving all testing fake helper methods to test_helper
Showing
9 changed files
with
46 additions
and
115 deletions
Show diff stats
test/test_helper.rb
| @@ -233,8 +233,9 @@ module NoosferoTestHelper | @@ -233,8 +233,9 @@ module NoosferoTestHelper | ||
| 233 | '' | 233 | '' |
| 234 | end | 234 | end |
| 235 | 235 | ||
| 236 | - def tag(tag) | ||
| 237 | - "<#{tag}/>" | 236 | + def tag(tag, args = {}) |
| 237 | + attrs = args.map{|k,v| "#{k}='#{v}'"}.join(' ') | ||
| 238 | + "<#{tag} #{attrs} />" | ||
| 238 | end | 239 | end |
| 239 | 240 | ||
| 240 | def options_from_collection_for_select(collection, value_method, content_method) | 241 | def options_from_collection_for_select(collection, value_method, content_method) |
| @@ -245,7 +246,7 @@ module NoosferoTestHelper | @@ -245,7 +246,7 @@ module NoosferoTestHelper | ||
| 245 | "<select id='#{id}'>fake content</select>" | 246 | "<select id='#{id}'>fake content</select>" |
| 246 | end | 247 | end |
| 247 | 248 | ||
| 248 | - def options_for_select(collection) | 249 | + def options_for_select(collection, selected = nil) |
| 249 | collection.map{|item| "<option value='#{item[1]}'>#{item[0]}</option>"}.join("\n") | 250 | collection.map{|item| "<option value='#{item[1]}'>#{item[0]}</option>"}.join("\n") |
| 250 | end | 251 | end |
| 251 | 252 | ||
| @@ -259,6 +260,35 @@ module NoosferoTestHelper | @@ -259,6 +260,35 @@ module NoosferoTestHelper | ||
| 259 | 260 | ||
| 260 | def will_paginate(arg1, arg2) | 261 | def will_paginate(arg1, arg2) |
| 261 | end | 262 | end |
| 263 | + | ||
| 264 | + def url_for(args = {}) | ||
| 265 | + args | ||
| 266 | + end | ||
| 267 | + def javascript_tag(any) | ||
| 268 | + '' | ||
| 269 | + end | ||
| 270 | + def javascript_include_tag(any) | ||
| 271 | + '' | ||
| 272 | + end | ||
| 273 | + def check_box_tag(name, value = 1, checked = false, options = {}) | ||
| 274 | + name | ||
| 275 | + end | ||
| 276 | + def stylesheet_link_tag(arg) | ||
| 277 | + arg | ||
| 278 | + end | ||
| 279 | + | ||
| 280 | + def show_date(date) | ||
| 281 | + date.to_s | ||
| 282 | + end | ||
| 283 | + | ||
| 284 | + def strip_tags(html) | ||
| 285 | + html.gsub(/<[^>]+>/, '') | ||
| 286 | + end | ||
| 287 | + | ||
| 288 | + def icon_for_article(article) | ||
| 289 | + '' | ||
| 290 | + end | ||
| 291 | + | ||
| 262 | end | 292 | end |
| 263 | 293 | ||
| 264 | class ActionController::IntegrationTest | 294 | class ActionController::IntegrationTest |
test/unit/application_helper_test.rb
| @@ -89,7 +89,7 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -89,7 +89,7 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 89 | person = create_user('usertest').person | 89 | person = create_user('usertest').person |
| 90 | community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id) | 90 | community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id) |
| 91 | community.add_member(person) | 91 | community.add_member(person) |
| 92 | - assert_equal 'Profile Administrator', rolename_for(person, community) | 92 | + assert_tag_in_string rolename_for(person, community), :tag => 'span', :content => 'Profile Administrator' |
| 93 | end | 93 | end |
| 94 | 94 | ||
| 95 | should 'rolename for a member' do | 95 | should 'rolename for a member' do |
| @@ -98,7 +98,7 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -98,7 +98,7 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 98 | community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id) | 98 | community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id) |
| 99 | community.add_member(member1) | 99 | community.add_member(member1) |
| 100 | community.add_member(member2) | 100 | community.add_member(member2) |
| 101 | - assert_equal 'Profile Member', rolename_for(member2, community) | 101 | + assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Member' |
| 102 | end | 102 | end |
| 103 | 103 | ||
| 104 | should 'get theme from environment by default' do | 104 | should 'get theme from environment by default' do |
| @@ -608,27 +608,6 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -608,27 +608,6 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 608 | end | 608 | end |
| 609 | 609 | ||
| 610 | protected | 610 | protected |
| 611 | - | ||
| 612 | - def url_for(args = {}) | ||
| 613 | - args | ||
| 614 | - end | ||
| 615 | - def content_tag(tag, content, options = {}) | ||
| 616 | - content.strip | ||
| 617 | - end | ||
| 618 | - def javascript_tag(any) | ||
| 619 | - '' | ||
| 620 | - end | ||
| 621 | - def javascript_include_tag(any) | ||
| 622 | - '' | ||
| 623 | - end | ||
| 624 | - def link_to(label, action, options = {}) | ||
| 625 | - label | ||
| 626 | - end | ||
| 627 | - def check_box_tag(name, value = 1, checked = false, options = {}) | ||
| 628 | - name | ||
| 629 | - end | ||
| 630 | - def stylesheet_link_tag(arg) | ||
| 631 | - arg | ||
| 632 | - end | 611 | + include NoosferoTestHelper |
| 633 | 612 | ||
| 634 | end | 613 | end |
test/unit/blog_helper_test.rb
| @@ -113,20 +113,6 @@ class BlogHelperTest < Test::Unit::TestCase | @@ -113,20 +113,6 @@ class BlogHelperTest < Test::Unit::TestCase | ||
| 113 | end | 113 | end |
| 114 | 114 | ||
| 115 | protected | 115 | protected |
| 116 | + include NoosferoTestHelper | ||
| 116 | 117 | ||
| 117 | - def will_paginate(arg1, arg2) | ||
| 118 | - end | ||
| 119 | - | ||
| 120 | - def link_to(content, url) | ||
| 121 | - content | ||
| 122 | - end | ||
| 123 | - | ||
| 124 | - def tag(tag, args = {}) | ||
| 125 | - attrs = args.map{|k,v| "#{k}='#{v}'"}.join(' ') | ||
| 126 | - "<#{tag} #{attrs} />" | ||
| 127 | - end | ||
| 128 | - | ||
| 129 | - def content_tag(tag, content, options = {}) | ||
| 130 | - "<#{tag}>#{content}</#{tag}>" | ||
| 131 | - end | ||
| 132 | end | 118 | end |
test/unit/content_viewer_helper_test.rb
| @@ -30,7 +30,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase | @@ -30,7 +30,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase | ||
| 30 | post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) | 30 | post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) |
| 31 | assert post.belongs_to_blog? | 31 | assert post.belongs_to_blog? |
| 32 | result = article_title(post) | 32 | result = article_title(post) |
| 33 | - assert_match /a href='#{post.url}'>#{post.name}</, result | 33 | + assert_tag_in_string result, :tag => 'h1', :child => {:tag => 'a', :content => 'post test', :attributes => { :href => /my-article-\d+/ }} |
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | should 'not create link on title if pass no_link option' do | 36 | should 'not create link on title if pass no_link option' do |
| @@ -130,34 +130,10 @@ class ContentViewerHelperTest < Test::Unit::TestCase | @@ -130,34 +130,10 @@ class ContentViewerHelperTest < Test::Unit::TestCase | ||
| 130 | end | 130 | end |
| 131 | 131 | ||
| 132 | protected | 132 | protected |
| 133 | - | 133 | + include NoosferoTestHelper |
| 134 | include ActionView::Helpers::TextHelper | 134 | include ActionView::Helpers::TextHelper |
| 135 | - | ||
| 136 | - def show_date(date) | ||
| 137 | - date.to_s | ||
| 138 | - end | ||
| 139 | - | ||
| 140 | - def link_to(content, url) | ||
| 141 | - "<a href='#{url}'>#{content}</a>" | ||
| 142 | - end | ||
| 143 | - | ||
| 144 | - def _(text) | ||
| 145 | - text | ||
| 146 | - end | ||
| 147 | - | ||
| 148 | - def will_paginate(arg1, arg2) | ||
| 149 | - end | ||
| 150 | - | ||
| 151 | - def strip_tags(html) | ||
| 152 | - html.gsub(/<[^>]+>/, '') | ||
| 153 | - end | ||
| 154 | - | ||
| 155 | def url_for(args = {}) | 135 | def url_for(args = {}) |
| 156 | ['http:/', args[:host], args[:profile], args[:page]].join('/') | 136 | ['http:/', args[:host], args[:profile], args[:page]].join('/') |
| 157 | end | 137 | end |
| 158 | 138 | ||
| 159 | - def image_tag(file, args = {}) | ||
| 160 | - file | ||
| 161 | - end | ||
| 162 | - | ||
| 163 | end | 139 | end |
test/unit/events_helper_test.rb
| @@ -79,18 +79,6 @@ class EventsHelperTest < Test::Unit::TestCase | @@ -79,18 +79,6 @@ class EventsHelperTest < Test::Unit::TestCase | ||
| 79 | end | 79 | end |
| 80 | 80 | ||
| 81 | protected | 81 | protected |
| 82 | - | ||
| 83 | - def content_tag(tag, text, options = {}) | ||
| 84 | - "<#{tag}>#{text}</#{tag}>" | ||
| 85 | - end | ||
| 86 | - def icon_for_article(article) | ||
| 87 | - '' | ||
| 88 | - end | ||
| 89 | - def image_tag(arg) | ||
| 90 | - arg | ||
| 91 | - end | ||
| 92 | - def link_to(text, url, options = {}) | ||
| 93 | - "<a href='#{url.to_s}'>#{text}</a>" | ||
| 94 | - end | 82 | + include NoosferoTestHelper |
| 95 | 83 | ||
| 96 | end | 84 | end |
test/unit/forms_helper_test.rb
test/unit/language_helper_test.rb
| @@ -38,8 +38,6 @@ class LanguageHelperTest < Test::Unit::TestCase | @@ -38,8 +38,6 @@ class LanguageHelperTest < Test::Unit::TestCase | ||
| 38 | 38 | ||
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | - include ActionView::Helpers::FormOptionsHelper | ||
| 42 | - include ActionView::Helpers::FormTagHelper | ||
| 43 | should 'generate drodown language chooser correcly' do | 41 | should 'generate drodown language chooser correcly' do |
| 44 | Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once | 42 | Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once |
| 45 | 43 | ||
| @@ -55,26 +53,8 @@ class LanguageHelperTest < Test::Unit::TestCase | @@ -55,26 +53,8 @@ class LanguageHelperTest < Test::Unit::TestCase | ||
| 55 | end | 53 | end |
| 56 | 54 | ||
| 57 | protected | 55 | protected |
| 56 | + include NoosferoTestHelper | ||
| 57 | + include ActionView::Helpers::FormOptionsHelper | ||
| 58 | + include ActionView::Helpers::FormTagHelper | ||
| 58 | 59 | ||
| 59 | - def _(s) | ||
| 60 | - s | ||
| 61 | - end | ||
| 62 | - | ||
| 63 | - def content_tag(tag, text, options = {}) | ||
| 64 | - "<#{tag}>#{text}</#{tag}>" | ||
| 65 | - end | ||
| 66 | - | ||
| 67 | - def link_to(text, url, options = {}) | ||
| 68 | - "<a href='?lang=#{url[:lang]}'>#{text}</a>" | ||
| 69 | - end | ||
| 70 | - | ||
| 71 | - def params | ||
| 72 | - {} | ||
| 73 | - end | ||
| 74 | - | ||
| 75 | - def url_for(x) | ||
| 76 | - x.inspect | ||
| 77 | - end | ||
| 78 | - | ||
| 79 | end | 60 | end |
| 80 | - |
test/unit/organization_mailing_test.rb
| @@ -112,9 +112,6 @@ class OrganizationMailingTest < ActiveSupport::TestCase | @@ -112,9 +112,6 @@ class OrganizationMailingTest < ActiveSupport::TestCase | ||
| 112 | end | 112 | end |
| 113 | 113 | ||
| 114 | protected | 114 | protected |
| 115 | - | ||
| 116 | - def url_for(url) | ||
| 117 | - url | ||
| 118 | - end | 115 | + include NoosferoTestHelper |
| 119 | 116 | ||
| 120 | end | 117 | end |
test/unit/people_block_test.rb
| @@ -45,8 +45,6 @@ class PeopleBlockTest < ActiveSupport::TestCase | @@ -45,8 +45,6 @@ class PeopleBlockTest < ActiveSupport::TestCase | ||
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | protected | 47 | protected |
| 48 | + include NoosferoTestHelper | ||
| 48 | 49 | ||
| 49 | - def content_tag(tag, text, options = {}) | ||
| 50 | - text | ||
| 51 | - end | ||
| 52 | end | 50 | end |