Commit 085aaaa9185809b174b4ad05bd1cb7e691dce599
Committed by
Leandro Santos
1 parent
52a0efb0
Exists in
send_email_to_admins
and in
5 other branches
Fix merge problems with master and other small fixes
Showing
4 changed files
with
131 additions
and
22 deletions
Show diff stats
test/api/comments_test.rb
... | ... | @@ -154,8 +154,8 @@ class CommentsTest < ActiveSupport::TestCase |
154 | 154 | assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} |
155 | 155 | end |
156 | 156 | |
157 | - should 'not visitor list comments if has no permission to view the source article' do | |
158 | - visitor_setup | |
157 | + should 'not, anonymous list comments if has no permission to view the source article' do | |
158 | + anonymous_setup | |
159 | 159 | person = fast_create(Person) |
160 | 160 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) |
161 | 161 | assert !article.published? |
... | ... | @@ -188,9 +188,9 @@ class CommentsTest < ActiveSupport::TestCase |
188 | 188 | assert_equal 200, last_response.status |
189 | 189 | assert_equal comment.id, json['comment']['id'] |
190 | 190 | end |
191 | - | |
192 | - should 'not visitor comment an article (at least so far...)' do | |
193 | - visitor_setup | |
191 | + | |
192 | + should 'not, anonymous comment an article (at least so far...)' do | |
193 | + anonymous_setup | |
194 | 194 | person = fast_create(Person) |
195 | 195 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing") |
196 | 196 | body = 'My comment' |
... | ... | @@ -202,4 +202,29 @@ class CommentsTest < ActiveSupport::TestCase |
202 | 202 | assert_equal 401, last_response.status |
203 | 203 | end |
204 | 204 | |
205 | + should 'paginate comments' do | |
206 | + login_api | |
207 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
208 | + 5.times { article.comments.create!(:body => "some comment", :author => user.person) } | |
209 | + params[:per_page] = 3 | |
210 | + | |
211 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
212 | + json = JSON.parse(last_response.body) | |
213 | + assert_equal 200, last_response.status | |
214 | + assert_equal 3, json["comments"].length | |
215 | + end | |
216 | + | |
217 | + should 'return only root comments' do | |
218 | + login_api | |
219 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
220 | + comment1 = article.comments.create!(:body => "some comment", :author => user.person) | |
221 | + comment2 = article.comments.create!(:body => "another comment", :author => user.person, :reply_of_id => comment1.id) | |
222 | + params[:without_reply] = true | |
223 | + | |
224 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
225 | + json = JSON.parse(last_response.body) | |
226 | + assert_equal 200, last_response.status | |
227 | + assert_equal [comment1.id], json["comments"].map { |c| c['id'] } | |
228 | + end | |
229 | + | |
205 | 230 | end | ... | ... |
test/api/communities_test.rb
... | ... | @@ -25,7 +25,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
25 | 25 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
26 | 26 | end |
27 | 27 | |
28 | - should 'logged user not list invisible communities' do | |
28 | + should 'not, logged user list invisible communities' do | |
29 | 29 | login_api |
30 | 30 | community1 = fast_create(Community, :environment_id => environment.id) |
31 | 31 | fast_create(Community, :environment_id => environment.id, :visible => false) |
... | ... | @@ -80,7 +80,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
80 | 80 | assert_equal community.id, json['community']['id'] |
81 | 81 | end |
82 | 82 | |
83 | - should 'logged user not get invisible community' do | |
83 | + should 'not, logged user get invisible community' do | |
84 | 84 | login_api |
85 | 85 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
86 | 86 | |
... | ... | @@ -89,7 +89,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
89 | 89 | assert json['community'].blank? |
90 | 90 | end |
91 | 91 | |
92 | - should 'logged user not get private communities without permission' do | |
92 | + should 'not, logged user get private communities without permission' do | |
93 | 93 | login_api |
94 | 94 | community = fast_create(Community, :environment_id => environment.id) |
95 | 95 | fast_create(Community, :environment_id => environment.id, :public_profile => false) |
... | ... | @@ -120,7 +120,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
120 | 120 | assert_equivalent [community.id], json['communities'].map {|c| c['id']} |
121 | 121 | end |
122 | 122 | |
123 | - should 'logged user not list person communities invisible' do | |
123 | + should 'not, logged user list person communities invisible' do | |
124 | 124 | login_api |
125 | 125 | c1 = fast_create(Community, :environment_id => environment.id) |
126 | 126 | c2 = fast_create(Community, :environment_id => environment.id, :visible => false) |
... | ... | @@ -190,7 +190,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
190 | 190 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
191 | 191 | end |
192 | 192 | |
193 | - should 'not anonymous list invisible communities' do | |
193 | + should 'not, anonymous list invisible communities' do | |
194 | 194 | anonymous_setup |
195 | 195 | community1 = fast_create(Community, :environment_id => environment.id) |
196 | 196 | fast_create(Community, :environment_id => environment.id, :visible => false) |
... | ... | @@ -210,9 +210,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
210 | 210 | assert_equal [community1.id, community2.id], json['communities'].map {|c| c['id']} |
211 | 211 | end |
212 | 212 | |
213 | - | |
214 | - | |
215 | - should 'not anonymous create a community' do | |
213 | + should 'not, anonymous create a community' do | |
216 | 214 | anonymous_setup |
217 | 215 | params[:community] = {:name => 'some'} |
218 | 216 | post "/api/v1/communities?#{params.to_query}" |
... | ... | @@ -228,7 +226,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
228 | 226 | assert_equal community.id, json['community']['id'] |
229 | 227 | end |
230 | 228 | |
231 | - should 'not anonymous get invisible community' do | |
229 | + should 'not, anonymous get invisible community' do | |
232 | 230 | anonymous_setup |
233 | 231 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
234 | 232 | get "/api/v1/communities/#{community.id}" |
... | ... | @@ -236,7 +234,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
236 | 234 | assert json['community'].blank? |
237 | 235 | end |
238 | 236 | |
239 | - should 'anonymous not get private communities' do | |
237 | + should 'not, anonymous get private communities' do | |
240 | 238 | anonymous_setup |
241 | 239 | community = fast_create(Community, :environment_id => environment.id) |
242 | 240 | fast_create(Community, :environment_id => environment.id, :public_profile => false) | ... | ... |
test/api/enterprises_test.rb
... | ... | @@ -4,10 +4,20 @@ class EnterprisesTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | Enterprise.delete_all |
7 | + end | |
8 | + | |
9 | + should 'logger user list only enterprises' do | |
7 | 10 | login_api |
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}" | |
14 | + json = JSON.parse(last_response.body) | |
15 | + assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id | |
16 | + assert_not_includes json['enterprises'].map {|c| c['id']}, community.id | |
8 | 17 | end |
9 | 18 | |
10 | - should 'list only enterprises' do | |
19 | + should 'anonymous list only enterprises' do | |
20 | + anonymous_setup | |
11 | 21 | community = fast_create(Community, :environment_id => environment.id) # should not list this community |
12 | 22 | enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) |
13 | 23 | get "/api/v1/enterprises?#{params.to_query}" |
... | ... | @@ -16,7 +26,17 @@ class EnterprisesTest < ActiveSupport::TestCase |
16 | 26 | assert_not_includes json['enterprises'].map {|c| c['id']}, community.id |
17 | 27 | end |
18 | 28 | |
19 | - should 'list all enterprises' do | |
29 | + should 'anonymous list all enterprises' do | |
30 | + anonymous_setup | |
31 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) | |
32 | + enterprise2 = fast_create(Enterprise, :environment_id => environment.id) | |
33 | + get "/api/v1/enterprises?#{params.to_query}" | |
34 | + json = JSON.parse(last_response.body) | |
35 | + assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} | |
36 | + end | |
37 | + | |
38 | + should 'logger user list all enterprises' do | |
39 | + login_api | |
20 | 40 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) |
21 | 41 | enterprise2 = fast_create(Enterprise, :environment_id => environment.id) |
22 | 42 | get "/api/v1/enterprises?#{params.to_query}" |
... | ... | @@ -25,6 +45,27 @@ class EnterprisesTest < ActiveSupport::TestCase |
25 | 45 | end |
26 | 46 | |
27 | 47 | should 'not list invisible enterprises' do |
48 | + login_api | |
49 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | |
50 | + fast_create(Enterprise, :visible => false) | |
51 | + | |
52 | + get "/api/v1/enterprises?#{params.to_query}" | |
53 | + json = JSON.parse(last_response.body) | |
54 | + assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} | |
55 | + end | |
56 | + | |
57 | + should 'not, anonymous list invisible enterprises' do | |
58 | + anonymous_setup | |
59 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | |
60 | + fast_create(Enterprise, :visible => false) | |
61 | + | |
62 | + get "/api/v1/enterprises?#{params.to_query}" | |
63 | + json = JSON.parse(last_response.body) | |
64 | + assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} | |
65 | + end | |
66 | + | |
67 | + should 'not, logger user list invisible enterprises' do | |
68 | + login_api | |
28 | 69 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) |
29 | 70 | fast_create(Enterprise, :visible => false) |
30 | 71 | |
... | ... | @@ -33,7 +74,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
33 | 74 | assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} |
34 | 75 | end |
35 | 76 | |
36 | - should 'list private enterprises' do | |
77 | + should 'anonymous list private enterprises' do | |
78 | + anonymous_setup | |
37 | 79 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) |
38 | 80 | enterprise2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) |
39 | 81 | |
... | ... | @@ -42,7 +84,18 @@ class EnterprisesTest < ActiveSupport::TestCase |
42 | 84 | assert_equal [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} |
43 | 85 | end |
44 | 86 | |
45 | - should 'list private enterprise for members' do | |
87 | + should 'logged user list private enterprises' do | |
88 | + login_api | |
89 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | |
90 | + enterprise2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | |
91 | + | |
92 | + get "/api/v1/enterprises?#{params.to_query}" | |
93 | + json = JSON.parse(last_response.body) | |
94 | + assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} | |
95 | + end | |
96 | + | |
97 | + should 'logged user list private enterprise for members' do | |
98 | + login_api | |
46 | 99 | c1 = fast_create(Enterprise, :environment_id => environment.id) |
47 | 100 | c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) |
48 | 101 | c2.add_member(person) |
... | ... | @@ -52,7 +105,17 @@ class EnterprisesTest < ActiveSupport::TestCase |
52 | 105 | assert_equivalent [c1.id, c2.id], json['enterprises'].map {|c| c['id']} |
53 | 106 | end |
54 | 107 | |
55 | - should 'get enterprise' do | |
108 | + should 'anonymous get enterprise' do | |
109 | + anonymous_setup | |
110 | + enterprise = fast_create(Enterprise, :environment_id => environment.id) | |
111 | + | |
112 | + get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" | |
113 | + json = JSON.parse(last_response.body) | |
114 | + assert_equal enterprise.id, json['enterprise']['id'] | |
115 | + end | |
116 | + | |
117 | + should 'logged user get enterprise' do | |
118 | + login_api | |
56 | 119 | enterprise = fast_create(Enterprise, :environment_id => environment.id) |
57 | 120 | |
58 | 121 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" |
... | ... | @@ -60,7 +123,17 @@ class EnterprisesTest < ActiveSupport::TestCase |
60 | 123 | assert_equal enterprise.id, json['enterprise']['id'] |
61 | 124 | end |
62 | 125 | |
63 | - should 'not get invisible enterprise' do | |
126 | + should 'not, logger user get invisible enterprise' do | |
127 | + login_api | |
128 | + enterprise = fast_create(Enterprise, :visible => false) | |
129 | + | |
130 | + get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" | |
131 | + json = JSON.parse(last_response.body) | |
132 | + assert json['enterprise'].blank? | |
133 | + end | |
134 | + | |
135 | + should 'not, anonymous get invisible enterprise' do | |
136 | + anonymous_setup | |
64 | 137 | enterprise = fast_create(Enterprise, :visible => false) |
65 | 138 | |
66 | 139 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" |
... | ... | @@ -69,6 +142,17 @@ class EnterprisesTest < ActiveSupport::TestCase |
69 | 142 | end |
70 | 143 | |
71 | 144 | should 'not get private enterprises without permission' do |
145 | + login_api | |
146 | + enterprise = fast_create(Enterprise, :environment_id => environment.id) | |
147 | + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | |
148 | + | |
149 | + get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" | |
150 | + json = JSON.parse(last_response.body) | |
151 | + assert_equal enterprise.id, json['enterprise']['id'] | |
152 | + end | |
153 | + | |
154 | + should 'not, anonymous get private enterprises' do | |
155 | + anonymous_setup | |
72 | 156 | enterprise = fast_create(Enterprise, :environment_id => environment.id) |
73 | 157 | fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) |
74 | 158 | |
... | ... | @@ -78,6 +162,7 @@ class EnterprisesTest < ActiveSupport::TestCase |
78 | 162 | end |
79 | 163 | |
80 | 164 | should 'get private enterprise for members' do |
165 | + login_api | |
81 | 166 | enterprise = fast_create(Enterprise, :public_profile => false) |
82 | 167 | enterprise.add_member(person) |
83 | 168 | |
... | ... | @@ -87,6 +172,7 @@ class EnterprisesTest < ActiveSupport::TestCase |
87 | 172 | end |
88 | 173 | |
89 | 174 | should 'list person enterprises' do |
175 | + login_api | |
90 | 176 | enterprise = fast_create(Enterprise, :environment_id => environment.id) |
91 | 177 | fast_create(Enterprise, :environment_id => environment.id) |
92 | 178 | enterprise.add_member(person) |
... | ... | @@ -97,6 +183,7 @@ class EnterprisesTest < ActiveSupport::TestCase |
97 | 183 | end |
98 | 184 | |
99 | 185 | should 'not list person enterprises invisible' do |
186 | + login_api | |
100 | 187 | c1 = fast_create(Enterprise, :environment_id => environment.id) |
101 | 188 | c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false) |
102 | 189 | c1.add_member(person) | ... | ... |