Commit de0aceaacddab5649dd1de63ce0cef92ac494172

Authored by Victor Costa
1 parent 1b335879

rails3: fix assert_kind_of Array

On rails 3.2, the return type of some queries changes from Array to ActiveRecord::Relation.
An assertion that check if these attributes has been assigned (with a value != nil) should be enought.
This avoids future problems with api changes.
app/controllers/my_profile/cms_controller.rb
@@ -232,7 +232,7 @@ class CmsController < MyProfileController @@ -232,7 +232,7 @@ class CmsController < MyProfileController
232 begin 232 begin
233 task.finish unless item[:group].moderated_articles? 233 task.finish unless item[:group].moderated_articles?
234 rescue Exception => ex 234 rescue Exception => ex
235 - @failed[ex.clean_message] ? @failed[ex.clean_message] << item[:group].name : @failed[ex.clean_message] = [item[:group].name] 235 + @failed[ex.message] ? @failed[ex.message] << item[:group].name : @failed[ex.message] = [item[:group].name]
236 end 236 end
237 end 237 end
238 if @failed.blank? 238 if @failed.blank?
app/controllers/my_profile/tasks_controller.rb
@@ -27,7 +27,7 @@ class TasksController &lt; MyProfileController @@ -27,7 +27,7 @@ class TasksController &lt; MyProfileController
27 task.send(decision) 27 task.send(decision)
28 rescue Exception => ex 28 rescue Exception => ex
29 message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" 29 message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})"
30 - failed[ex.clean_message] ? failed[ex.clean_message] << message : failed[ex.clean_message] = [message] 30 + failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message]
31 end 31 end
32 end 32 end
33 end 33 end
test/functional/catalog_controller_test.rb
@@ -37,7 +37,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -37,7 +37,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
37 37
38 should 'list products of enterprise' do 38 should 'list products of enterprise' do
39 get :index, :profile => @enterprise.identifier 39 get :index, :profile => @enterprise.identifier
40 - assert_kind_of Array, assigns(:products) 40 + assert assigns(:products)
41 end 41 end
42 42
43 should 'paginate enterprise products list' do 43 should 'paginate enterprise products list' do
test/functional/cms_controller_test.rb
@@ -36,7 +36,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -36,7 +36,7 @@ class CmsControllerTest &lt; ActionController::TestCase
36 assert_template 'view' 36 assert_template 'view'
37 assert_equal profile, assigns(:profile) 37 assert_equal profile, assigns(:profile)
38 assert_nil assigns(:article) 38 assert_nil assigns(:article)
39 - assert_kind_of Array, assigns(:articles) 39 + assert assigns(:articles)
40 end 40 end
41 41
42 should 'be able to view a particular document' do 42 should 'be able to view a particular document' do
@@ -49,8 +49,6 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -49,8 +49,6 @@ class CmsControllerTest &lt; ActionController::TestCase
49 assert_template 'view' 49 assert_template 'view'
50 assert_equal a, assigns(:article) 50 assert_equal a, assigns(:article)
51 assert_equal [], assigns(:articles) 51 assert_equal [], assigns(:articles)
52 -  
53 - assert_kind_of Array, assigns(:articles)  
54 end 52 end
55 53
56 should 'be able to edit a document' do 54 should 'be able to edit a document' do
test/functional/friends_controller_test.rb
@@ -30,7 +30,7 @@ class FriendsControllerTest &lt; ActionController::TestCase @@ -30,7 +30,7 @@ class FriendsControllerTest &lt; ActionController::TestCase
30 get :index 30 get :index
31 assert_response :success 31 assert_response :success
32 assert_template 'index' 32 assert_template 'index'
33 - assert_kind_of Array, assigns(:friends) 33 + assert assigns(:friends)
34 end 34 end
35 35
36 should 'confirm removal of friend' do 36 should 'confirm removal of friend' do
test/functional/memberships_controller_test.rb
@@ -30,7 +30,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -30,7 +30,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
30 should 'list current memberships' do 30 should 'list current memberships' do
31 get :index, :profile => profile.identifier 31 get :index, :profile => profile.identifier
32 32
33 - assert_kind_of Array, assigns(:memberships) 33 + assert assigns(:memberships)
34 end 34 end
35 35
36 should 'present new community form' do 36 should 'present new community form' do
test/functional/profile_controller_test.rb
@@ -29,7 +29,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -29,7 +29,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
29 29
30 assert_response :success 30 assert_response :success
31 assert_template 'friends' 31 assert_template 'friends'
32 - assert_kind_of Array, assigns(:friends) 32 + assert assigns(:friends)
33 end 33 end
34 34
35 should 'point to manage friends in user is seeing his own friends' do 35 should 'point to manage friends in user is seeing his own friends' do
@@ -50,7 +50,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -50,7 +50,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
50 50
51 assert_response :success 51 assert_response :success
52 assert_template 'communities' 52 assert_template 'communities'
53 - assert_kind_of Array, assigns(:communities) 53 + assert assigns(:communities)
54 end 54 end
55 55
56 should 'list enterprises' do 56 should 'list enterprises' do
@@ -58,7 +58,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -58,7 +58,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
58 58
59 assert_response :success 59 assert_response :success
60 assert_template 'enterprises' 60 assert_template 'enterprises'
61 - assert_kind_of Array, assigns(:enterprises) 61 + assert assigns(:enterprises)
62 end 62 end
63 63
64 should 'list members (for organizations)' do 64 should 'list members (for organizations)' do
@@ -66,7 +66,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -66,7 +66,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
66 66
67 assert_response :success 67 assert_response :success
68 assert_template 'members' 68 assert_template 'members'
69 - assert_kind_of Array, assigns(:members) 69 + assert assigns(:members)
70 end 70 end
71 71
72 should 'list favorite enterprises' do 72 should 'list favorite enterprises' do
@@ -74,7 +74,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -74,7 +74,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
74 74
75 assert_response :success 75 assert_response :success
76 assert_template 'favorite_enterprises' 76 assert_template 'favorite_enterprises'
77 - assert_kind_of Array, assigns(:favorite_enterprises) 77 + assert assigns(:favorite_enterprises)
78 end 78 end
79 79
80 should 'not render any template when joining community due to Ajax request' do 80 should 'not render any template when joining community due to Ajax request' do
test/functional/region_validators_controller_test.rb
@@ -26,7 +26,7 @@ class RegionValidatorsControllerTest &lt; ActionController::TestCase @@ -26,7 +26,7 @@ class RegionValidatorsControllerTest &lt; ActionController::TestCase
26 get :index 26 get :index
27 assert_response :success 27 assert_response :success
28 assert_template 'index' 28 assert_template 'index'
29 - assert_kind_of Array, assigns(:regions) 29 + assert assigns(:regions)
30 end 30 end
31 31
32 should 'view validators for a specific region' do 32 should 'view validators for a specific region' do
test/functional/tasks_controller_test.rb
@@ -35,7 +35,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -35,7 +35,7 @@ class TasksControllerTest &lt; ActionController::TestCase
35 35
36 assert_response :success 36 assert_response :success
37 assert_template 'index' 37 assert_template 'index'
38 - assert_kind_of Array, assigns(:tasks) 38 + assert assigns(:tasks)
39 end 39 end
40 40
41 should 'list pending tasks without spam' do 41 should 'list pending tasks without spam' do
@@ -197,7 +197,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -197,7 +197,7 @@ class TasksControllerTest &lt; ActionController::TestCase
197 c = fast_create(Community) 197 c = fast_create(Community)
198 c.update_attributes(:moderated_articles => false) 198 c.update_attributes(:moderated_articles => false)
199 @controller.stubs(:profile).returns(c) 199 @controller.stubs(:profile).returns(c)
200 - folder = create(Article, :profile => c, :name => 'test folder', :type => 'Folder') 200 + folder = create(Folder, :profile => c, :name => 'test folder')
201 c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) 201 c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
202 article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') 202 article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
203 t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) 203 t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
@@ -275,8 +275,8 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -275,8 +275,8 @@ class TasksControllerTest &lt; ActionController::TestCase
275 t = SuggestArticle.create!(:article_name => 'test name', :article_abstract => 'test abstract', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c) 275 t = SuggestArticle.create!(:article_name => 'test name', :article_abstract => 'test abstract', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c)
276 276
277 get :index 277 get :index
278 - assert_tag :tag => 'textarea', :content => 'test abstract', :attributes => { :name => /article_abstract/, :class => 'mceEditor' }  
279 - assert_tag :tag => 'textarea', :content => 'test body', :attributes => { :name => /article_body/, :class => 'mceEditor' } 278 + assert_tag :tag => 'textarea', :content => /test abstract/, :attributes => { :name => /article_abstract/, :class => 'mceEditor' }
  279 + assert_tag :tag => 'textarea', :content => /test body/, :attributes => { :name => /article_body/, :class => 'mceEditor' }
280 end 280 end
281 281
282 should 'create TinyMceArticle article after finish approve suggested article task' do 282 should 'create TinyMceArticle article after finish approve suggested article task' do