Commit c609113cfa06f45e4b49945610c61e3be0299262

Authored by Leandro Santos
1 parent 5807ff83

fixing unit tests

app/models/profile.rb
@@ -203,9 +203,9 @@ class Profile < ActiveRecord::Base @@ -203,9 +203,9 @@ class Profile < ActiveRecord::Base
203 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') 203 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',')
204 end 204 end
205 205
206 - scope :visible, :conditions => { :visible => true } 206 + scope :visible, :conditions => { :visible => true, :secret => false }
207 scope :disabled, :conditions => { :visible => false } 207 scope :disabled, :conditions => { :visible => false }
208 - scope :public, :conditions => { :visible => true, :public_profile => true } 208 + scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false }
209 scope :enabled, :conditions => { :enabled => true } 209 scope :enabled, :conditions => { :enabled => true }
210 210
211 # Subclasses must override this method 211 # Subclasses must override this method
test/unit/api/articles_test.rb
@@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/test_helper' @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/test_helper'
3 class ArticlesTest < ActiveSupport::TestCase 3 class ArticlesTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - Environment.destroy_all  
7 login_api 6 login_api
8 end 7 end
9 8
@@ -32,7 +31,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -32,7 +31,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
32 end 31 end
33 32
34 should 'not return article if user has no permission to view it' do 33 should 'not return article if user has no permission to view it' do
35 - person = fast_create(Person) 34 + person = fast_create(Person, :environment_id => environment.id)
36 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 35 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
37 assert !article.published? 36 assert !article.published?
38 37
@@ -50,7 +49,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -50,7 +49,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
50 end 49 end
51 50
52 should 'not list children of forbidden article' do 51 should 'not list children of forbidden article' do
53 - person = fast_create(Person) 52 + person = fast_create(Person, :environment_id => environment.id)
54 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 53 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
55 child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 54 child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
56 child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 55 child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
@@ -59,7 +58,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -59,7 +58,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
59 end 58 end
60 59
61 should 'not return child of forbidden article' do 60 should 'not return child of forbidden article' do
62 - person = fast_create(Person) 61 + person = fast_create(Person, :environment_id => environment.id)
63 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 62 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
64 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 63 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
65 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" 64 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}"
@@ -67,7 +66,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -67,7 +66,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
67 end 66 end
68 67
69 should 'not return private child' do 68 should 'not return private child' do
70 - person = fast_create(Person) 69 + person = fast_create(Person, :environment_id => environment.id)
71 article = fast_create(Article, :profile_id => person.id, :name => "Some thing") 70 article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
72 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) 71 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false)
73 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" 72 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}"
@@ -75,7 +74,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -75,7 +74,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
75 end 74 end
76 75
77 should 'not list private child' do 76 should 'not list private child' do
78 - person = fast_create(Person) 77 + person = fast_create(Person, :environment_id => environment.id)
79 article = fast_create(Article, :profile_id => person.id, :name => "Some thing") 78 article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
80 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) 79 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false)
81 get "/api/v1/articles/#{article.id}/children?#{params.to_query}" 80 get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
@@ -90,15 +89,15 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -90,15 +89,15 @@ class ArticlesTest &lt; ActiveSupport::TestCase
90 profile_kinds = %w(community person enterprise) 89 profile_kinds = %w(community person enterprise)
91 profile_kinds.each do |kind| 90 profile_kinds.each do |kind|
92 should "return article by #{kind}" do 91 should "return article by #{kind}" do
93 - profile = fast_create(kind.camelcase.constantize)  
94 - article = fast_create(Article, :profile_id => person.id, :name => "Some thing")  
95 - get "/api/v1/#{kind.pluralize}/#{person.id}/articles/#{article.id}?#{params.to_query}" 92 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  93 + article = fast_create(Article, :profile_id => profile.id, :name => "Some thing")
  94 + get "/api/v1/#{kind.pluralize}/#{profile.id}/articles/#{article.id}?#{params.to_query}"
96 json = JSON.parse(last_response.body) 95 json = JSON.parse(last_response.body)
97 assert_equal article.id, json["article"]["id"] 96 assert_equal article.id, json["article"]["id"]
98 end 97 end
99 98
100 should "not return article by #{kind} if user has no permission to view it" do 99 should "not return article by #{kind} if user has no permission to view it" do
101 - profile = fast_create(kind.camelcase.constantize) 100 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
102 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) 101 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false)
103 assert !article.published? 102 assert !article.published?
104 103
@@ -107,7 +106,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -107,7 +106,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
107 end 106 end
108 107
109 should "not list forbidden article when listing articles by #{kind}" do 108 should "not list forbidden article when listing articles by #{kind}" do
110 - profile = fast_create(kind.camelcase.constantize) 109 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
111 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) 110 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false)
112 assert !article.published? 111 assert !article.published?
113 112
@@ -124,7 +123,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -124,7 +123,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
124 group_kinds = %w(community enterprise) 123 group_kinds = %w(community enterprise)
125 group_kinds.each do |kind| 124 group_kinds.each do |kind|
126 should "#{kind}: create article" do 125 should "#{kind}: create article" do
127 - profile = fast_create(kind.camelcase.constantize) 126 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
128 give_permission(user.person, 'post_content', profile) 127 give_permission(user.person, 'post_content', profile)
129 params[:article] = {:name => "Title"} 128 params[:article] = {:name => "Title"}
130 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 129 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -133,16 +132,16 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -133,16 +132,16 @@ class ArticlesTest &lt; ActiveSupport::TestCase
133 end 132 end
134 133
135 should "#{kind}: do not create article if user has no permission to post content" do 134 should "#{kind}: do not create article if user has no permission to post content" do
136 - profile = fast_create(kind.camelcase.constantize) 135 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
137 give_permission(user.person, 'invite_members', profile) 136 give_permission(user.person, 'invite_members', profile)
138 params[:article] = {:name => "Title"} 137 params[:article] = {:name => "Title"}
139 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 138 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
140 assert_equal 403, last_response.status 139 assert_equal 403, last_response.status
141 end 140 end
142 141
143 - should "#{kind}: create article with parent" do  
144 - profile = fast_create(kind.camelcase.constantize)  
145 - profile.add_member(user.person) 142 + should "#{kind} create article with parent" do
  143 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  144 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
146 article = fast_create(Article) 145 article = fast_create(Article)
147 146
148 params[:article] = {:name => "Title", :parent_id => article.id} 147 params[:article] = {:name => "Title", :parent_id => article.id}
@@ -151,9 +150,9 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -151,9 +150,9 @@ class ArticlesTest &lt; ActiveSupport::TestCase
151 assert_equal article.id, json["article"]["parent"]["id"] 150 assert_equal article.id, json["article"]["parent"]["id"]
152 end 151 end
153 152
154 - should "#{kind}: create article with content type passed as parameter" do  
155 - profile = fast_create(kind.camelcase.constantize)  
156 - profile.add_member(user.person) 153 + should "#{kind} create article with content type passed as parameter" do
  154 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  155 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
157 156
158 Article.delete_all 157 Article.delete_all
159 params[:article] = {:name => "Title"} 158 params[:article] = {:name => "Title"}
@@ -165,8 +164,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -165,8 +164,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase
165 end 164 end
166 165
167 should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do 166 should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do
168 - profile = fast_create(kind.camelcase.constantize)  
169 - profile.add_member(user.person) 167 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  168 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
170 169
171 params[:article] = {:name => "Title"} 170 params[:article] = {:name => "Title"}
172 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 171 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -176,7 +175,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -176,7 +175,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
176 end 175 end
177 176
178 should "#{kind}: not create article with invalid article content type" do 177 should "#{kind}: not create article with invalid article content type" do
179 - profile = fast_create(kind.camelcase.constantize) 178 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
180 profile.add_member(user.person) 179 profile.add_member(user.person)
181 180
182 params[:article] = {:name => "Title"} 181 params[:article] = {:name => "Title"}
@@ -187,20 +186,20 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -187,20 +186,20 @@ class ArticlesTest &lt; ActiveSupport::TestCase
187 assert_equal 403, last_response.status 186 assert_equal 403, last_response.status
188 end 187 end
189 188
190 - should "#{kind}: create article defining the correct profile" do  
191 - profile = fast_create(kind.camelcase.constantize)  
192 - profile.add_member(user.person) 189 + should "#{kind} create article defining the correct profile" do
  190 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  191 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
193 192
194 params[:article] = {:name => "Title"} 193 params[:article] = {:name => "Title"}
195 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 194 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
196 json = JSON.parse(last_response.body) 195 json = JSON.parse(last_response.body)
197 196
198 - assert_equal profile, Article.last.profile 197 + assert_equal profile.id, json['article']['profile']['id']
199 end 198 end
200 199
201 should "#{kind}: create article defining the created_by" do 200 should "#{kind}: create article defining the created_by" do
202 - profile = fast_create(kind.camelcase.constantize)  
203 - profile.add_member(user.person) 201 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  202 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
204 203
205 params[:article] = {:name => "Title"} 204 params[:article] = {:name => "Title"}
206 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 205 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -210,8 +209,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -210,8 +209,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase
210 end 209 end
211 210
212 should "#{kind}: create article defining the last_changed_by" do 211 should "#{kind}: create article defining the last_changed_by" do
213 - profile = fast_create(kind.camelcase.constantize)  
214 - profile.add_member(user.person) 212 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  213 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
215 214
216 params[:article] = {:name => "Title"} 215 params[:article] = {:name => "Title"}
217 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 216 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -233,7 +232,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -233,7 +232,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
233 end 232 end
234 233
235 should 'person do not create article if user has no permission to post content' do 234 should 'person do not create article if user has no permission to post content' do
236 - person = fast_create(Person) 235 + person = fast_create(Person, :environment_id => environment.id)
237 params[:article] = {:name => "Title"} 236 params[:article] = {:name => "Title"}
238 post "/api/v1/people/#{person.id}/articles?#{params.to_query}" 237 post "/api/v1/people/#{person.id}/articles?#{params.to_query}"
239 assert_equal 403, last_response.status 238 assert_equal 403, last_response.status
test/unit/api/categories_test.rb
@@ -7,25 +7,25 @@ class CategoriesTest &lt; ActiveSupport::TestCase @@ -7,25 +7,25 @@ class CategoriesTest &lt; ActiveSupport::TestCase
7 end 7 end
8 8
9 should 'list categories' do 9 should 'list categories' do
10 - category = fast_create(Category) 10 + category = fast_create(Category, :environment_id => environment.id)
11 get "/api/v1/categories/?#{params.to_query}" 11 get "/api/v1/categories/?#{params.to_query}"
12 json = JSON.parse(last_response.body) 12 json = JSON.parse(last_response.body)
13 assert_includes json["categories"].map { |c| c["name"] }, category.name 13 assert_includes json["categories"].map { |c| c["name"] }, category.name
14 end 14 end
15 15
16 should 'get category by id' do 16 should 'get category by id' do
17 - category = fast_create(Category) 17 + category = fast_create(Category, :environment_id => environment.id)
18 get "/api/v1/categories/#{category.id}/?#{params.to_query}" 18 get "/api/v1/categories/#{category.id}/?#{params.to_query}"
19 json = JSON.parse(last_response.body) 19 json = JSON.parse(last_response.body)
20 assert_equal category.name, json["category"]["name"] 20 assert_equal category.name, json["category"]["name"]
21 end 21 end
22 22
23 should 'list parent and children when get category by id' do 23 should 'list parent and children when get category by id' do
24 - parent = fast_create(Category)  
25 - child_1 = fast_create(Category)  
26 - child_2 = fast_create(Category) 24 + parent = fast_create(Category, :environment_id => environment.id)
  25 + child_1 = fast_create(Category, :environment_id => environment.id)
  26 + child_2 = fast_create(Category, :environment_id => environment.id)
27 27
28 - category = fast_create(Category) 28 + category = fast_create(Category, :environment_id => environment.id)
29 category.parent = parent 29 category.parent = parent
30 category.children << child_1 30 category.children << child_1
31 category.children << child_2 31 category.children << child_2
@@ -38,11 +38,11 @@ class CategoriesTest &lt; ActiveSupport::TestCase @@ -38,11 +38,11 @@ class CategoriesTest &lt; ActiveSupport::TestCase
38 end 38 end
39 39
40 should 'include parent in categories list if params is true' do 40 should 'include parent in categories list if params is true' do
41 - parent_1 = fast_create(Category) # parent_1 has no parent category  
42 - child_1 = fast_create(Category)  
43 - child_2 = fast_create(Category) 41 + parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category
  42 + child_1 = fast_create(Category, :environment_id => environment.id)
  43 + child_2 = fast_create(Category, :environment_id => environment.id)
44 44
45 - parent_2 = fast_create(Category) 45 + parent_2 = fast_create(Category, :environment_id => environment.id)
46 parent_2.parent = parent_1 46 parent_2.parent = parent_1
47 parent_2.children << child_1 47 parent_2.children << child_1
48 parent_2.children << child_2 48 parent_2.children << child_2
@@ -60,10 +60,10 @@ class CategoriesTest &lt; ActiveSupport::TestCase @@ -60,10 +60,10 @@ class CategoriesTest &lt; ActiveSupport::TestCase
60 end 60 end
61 61
62 should 'include children in categories list if params is true' do 62 should 'include children in categories list if params is true' do
63 - category = fast_create(Category)  
64 - child_1 = fast_create(Category)  
65 - child_2 = fast_create(Category)  
66 - child_3 = fast_create(Category) 63 + category = fast_create(Category, :environment_id => environment.id)
  64 + child_1 = fast_create(Category, :environment_id => environment.id)
  65 + child_2 = fast_create(Category, :environment_id => environment.id)
  66 + child_3 = fast_create(Category, :environment_id => environment.id)
67 67
68 category.children << child_1 68 category.children << child_1
69 category.children << child_2 69 category.children << child_2
test/unit/api/communities_test.rb
@@ -8,8 +8,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -8,8 +8,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
8 end 8 end
9 9
10 should 'list only communities' do 10 should 'list only communities' do
11 - community = fast_create(Community)  
12 - enterprise = fast_create(Enterprise) # should not list this enterprise 11 + community = fast_create(Community, :environment_id => environment.id)
  12 + enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise
13 get "/api/v1/communities?#{params.to_query}" 13 get "/api/v1/communities?#{params.to_query}"
14 json = JSON.parse(last_response.body) 14 json = JSON.parse(last_response.body)
15 assert_not_includes json['communities'].map {|c| c['id']}, enterprise.id 15 assert_not_includes json['communities'].map {|c| c['id']}, enterprise.id
@@ -17,16 +17,16 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -17,16 +17,16 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
17 end 17 end
18 18
19 should 'list all communities' do 19 should 'list all communities' do
20 - community1 = fast_create(Community, :public_profile => true)  
21 - community2 = fast_create(Community) 20 + community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true)
  21 + community2 = fast_create(Community, :environment_id => environment.id)
22 get "/api/v1/communities?#{params.to_query}" 22 get "/api/v1/communities?#{params.to_query}"
23 json = JSON.parse(last_response.body) 23 json = JSON.parse(last_response.body)
24 assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} 24 assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']}
25 end 25 end
26 26
27 should 'not list invisible communities' do 27 should 'not list invisible communities' do
28 - community1 = fast_create(Community)  
29 - fast_create(Community, :visible => false) 28 + community1 = fast_create(Community, :environment_id => environment.id)
  29 + fast_create(Community, :environment_id => environment.id, :visible => false)
30 30
31 get "/api/v1/communities?#{params.to_query}" 31 get "/api/v1/communities?#{params.to_query}"
32 json = JSON.parse(last_response.body) 32 json = JSON.parse(last_response.body)
@@ -34,8 +34,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -34,8 +34,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
34 end 34 end
35 35
36 should 'not list private communities without permission' do 36 should 'not list private communities without permission' do
37 - community1 = fast_create(Community)  
38 - fast_create(Community, :public_profile => false) 37 + community1 = fast_create(Community, :environment_id => environment.id)
  38 + fast_create(Community, :environment_id => environment.id, :public_profile => false)
39 39
40 get "/api/v1/communities?#{params.to_query}" 40 get "/api/v1/communities?#{params.to_query}"
41 json = JSON.parse(last_response.body) 41 json = JSON.parse(last_response.body)
@@ -43,8 +43,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -43,8 +43,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
43 end 43 end
44 44
45 should 'list private community for members' do 45 should 'list private community for members' do
46 - c1 = fast_create(Community)  
47 - c2 = fast_create(Community, :public_profile => false) 46 + c1 = fast_create(Community, :environment_id => environment.id)
  47 + c2 = fast_create(Community, :environment_id => environment.id, :public_profile => false)
48 c2.add_member(person) 48 c2.add_member(person)
49 49
50 get "/api/v1/communities?#{params.to_query}" 50 get "/api/v1/communities?#{params.to_query}"
@@ -66,7 +66,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -66,7 +66,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
66 end 66 end
67 67
68 should 'get community' do 68 should 'get community' do
69 - community = fast_create(Community) 69 + community = fast_create(Community, :environment_id => environment.id)
70 70
71 get "/api/v1/communities/#{community.id}?#{params.to_query}" 71 get "/api/v1/communities/#{community.id}?#{params.to_query}"
72 json = JSON.parse(last_response.body) 72 json = JSON.parse(last_response.body)
@@ -74,7 +74,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -74,7 +74,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
74 end 74 end
75 75
76 should 'not get invisible community' do 76 should 'not get invisible community' do
77 - community = fast_create(Community, :visible => false) 77 + community = fast_create(Community, :environment_id => environment.id, :visible => false)
78 78
79 get "/api/v1/communities/#{community.id}?#{params.to_query}" 79 get "/api/v1/communities/#{community.id}?#{params.to_query}"
80 json = JSON.parse(last_response.body) 80 json = JSON.parse(last_response.body)
@@ -82,8 +82,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -82,8 +82,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
82 end 82 end
83 83
84 should 'not get private communities without permission' do 84 should 'not get private communities without permission' do
85 - community = fast_create(Community)  
86 - fast_create(Community, :public_profile => false) 85 + community = fast_create(Community, :environment_id => environment.id)
  86 + fast_create(Community, :environment_id => environment.id, :public_profile => false)
87 87
88 get "/api/v1/communities/#{community.id}?#{params.to_query}" 88 get "/api/v1/communities/#{community.id}?#{params.to_query}"
89 json = JSON.parse(last_response.body) 89 json = JSON.parse(last_response.body)
@@ -91,17 +91,18 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -91,17 +91,18 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
91 end 91 end
92 92
93 should 'get private community for members' do 93 should 'get private community for members' do
94 - community = fast_create(Community, :public_profile => false) 94 + community = fast_create(Community, :environment_id => environment.id, :public_profile => false, :visible => true)
95 community.add_member(person) 95 community.add_member(person)
96 96
  97 +
97 get "/api/v1/communities/#{community.id}?#{params.to_query}" 98 get "/api/v1/communities/#{community.id}?#{params.to_query}"
98 json = JSON.parse(last_response.body) 99 json = JSON.parse(last_response.body)
99 assert_equal community.id, json['community']['id'] 100 assert_equal community.id, json['community']['id']
100 end 101 end
101 102
102 should 'list person communities' do 103 should 'list person communities' do
103 - community = fast_create(Community)  
104 - fast_create(Community) 104 + community = fast_create(Community, :environment_id => environment.id)
  105 + fast_create(Community, :environment_id => environment.id)
105 community.add_member(person) 106 community.add_member(person)
106 107
107 get "/api/v1/people/#{person.id}/communities?#{params.to_query}" 108 get "/api/v1/people/#{person.id}/communities?#{params.to_query}"
@@ -110,8 +111,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -110,8 +111,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
110 end 111 end
111 112
112 should 'not list person communities invisible' do 113 should 'not list person communities invisible' do
113 - c1 = fast_create(Community)  
114 - c2 = fast_create(Community, :visible => false) 114 + c1 = fast_create(Community, :environment_id => environment.id)
  115 + c2 = fast_create(Community, :environment_id => environment.id, :visible => false)
115 c1.add_member(person) 116 c1.add_member(person)
116 c2.add_member(person) 117 c2.add_member(person)
117 118
test/unit/api/enterprises_test.rb
@@ -8,8 +8,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -8,8 +8,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
8 end 8 end
9 9
10 should 'list only enterprises' do 10 should 'list only enterprises' do
11 - community = fast_create(Community) # should not list this community  
12 - enterprise = fast_create(Enterprise, :public_profile => true) 11 + community = fast_create(Community, :environment_id => environment.id) # should not list this community
  12 + enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true)
13 get "/api/v1/enterprises?#{params.to_query}" 13 get "/api/v1/enterprises?#{params.to_query}"
14 json = JSON.parse(last_response.body) 14 json = JSON.parse(last_response.body)
15 assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id 15 assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id
@@ -17,15 +17,15 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -17,15 +17,15 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
17 end 17 end
18 18
19 should 'list all enterprises' do 19 should 'list all enterprises' do
20 - enterprise1 = fast_create(Enterprise, :public_profile => true)  
21 - enterprise2 = fast_create(Enterprise) 20 + enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true)
  21 + enterprise2 = fast_create(Enterprise, :environment_id => environment.id)
22 get "/api/v1/enterprises?#{params.to_query}" 22 get "/api/v1/enterprises?#{params.to_query}"
23 json = JSON.parse(last_response.body) 23 json = JSON.parse(last_response.body)
24 assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} 24 assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']}
25 end 25 end
26 26
27 should 'not list invisible enterprises' do 27 should 'not list invisible enterprises' do
28 - enterprise1 = fast_create(Enterprise) 28 + enterprise1 = fast_create(Enterprise, :environment_id => environment.id)
29 fast_create(Enterprise, :visible => false) 29 fast_create(Enterprise, :visible => false)
30 30
31 get "/api/v1/enterprises?#{params.to_query}" 31 get "/api/v1/enterprises?#{params.to_query}"
@@ -34,8 +34,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -34,8 +34,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
34 end 34 end
35 35
36 should 'not list private enterprises without permission' do 36 should 'not list private enterprises without permission' do
37 - enterprise1 = fast_create(Enterprise)  
38 - fast_create(Enterprise, :public_profile => false) 37 + enterprise1 = fast_create(Enterprise, :environment_id => environment.id)
  38 + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false)
39 39
40 get "/api/v1/enterprises?#{params.to_query}" 40 get "/api/v1/enterprises?#{params.to_query}"
41 json = JSON.parse(last_response.body) 41 json = JSON.parse(last_response.body)
@@ -43,8 +43,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -43,8 +43,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
43 end 43 end
44 44
45 should 'list private enterprise for members' do 45 should 'list private enterprise for members' do
46 - c1 = fast_create(Enterprise)  
47 - c2 = fast_create(Enterprise, :public_profile => false) 46 + c1 = fast_create(Enterprise, :environment_id => environment.id)
  47 + c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false)
48 c2.add_member(person) 48 c2.add_member(person)
49 49
50 get "/api/v1/enterprises?#{params.to_query}" 50 get "/api/v1/enterprises?#{params.to_query}"
@@ -53,7 +53,7 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -53,7 +53,7 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
53 end 53 end
54 54
55 should 'get enterprise' do 55 should 'get enterprise' do
56 - enterprise = fast_create(Enterprise) 56 + enterprise = fast_create(Enterprise, :environment_id => environment.id)
57 57
58 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" 58 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
59 json = JSON.parse(last_response.body) 59 json = JSON.parse(last_response.body)
@@ -69,8 +69,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -69,8 +69,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
69 end 69 end
70 70
71 should 'not get private enterprises without permission' do 71 should 'not get private enterprises without permission' do
72 - enterprise = fast_create(Enterprise)  
73 - fast_create(Enterprise, :public_profile => false) 72 + enterprise = fast_create(Enterprise, :environment_id => environment.id)
  73 + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false)
74 74
75 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" 75 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
76 json = JSON.parse(last_response.body) 76 json = JSON.parse(last_response.body)
@@ -87,8 +87,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -87,8 +87,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
87 end 87 end
88 88
89 should 'list person enterprises' do 89 should 'list person enterprises' do
90 - enterprise = fast_create(Enterprise)  
91 - fast_create(Enterprise) 90 + enterprise = fast_create(Enterprise, :environment_id => environment.id)
  91 + fast_create(Enterprise, :environment_id => environment.id)
92 enterprise.add_member(person) 92 enterprise.add_member(person)
93 93
94 get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}" 94 get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}"
@@ -97,8 +97,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -97,8 +97,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
97 end 97 end
98 98
99 should 'not list person enterprises invisible' do 99 should 'not list person enterprises invisible' do
100 - c1 = fast_create(Enterprise)  
101 - c2 = fast_create(Enterprise, :visible => false) 100 + c1 = fast_create(Enterprise, :environment_id => environment.id)
  101 + c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false)
102 c1.add_member(person) 102 c1.add_member(person)
103 c2.add_member(person) 103 c2.add_member(person)
104 104
test/unit/api/test_helper.rb
@@ -9,7 +9,7 @@ class ActiveSupport::TestCase @@ -9,7 +9,7 @@ class ActiveSupport::TestCase
9 end 9 end
10 10
11 def login_api 11 def login_api
12 - @environment = fast_create(Environment, :is_default => true) 12 + @environment = Environment.default
13 @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => @environment) 13 @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => @environment)
14 @user.activate 14 @user.activate
15 @person = @user.person 15 @person = @user.person
test/unit/scrap_test.rb
@@ -218,7 +218,7 @@ class ScrapTest &lt; ActiveSupport::TestCase @@ -218,7 +218,7 @@ class ScrapTest &lt; ActiveSupport::TestCase
218 should "update the scrap on reply creation" do 218 should "update the scrap on reply creation" do
219 person = create_user.person 219 person = create_user.person
220 s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) 220 s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01'))
221 - assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') 221 + assert_equal DateTime.parse('2010-01-01'), s.updated_at
222 DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) 222 DateTime.stubs(:now).returns(DateTime.parse('2010-09-07'))
223 s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id) 223 s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id)
224 s.reload 224 s.reload