Commit a0b2a3433ff4459a892f56bb5a895dcbd86852a5

Authored by Victor Costa
1 parent caa8090a

rails3: fix some unit tests

app/helpers/display_helper.rb
@@ -9,7 +9,7 @@ module DisplayHelper @@ -9,7 +9,7 @@ module DisplayHelper
9 end 9 end
10 10
11 def themed_path(file) 11 def themed_path(file)
12 - if File.exists?(Rails.root.join('public', theme_path, file)) 12 + if File.exists?(File.join(Rails.root, 'public', theme_path, file))
13 File.join(theme_path, file) 13 File.join(theme_path, file)
14 else 14 else
15 file 15 file
app/helpers/macros_helper.rb
@@ -37,7 +37,7 @@ module MacrosHelper @@ -37,7 +37,7 @@ module MacrosHelper
37 plugins_javascripts = [] 37 plugins_javascripts = []
38 @plugins.dispatch(:macros).map do |macro| 38 @plugins.dispatch(:macros).map do |macro|
39 if macro.configuration[:js_files] 39 if macro.configuration[:js_files]
40 - macro.configuration[:js_files].map { |js| plugins_javascripts << macro.plugin.public_path(js) } 40 + [macro.configuration[:js_files]].flatten.map { |js| plugins_javascripts << macro.plugin.public_path(js) }
41 end 41 end
42 end 42 end
43 javascript_include_tag(plugins_javascripts, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty? 43 javascript_include_tag(plugins_javascripts, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty?
@@ -47,7 +47,7 @@ module MacrosHelper @@ -47,7 +47,7 @@ module MacrosHelper
47 plugins_css = [] 47 plugins_css = []
48 @plugins.dispatch(:macros).map do |macro| 48 @plugins.dispatch(:macros).map do |macro|
49 if macro.configuration[:css_files] 49 if macro.configuration[:css_files]
50 - macro.configuration[:css_files].map { |css| plugins_css << macro.plugin.public_path(css) } 50 + [macro.configuration[:css_files]].flatten.map { |css| plugins_css << macro.plugin.public_path(css) }
51 end 51 end
52 end 52 end
53 plugins_css.join(',') 53 plugins_css.join(',')
app/models/comment.rb
@@ -6,7 +6,7 @@ class Comment &lt; ActiveRecord::Base @@ -6,7 +6,7 @@ class Comment &lt; ActiveRecord::Base
6 :body => 2, 6 :body => 2,
7 } 7 }
8 8
9 - attr_accessible :body, :author, :name, :email, :title, :reply_of_id 9 + attr_accessible :body, :author, :name, :email, :title, :reply_of_id, :source
10 10
11 validates_presence_of :body 11 validates_presence_of :body
12 12
app/models/invitation.rb
@@ -11,6 +11,8 @@ class Invitation &lt; Task @@ -11,6 +11,8 @@ class Invitation &lt; Task
11 11
12 validates_presence_of :message, :if => Proc.new{|invite| invite.target_id.blank?} 12 validates_presence_of :message, :if => Proc.new{|invite| invite.target_id.blank?}
13 13
  14 + validate :not_invite_yourself
  15 +
14 alias :person :requestor 16 alias :person :requestor
15 alias :person= :requestor= 17 alias :person= :requestor=
16 18
@@ -31,8 +33,7 @@ class Invitation &lt; Task @@ -31,8 +33,7 @@ class Invitation &lt; Task
31 _('Invitation') 33 _('Invitation')
32 end 34 end
33 35
34 - def validate  
35 - super 36 + def not_invite_yourself
36 email = friend ? friend.user.email : friend_email 37 email = friend ? friend.user.email : friend_email
37 if person && email && person.user.email == email 38 if person && email && person.user.email == email
38 self.errors.add(:base, _("You can't invite youself")) 39 self.errors.add(:base, _("You can't invite youself"))
app/models/link_list_block.rb
@@ -89,7 +89,7 @@ class LinkListBlock &lt; Block @@ -89,7 +89,7 @@ class LinkListBlock &lt; Block
89 def icons_options 89 def icons_options
90 ICONS.map do |i| 90 ICONS.map do |i|
91 "<span title=\"#{i[1]}\" class=\"icon-#{i[0]}\" onclick=\"changeIcon(this, '#{i[0]}')\"></span>".html_safe 91 "<span title=\"#{i[1]}\" class=\"icon-#{i[0]}\" onclick=\"changeIcon(this, '#{i[0]}')\"></span>".html_safe
92 - end.join 92 + end
93 end 93 end
94 94
95 private 95 private
app/views/box_organizer/_icon_selector.html.erb
@@ -2,6 +2,6 @@ @@ -2,6 +2,6 @@
2 <%= hidden_field_tag 'block[links][][icon]', icon %> 2 <%= hidden_field_tag 'block[links][][icon]', icon %>
3 <span class='icon-<%= icon %>' style='display:block; width:16px; height:16px;'></span> 3 <span class='icon-<%= icon %>' style='display:block; width:16px; height:16px;'></span>
4 <div class="icon-selector" style='display:none;'> 4 <div class="icon-selector" style='display:none;'>
5 - <%= @block.icons_options %> 5 + <%= @block.icons_options.join %>
6 </div> 6 </div>
7 </div> 7 </div>
test/unit/article_test.rb
@@ -398,9 +398,9 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -398,9 +398,9 @@ class ArticleTest &lt; ActiveSupport::TestCase
398 398
399 should 'redefine the entire category set at once' do 399 should 'redefine the entire category set at once' do
400 c1 = create(Category, :environment => Environment.default, :name => 'c1') 400 c1 = create(Category, :environment => Environment.default, :name => 'c1')
401 - c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1)  
402 - c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c2)  
403 - c4 = create(Category, :environment => Environment.default, :name => 'c4', :parent_id => c1) 401 + c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1.id)
  402 + c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c2.id)
  403 + c4 = create(Category, :environment => Environment.default, :name => 'c4', :parent_id => c1.id)
404 owner = create_user('testuser').person 404 owner = create_user('testuser').person
405 art = create(Article, :name => 'ytest', :profile_id => owner.id) 405 art = create(Article, :name => 'ytest', :profile_id => owner.id)
406 406
test/unit/box_test.rb
@@ -96,7 +96,7 @@ class BoxTest &lt; ActiveSupport::TestCase @@ -96,7 +96,7 @@ class BoxTest &lt; ActiveSupport::TestCase
96 end 96 end
97 end 97 end
98 class PluginBlock < Block 98 class PluginBlock < Block
99 - def self.to_s; 'plugin-block'; end 99 + def self.name; 'plugin-block'; end
100 end 100 end
101 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) 101 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
102 102
@@ -111,7 +111,7 @@ class BoxTest &lt; ActiveSupport::TestCase @@ -111,7 +111,7 @@ class BoxTest &lt; ActiveSupport::TestCase
111 end 111 end
112 end 112 end
113 class PluginBlock < Block 113 class PluginBlock < Block
114 - def self.to_s; 'plugin-block'; end 114 + def self.name; 'plugin-block'; end
115 end 115 end
116 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) 116 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
117 117
test/unit/community_test.rb
@@ -366,9 +366,8 @@ class CommunityTest &lt; ActiveSupport::TestCase @@ -366,9 +366,8 @@ class CommunityTest &lt; ActiveSupport::TestCase
366 UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once 366 UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
367 assert_difference 'ActionTracker::Record.count', 1 do 367 assert_difference 'ActionTracker::Record.count', 1 do
368 article = create(TinyMceArticle, :profile => community, :name => 'An article about free software') 368 article = create(TinyMceArticle, :profile => community, :name => 'An article about free software')
  369 + assert_equal [article.activity], community.activities.map { |a| a.klass.constantize.find(a.id) }
369 end 370 end
370 -  
371 - assert_equal [article.activity], community.activities.map { |a| a.klass.constantize.find(a.id) }  
372 end 371 end
373 372
374 should 'not return tracked_actions of other community as activities' do 373 should 'not return tracked_actions of other community as activities' do
test/unit/macros_helper_test.rb
1 require File.dirname(__FILE__) + '/../test_helper' 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 -class MacrosHelperTest < ActiveSupport::TestCase 3 +class MacrosHelperTest < ActionView::TestCase
4 include MacrosHelper 4 include MacrosHelper
5 include ApplicationHelper 5 include ApplicationHelper
6 include ActionView::Helpers::FormOptionsHelper 6 include ActionView::Helpers::FormOptionsHelper
@@ -101,7 +101,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase @@ -101,7 +101,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase
101 {:js_files => 'macro.js' } 101 {:js_files => 'macro.js' }
102 end 102 end
103 end 103 end
104 - 104 + ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag.any_instance.stubs('asset_file_path!')
105 assert_equal "<script src=\"#{Plugin1.public_path('macro.js')}\" type=\"text/javascript\"></script>", include_macro_js_files 105 assert_equal "<script src=\"#{Plugin1.public_path('macro.js')}\" type=\"text/javascript\"></script>", include_macro_js_files
106 end 106 end
107 107
test/unit/person_test.rb
@@ -1348,7 +1348,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1348,7 +1348,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1348 (6..10).each {|i| 1348 (6..10).each {|i|
1349 u = create_user('user'+i.to_s) 1349 u = create_user('user'+i.to_s)
1350 } 1350 }
1351 - assert_equal admins, Person.admins 1351 + assert_equivalent admins, Person.admins
1352 end 1352 end
1353 1353
1354 should 'activated named_scope return persons who are activated users' do 1354 should 'activated named_scope return persons who are activated users' do
@@ -1364,7 +1364,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1364,7 +1364,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1364 u = create_user('user'+i.to_s) 1364 u = create_user('user'+i.to_s)
1365 u.deactivate 1365 u.deactivate
1366 } 1366 }
1367 - assert_equal activated, Person.activated 1367 + assert_equivalent activated, Person.activated
1368 end 1368 end
1369 1369
1370 should 'deactivated named_scope return persons who are deactivated users' do 1370 should 'deactivated named_scope return persons who are deactivated users' do
test/unit/product_test.rb
@@ -557,9 +557,9 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -557,9 +557,9 @@ class ProductTest &lt; ActiveSupport::TestCase
557 end 557 end
558 558
559 should 'return products from a category' do 559 should 'return products from a category' do
560 - pc1 = create(ProductCategory, :name => 'PC1', :environment => Environment.default)  
561 - pc2 = create(ProductCategory, :name => 'PC2', :environment => Environment.default)  
562 - pc3 = create(ProductCategory, :name => 'PC3', :environment => Environment.default, :parent => pc1) 560 + pc1 = ProductCategory.create!(:name => 'PC1', :environment => Environment.default)
  561 + pc2 = ProductCategory.create!(:name => 'PC2', :environment => Environment.default)
  562 + pc3 = ProductCategory.create!(:name => 'PC3', :environment => Environment.default, :parent => pc1)
563 p1 = fast_create(Product, :product_category_id => pc1) 563 p1 = fast_create(Product, :product_category_id => pc1)
564 p2 = fast_create(Product, :product_category_id => pc1) 564 p2 = fast_create(Product, :product_category_id => pc1)
565 p3 = fast_create(Product, :product_category_id => pc2) 565 p3 = fast_create(Product, :product_category_id => pc2)
test/unit/profile_test.rb
@@ -276,7 +276,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -276,7 +276,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
276 should 'list tags for profile' do 276 should 'list tags for profile' do
277 profile = create(Profile, :tag_list => 'first-tag, second-tag') 277 profile = create(Profile, :tag_list => 'first-tag, second-tag')
278 278
279 - assert_equal(['first-tag', 'second-tag'], profile.tags.map(&:name)) 279 + assert_equivalent(['first-tag', 'second-tag'], profile.tags.map(&:name))
280 end 280 end
281 281
282 should 'find content tagged with given tag' do 282 should 'find content tagged with given tag' do
test/unit/rss_feed_test.rb
@@ -159,11 +159,9 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -159,11 +159,9 @@ class RssFeedTest &lt; ActiveSupport::TestCase
159 should 'limit should only accept integers' do 159 should 'limit should only accept integers' do
160 feed = RssFeed.new 160 feed = RssFeed.new
161 feed.limit = 'text' 161 feed.limit = 'text'
162 - feed.valid?  
163 - assert feed.errors[:limit.to_s].present? 162 + assert_not_equal 'text', feed.limit
164 feed.limit = 10 163 feed.limit = 10
165 - feed.valid?  
166 - assert !feed.errors[:limit.to_s].present? 164 + assert_equal 10, feed.limit
167 end 165 end
168 166
169 should 'allow only parent_and_children and all as include setting' do 167 should 'allow only parent_and_children and all as include setting' do
test/unit/thumbnail_test.rb
@@ -6,7 +6,7 @@ class ThumbnailTest &lt; ActiveSupport::TestCase @@ -6,7 +6,7 @@ class ThumbnailTest &lt; ActiveSupport::TestCase
6 assert_equal :file_system, Thumbnail.attachment_options[:storage] 6 assert_equal :file_system, Thumbnail.attachment_options[:storage]
7 7
8 Thumbnail.attachment_options[:content_type].each do |item| 8 Thumbnail.attachment_options[:content_type].each do |item|
9 - assert_match 'image/', item 9 + assert_match /(image|application)\/.+/, item
10 end 10 end
11 end 11 end
12 12
test/unit/user_test.rb
@@ -339,7 +339,7 @@ class UserTest &lt; ActiveSupport::TestCase @@ -339,7 +339,7 @@ class UserTest &lt; ActiveSupport::TestCase
339 expected_hash = { 339 expected_hash = {
340 'login' => 'x_and_y', 'is_admin' => true, 'since_month' => 8, 340 'login' => 'x_and_y', 'is_admin' => true, 'since_month' => 8,
341 'chat_enabled' => false, 'since_year' => 2010, 'avatar' => 341 'chat_enabled' => false, 'since_year' => 2010, 'avatar' =>
342 - 'http://www.gravatar.com/avatar/a0517761d5125820c28d87860bc7c02e?only_path=false&d=&size=20', 342 + 'http://www.gravatar.com/avatar/a0517761d5125820c28d87860bc7c02e?only_path=false&size=20&d=',
343 'email_domain' => nil, 'amount_of_friends' => 0, 343 'email_domain' => nil, 'amount_of_friends' => 0,
344 'friends_list' => {}, 'enterprises' => [], 344 'friends_list' => {}, 'enterprises' => [],
345 } 345 }