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,8 +154,8 @@ class CommentsTest < ActiveSupport::TestCase | ||
154 | assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} | 154 | assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} |
155 | end | 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 | person = fast_create(Person) | 159 | person = fast_create(Person) |
160 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) | 160 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) |
161 | assert !article.published? | 161 | assert !article.published? |
@@ -188,9 +188,9 @@ class CommentsTest < ActiveSupport::TestCase | @@ -188,9 +188,9 @@ class CommentsTest < ActiveSupport::TestCase | ||
188 | assert_equal 200, last_response.status | 188 | assert_equal 200, last_response.status |
189 | assert_equal comment.id, json['comment']['id'] | 189 | assert_equal comment.id, json['comment']['id'] |
190 | end | 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 | person = fast_create(Person) | 194 | person = fast_create(Person) |
195 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | 195 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing") |
196 | body = 'My comment' | 196 | body = 'My comment' |
@@ -202,4 +202,29 @@ class CommentsTest < ActiveSupport::TestCase | @@ -202,4 +202,29 @@ class CommentsTest < ActiveSupport::TestCase | ||
202 | assert_equal 401, last_response.status | 202 | assert_equal 401, last_response.status |
203 | end | 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 | end | 230 | end |
test/api/communities_test.rb
@@ -25,7 +25,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -25,7 +25,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
25 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} | 25 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
26 | end | 26 | end |
27 | 27 | ||
28 | - should 'logged user not list invisible communities' do | 28 | + should 'not, logged user list invisible communities' do |
29 | login_api | 29 | login_api |
30 | community1 = fast_create(Community, :environment_id => environment.id) | 30 | community1 = fast_create(Community, :environment_id => environment.id) |
31 | fast_create(Community, :environment_id => environment.id, :visible => false) | 31 | fast_create(Community, :environment_id => environment.id, :visible => false) |
@@ -80,7 +80,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -80,7 +80,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
80 | assert_equal community.id, json['community']['id'] | 80 | assert_equal community.id, json['community']['id'] |
81 | end | 81 | end |
82 | 82 | ||
83 | - should 'logged user not get invisible community' do | 83 | + should 'not, logged user get invisible community' do |
84 | login_api | 84 | login_api |
85 | community = fast_create(Community, :environment_id => environment.id, :visible => false) | 85 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
86 | 86 | ||
@@ -89,7 +89,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -89,7 +89,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
89 | assert json['community'].blank? | 89 | assert json['community'].blank? |
90 | end | 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 | login_api | 93 | login_api |
94 | community = fast_create(Community, :environment_id => environment.id) | 94 | community = fast_create(Community, :environment_id => environment.id) |
95 | fast_create(Community, :environment_id => environment.id, :public_profile => false) | 95 | fast_create(Community, :environment_id => environment.id, :public_profile => false) |
@@ -120,7 +120,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -120,7 +120,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
120 | assert_equivalent [community.id], json['communities'].map {|c| c['id']} | 120 | assert_equivalent [community.id], json['communities'].map {|c| c['id']} |
121 | end | 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 | login_api | 124 | login_api |
125 | c1 = fast_create(Community, :environment_id => environment.id) | 125 | c1 = fast_create(Community, :environment_id => environment.id) |
126 | c2 = fast_create(Community, :environment_id => environment.id, :visible => false) | 126 | c2 = fast_create(Community, :environment_id => environment.id, :visible => false) |
@@ -190,7 +190,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -190,7 +190,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
190 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} | 190 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
191 | end | 191 | end |
192 | 192 | ||
193 | - should 'not anonymous list invisible communities' do | 193 | + should 'not, anonymous list invisible communities' do |
194 | anonymous_setup | 194 | anonymous_setup |
195 | community1 = fast_create(Community, :environment_id => environment.id) | 195 | community1 = fast_create(Community, :environment_id => environment.id) |
196 | fast_create(Community, :environment_id => environment.id, :visible => false) | 196 | fast_create(Community, :environment_id => environment.id, :visible => false) |
@@ -210,9 +210,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -210,9 +210,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
210 | assert_equal [community1.id, community2.id], json['communities'].map {|c| c['id']} | 210 | assert_equal [community1.id, community2.id], json['communities'].map {|c| c['id']} |
211 | end | 211 | end |
212 | 212 | ||
213 | - | ||
214 | - | ||
215 | - should 'not anonymous create a community' do | 213 | + should 'not, anonymous create a community' do |
216 | anonymous_setup | 214 | anonymous_setup |
217 | params[:community] = {:name => 'some'} | 215 | params[:community] = {:name => 'some'} |
218 | post "/api/v1/communities?#{params.to_query}" | 216 | post "/api/v1/communities?#{params.to_query}" |
@@ -228,7 +226,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -228,7 +226,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
228 | assert_equal community.id, json['community']['id'] | 226 | assert_equal community.id, json['community']['id'] |
229 | end | 227 | end |
230 | 228 | ||
231 | - should 'not anonymous get invisible community' do | 229 | + should 'not, anonymous get invisible community' do |
232 | anonymous_setup | 230 | anonymous_setup |
233 | community = fast_create(Community, :environment_id => environment.id, :visible => false) | 231 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
234 | get "/api/v1/communities/#{community.id}" | 232 | get "/api/v1/communities/#{community.id}" |
@@ -236,7 +234,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -236,7 +234,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
236 | assert json['community'].blank? | 234 | assert json['community'].blank? |
237 | end | 235 | end |
238 | 236 | ||
239 | - should 'anonymous not get private communities' do | 237 | + should 'not, anonymous get private communities' do |
240 | anonymous_setup | 238 | anonymous_setup |
241 | community = fast_create(Community, :environment_id => environment.id) | 239 | community = fast_create(Community, :environment_id => environment.id) |
242 | fast_create(Community, :environment_id => environment.id, :public_profile => false) | 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,10 +4,20 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | Enterprise.delete_all | 6 | Enterprise.delete_all |
7 | + end | ||
8 | + | ||
9 | + should 'logger user list only enterprises' do | ||
7 | login_api | 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 | end | 17 | end |
9 | 18 | ||
10 | - should 'list only enterprises' do | 19 | + should 'anonymous list only enterprises' do |
20 | + anonymous_setup | ||
11 | community = fast_create(Community, :environment_id => environment.id) # should not list this community | 21 | 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) | 22 | enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) |
13 | get "/api/v1/enterprises?#{params.to_query}" | 23 | get "/api/v1/enterprises?#{params.to_query}" |
@@ -16,7 +26,17 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -16,7 +26,17 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
16 | assert_not_includes json['enterprises'].map {|c| c['id']}, community.id | 26 | assert_not_includes json['enterprises'].map {|c| c['id']}, community.id |
17 | end | 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 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) | 40 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) |
21 | enterprise2 = fast_create(Enterprise, :environment_id => environment.id) | 41 | enterprise2 = fast_create(Enterprise, :environment_id => environment.id) |
22 | get "/api/v1/enterprises?#{params.to_query}" | 42 | get "/api/v1/enterprises?#{params.to_query}" |
@@ -25,6 +45,27 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -25,6 +45,27 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
25 | end | 45 | end |
26 | 46 | ||
27 | should 'not list invisible enterprises' do | 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 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | 69 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) |
29 | fast_create(Enterprise, :visible => false) | 70 | fast_create(Enterprise, :visible => false) |
30 | 71 | ||
@@ -33,7 +74,8 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -33,7 +74,8 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
33 | assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} | 74 | assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} |
34 | end | 75 | end |
35 | 76 | ||
36 | - should 'list private enterprises' do | 77 | + should 'anonymous list private enterprises' do |
78 | + anonymous_setup | ||
37 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | 79 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) |
38 | enterprise2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | 80 | enterprise2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) |
39 | 81 | ||
@@ -42,7 +84,18 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -42,7 +84,18 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
42 | assert_equal [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} | 84 | assert_equal [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} |
43 | end | 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 | c1 = fast_create(Enterprise, :environment_id => environment.id) | 99 | c1 = fast_create(Enterprise, :environment_id => environment.id) |
47 | c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | 100 | c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) |
48 | c2.add_member(person) | 101 | c2.add_member(person) |
@@ -52,7 +105,17 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -52,7 +105,17 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
52 | assert_equivalent [c1.id, c2.id], json['enterprises'].map {|c| c['id']} | 105 | assert_equivalent [c1.id, c2.id], json['enterprises'].map {|c| c['id']} |
53 | end | 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 | enterprise = fast_create(Enterprise, :environment_id => environment.id) | 119 | enterprise = fast_create(Enterprise, :environment_id => environment.id) |
57 | 120 | ||
58 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" | 121 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" |
@@ -60,7 +123,17 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -60,7 +123,17 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
60 | assert_equal enterprise.id, json['enterprise']['id'] | 123 | assert_equal enterprise.id, json['enterprise']['id'] |
61 | end | 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 | enterprise = fast_create(Enterprise, :visible => false) | 137 | enterprise = fast_create(Enterprise, :visible => false) |
65 | 138 | ||
66 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" | 139 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" |
@@ -69,6 +142,17 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -69,6 +142,17 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
69 | end | 142 | end |
70 | 143 | ||
71 | should 'not get private enterprises without permission' do | 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 | enterprise = fast_create(Enterprise, :environment_id => environment.id) | 156 | enterprise = fast_create(Enterprise, :environment_id => environment.id) |
73 | fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | 157 | fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) |
74 | 158 | ||
@@ -78,6 +162,7 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -78,6 +162,7 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
78 | end | 162 | end |
79 | 163 | ||
80 | should 'get private enterprise for members' do | 164 | should 'get private enterprise for members' do |
165 | + login_api | ||
81 | enterprise = fast_create(Enterprise, :public_profile => false) | 166 | enterprise = fast_create(Enterprise, :public_profile => false) |
82 | enterprise.add_member(person) | 167 | enterprise.add_member(person) |
83 | 168 | ||
@@ -87,6 +172,7 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -87,6 +172,7 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
87 | end | 172 | end |
88 | 173 | ||
89 | should 'list person enterprises' do | 174 | should 'list person enterprises' do |
175 | + login_api | ||
90 | enterprise = fast_create(Enterprise, :environment_id => environment.id) | 176 | enterprise = fast_create(Enterprise, :environment_id => environment.id) |
91 | fast_create(Enterprise, :environment_id => environment.id) | 177 | fast_create(Enterprise, :environment_id => environment.id) |
92 | enterprise.add_member(person) | 178 | enterprise.add_member(person) |
@@ -97,6 +183,7 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -97,6 +183,7 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
97 | end | 183 | end |
98 | 184 | ||
99 | should 'not list person enterprises invisible' do | 185 | should 'not list person enterprises invisible' do |
186 | + login_api | ||
100 | c1 = fast_create(Enterprise, :environment_id => environment.id) | 187 | c1 = fast_create(Enterprise, :environment_id => environment.id) |
101 | c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false) | 188 | c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false) |
102 | c1.add_member(person) | 189 | c1.add_member(person) |
test/api/profiles_test.rb