Commit d6d98372d6f771cef8ce67e2d8960641a9d57041
Committed by
Gabriel Silva
1 parent
82498934
Exists in
send_email_to_admins
and in
5 other branches
API unlocked for visitor
Showing
9 changed files
with
29 additions
and
68 deletions
Show diff stats
app/models/organization.rb
@@ -17,8 +17,6 @@ class Organization < Profile | @@ -17,8 +17,6 @@ class Organization < Profile | ||
17 | # 4) The user is not a member of the organization but the organization is | 17 | # 4) The user is not a member of the organization but the organization is |
18 | # visible, public and enabled. | 18 | # visible, public and enabled. |
19 | def self.visible_for_person(person) | 19 | def self.visible_for_person(person) |
20 | - # Visitor if person.nil? | ||
21 | - person_id = person.nil? ? nil : person.id | ||
22 | joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = "profiles"."id" | 20 | joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = "profiles"."id" |
23 | AND "role_assignments"."resource_type" = \'Profile\') OR ( | 21 | AND "role_assignments"."resource_type" = \'Profile\') OR ( |
24 | "role_assignments"."resource_id" = "profiles"."environment_id" AND | 22 | "role_assignments"."resource_id" = "profiles"."environment_id" AND |
@@ -30,8 +28,8 @@ class Organization < Profile | @@ -30,8 +28,8 @@ class Organization < Profile | ||
30 | ( ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR | 28 | ( ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR |
31 | ( profiles.public_profile = ? AND profiles.enabled = ? ) ) AND | 29 | ( profiles.public_profile = ? AND profiles.enabled = ? ) ) AND |
32 | ( profiles.visible = ? ) )', | 30 | ( profiles.visible = ? ) )', |
33 | - 'profile_admin', 'environment_administrator', Profile.name, person_id, | ||
34 | - Profile.name, person_id, true, true, true] | 31 | + 'profile_admin', 'environment_administrator', Profile.name, person.id, |
32 | + Profile.name, person.id, true, true, true] | ||
35 | ).uniq | 33 | ).uniq |
36 | end | 34 | end |
37 | 35 |
app/models/person.rb
@@ -42,8 +42,6 @@ class Person < Profile | @@ -42,8 +42,6 @@ class Person < Profile | ||
42 | } | 42 | } |
43 | 43 | ||
44 | scope :visible_for_person, lambda { |person| | 44 | scope :visible_for_person, lambda { |person| |
45 | - # Visitor if person.nil? | ||
46 | - person_id = person.nil? ? nil : person.id | ||
47 | joins('LEFT JOIN "role_assignments" ON | 45 | joins('LEFT JOIN "role_assignments" ON |
48 | "role_assignments"."resource_id" = "profiles"."environment_id" AND | 46 | "role_assignments"."resource_id" = "profiles"."environment_id" AND |
49 | "role_assignments"."resource_type" = \'Environment\'') | 47 | "role_assignments"."resource_type" = \'Environment\'') |
@@ -52,7 +50,7 @@ class Person < Profile | @@ -52,7 +50,7 @@ class Person < Profile | ||
52 | .where( | 50 | .where( |
53 | ['( roles.key = ? AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( | 51 | ['( roles.key = ? AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( |
54 | ( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?) )', | 52 | ( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?) )', |
55 | - 'environment_administrator', Profile.name, person_id, person_id, true, true] | 53 | + 'environment_administrator', Profile.name, person.id, person.id, true, true] |
56 | ).uniq | 54 | ).uniq |
57 | } | 55 | } |
58 | 56 |
test/api/categories_test.rb
@@ -2,8 +2,7 @@ require_relative 'test_helper' | @@ -2,8 +2,7 @@ require_relative 'test_helper' | ||
2 | 2 | ||
3 | class CategoriesTest < ActiveSupport::TestCase | 3 | class CategoriesTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | - | ||
6 | - should 'logged user list categories' do | 5 | + should 'list categories to logged user' do |
7 | login_api | 6 | login_api |
8 | category = fast_create(Category, :environment_id => environment.id) | 7 | category = fast_create(Category, :environment_id => environment.id) |
9 | get "/api/v1/categories/?#{params.to_query}" | 8 | get "/api/v1/categories/?#{params.to_query}" |
@@ -11,7 +10,7 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -11,7 +10,7 @@ class CategoriesTest < ActiveSupport::TestCase | ||
11 | assert_includes json["categories"].map { |c| c["name"] }, category.name | 10 | assert_includes json["categories"].map { |c| c["name"] }, category.name |
12 | end | 11 | end |
13 | 12 | ||
14 | - should 'logged user get category by id' do | 13 | + should 'get category by id to logged user' do |
15 | login_api | 14 | login_api |
16 | category = fast_create(Category, :environment_id => environment.id) | 15 | category = fast_create(Category, :environment_id => environment.id) |
17 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" | 16 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" |
@@ -19,7 +18,7 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -19,7 +18,7 @@ class CategoriesTest < ActiveSupport::TestCase | ||
19 | assert_equal category.name, json["category"]["name"] | 18 | assert_equal category.name, json["category"]["name"] |
20 | end | 19 | end |
21 | 20 | ||
22 | - should 'logged user list parent and children when get category by id' do | 21 | + should 'list parent and children when get category by id to logged user' do |
23 | login_api | 22 | login_api |
24 | parent = fast_create(Category, :environment_id => environment.id) | 23 | parent = fast_create(Category, :environment_id => environment.id) |
25 | child_1 = fast_create(Category, :environment_id => environment.id) | 24 | child_1 = fast_create(Category, :environment_id => environment.id) |
@@ -37,7 +36,7 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -37,7 +36,7 @@ class CategoriesTest < ActiveSupport::TestCase | ||
37 | assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } | 36 | assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } |
38 | end | 37 | end |
39 | 38 | ||
40 | - should 'logged user include parent in categories list if params is true' do | 39 | + should 'include parent in categories list if params is true to logged_user' do |
41 | login_api | 40 | login_api |
42 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category | 41 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category |
43 | child_1 = fast_create(Category, :environment_id => environment.id) | 42 | child_1 = fast_create(Category, :environment_id => environment.id) |
@@ -60,7 +59,7 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -60,7 +59,7 @@ class CategoriesTest < ActiveSupport::TestCase | ||
60 | json["categories"].map { |c| c['parent'] && c['parent']['id'] } | 59 | json["categories"].map { |c| c['parent'] && c['parent']['id'] } |
61 | end | 60 | end |
62 | 61 | ||
63 | - should 'logged user include children in categories list if params is true' do | 62 | + should 'include children in categories list if params is true to logged user' do |
64 | login_api | 63 | login_api |
65 | category = fast_create(Category, :environment_id => environment.id) | 64 | category = fast_create(Category, :environment_id => environment.id) |
66 | child_1 = fast_create(Category, :environment_id => environment.id) | 65 | child_1 = fast_create(Category, :environment_id => environment.id) |
@@ -88,7 +87,7 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -88,7 +87,7 @@ class CategoriesTest < ActiveSupport::TestCase | ||
88 | expose_attributes = %w(id name full_name image display_color) | 87 | expose_attributes = %w(id name full_name image display_color) |
89 | 88 | ||
90 | expose_attributes.each do |attr| | 89 | expose_attributes.each do |attr| |
91 | - should "logged user expose category #{attr} attribute by default" do | 90 | + should "expose category #{attr} attribute by default to logged user" do |
92 | login_api | 91 | login_api |
93 | category = fast_create(Category, :environment_id => environment.id) | 92 | category = fast_create(Category, :environment_id => environment.id) |
94 | get "/api/v1/categories/?#{params.to_query}" | 93 | get "/api/v1/categories/?#{params.to_query}" |
@@ -97,24 +96,21 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -97,24 +96,21 @@ class CategoriesTest < ActiveSupport::TestCase | ||
97 | end | 96 | end |
98 | end | 97 | end |
99 | 98 | ||
100 | - should 'anonymous list categories' do | ||
101 | - anonymous_setup | 99 | + should 'list categories to anonymous' do |
102 | category = fast_create(Category, :environment_id => environment.id) | 100 | category = fast_create(Category, :environment_id => environment.id) |
103 | get "/api/v1/categories/?#{params.to_query}" | 101 | get "/api/v1/categories/?#{params.to_query}" |
104 | json = JSON.parse(last_response.body) | 102 | json = JSON.parse(last_response.body) |
105 | assert_includes json["categories"].map { |c| c["name"] }, category.name | 103 | assert_includes json["categories"].map { |c| c["name"] }, category.name |
106 | end | 104 | end |
107 | 105 | ||
108 | - should 'anonymous get category by id' do | ||
109 | - anonymous_setup | 106 | + should 'get category by id to anonymous' do |
110 | category = fast_create(Category, :environment_id => environment.id) | 107 | category = fast_create(Category, :environment_id => environment.id) |
111 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" | 108 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" |
112 | json = JSON.parse(last_response.body) | 109 | json = JSON.parse(last_response.body) |
113 | assert_equal category.name, json["category"]["name"] | 110 | assert_equal category.name, json["category"]["name"] |
114 | end | 111 | end |
115 | 112 | ||
116 | - should 'anonymous list parent and children when get category by id' do | ||
117 | - anonymous_setup | 113 | + should 'list parent and children when get category by id to anonymous' do |
118 | parent = fast_create(Category, :environment_id => environment.id) | 114 | parent = fast_create(Category, :environment_id => environment.id) |
119 | child_1 = fast_create(Category, :environment_id => environment.id) | 115 | child_1 = fast_create(Category, :environment_id => environment.id) |
120 | child_2 = fast_create(Category, :environment_id => environment.id) | 116 | child_2 = fast_create(Category, :environment_id => environment.id) |
@@ -132,7 +128,6 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -132,7 +128,6 @@ class CategoriesTest < ActiveSupport::TestCase | ||
132 | end | 128 | end |
133 | 129 | ||
134 | should 'anonymous include parent in categories list if params is true' do | 130 | should 'anonymous include parent in categories list if params is true' do |
135 | - anonymous_setup | ||
136 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category | 131 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category |
137 | child_1 = fast_create(Category, :environment_id => environment.id) | 132 | child_1 = fast_create(Category, :environment_id => environment.id) |
138 | child_2 = fast_create(Category, :environment_id => environment.id) | 133 | child_2 = fast_create(Category, :environment_id => environment.id) |
@@ -155,7 +150,6 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -155,7 +150,6 @@ class CategoriesTest < ActiveSupport::TestCase | ||
155 | end | 150 | end |
156 | 151 | ||
157 | should 'anonymous include children in categories list if params is true' do | 152 | should 'anonymous include children in categories list if params is true' do |
158 | - anonymous_setup | ||
159 | category = fast_create(Category, :environment_id => environment.id) | 153 | category = fast_create(Category, :environment_id => environment.id) |
160 | child_1 = fast_create(Category, :environment_id => environment.id) | 154 | child_1 = fast_create(Category, :environment_id => environment.id) |
161 | child_2 = fast_create(Category, :environment_id => environment.id) | 155 | child_2 = fast_create(Category, :environment_id => environment.id) |
@@ -180,8 +174,7 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -180,8 +174,7 @@ class CategoriesTest < ActiveSupport::TestCase | ||
180 | end | 174 | end |
181 | 175 | ||
182 | expose_attributes.each do |attr| | 176 | expose_attributes.each do |attr| |
183 | - should "anonymous expose category #{attr} attribute by default" do | ||
184 | - anonymous_setup | 177 | + should "expose category #{attr} attribute by default to anonymous" do |
185 | category = fast_create(Category, :environment_id => environment.id) | 178 | category = fast_create(Category, :environment_id => environment.id) |
186 | get "/api/v1/categories/?#{params.to_query}" | 179 | get "/api/v1/categories/?#{params.to_query}" |
187 | json = JSON.parse(last_response.body) | 180 | json = JSON.parse(last_response.body) |
@@ -189,6 +182,4 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -189,6 +182,4 @@ class CategoriesTest < ActiveSupport::TestCase | ||
189 | end | 182 | end |
190 | end | 183 | end |
191 | 184 | ||
192 | - | ||
193 | - | ||
194 | end | 185 | end |
test/api/comments_test.rb
@@ -4,7 +4,6 @@ class CommentsTest < ActiveSupport::TestCase | @@ -4,7 +4,6 @@ class CommentsTest < ActiveSupport::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @local_person = fast_create(Person) | 6 | @local_person = fast_create(Person) |
7 | - anonymous_setup | ||
8 | end | 7 | end |
9 | attr_reader :local_person | 8 | attr_reader :local_person |
10 | 9 | ||
@@ -82,16 +81,16 @@ class CommentsTest < ActiveSupport::TestCase | @@ -82,16 +81,16 @@ class CommentsTest < ActiveSupport::TestCase | ||
82 | end | 81 | end |
83 | 82 | ||
84 | should 'logged user comment creation define the source' do | 83 | should 'logged user comment creation define the source' do |
85 | - login_api | ||
86 | - amount = Comment.count | ||
87 | - article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing") | ||
88 | - body = 'My comment' | ||
89 | - params.merge!({:body => body}) | 84 | + login_api |
85 | + amount = Comment.count | ||
86 | + article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing") | ||
87 | + body = 'My comment' | ||
88 | + params.merge!({:body => body}) | ||
90 | 89 | ||
91 | - post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | ||
92 | - assert_equal amount + 1, Comment.count | ||
93 | - comment = Comment.last | ||
94 | - assert_not_nil comment.source | 90 | + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" |
91 | + assert_equal amount + 1, Comment.count | ||
92 | + comment = Comment.last | ||
93 | + assert_not_nil comment.source | ||
95 | end | 94 | end |
96 | 95 | ||
97 | should 'call plugin hotspot to filter unavailable comments' do | 96 | should 'call plugin hotspot to filter unavailable comments' do |
@@ -124,26 +123,26 @@ class CommentsTest < ActiveSupport::TestCase | @@ -124,26 +123,26 @@ class CommentsTest < ActiveSupport::TestCase | ||
124 | should 'not, anonymous list comments if has no permission to view the source article' do | 123 | should 'not, anonymous list comments if has no permission to view the source article' do |
125 | article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing", :published => false) | 124 | article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing", :published => false) |
126 | assert !article.published? | 125 | assert !article.published? |
127 | - | 126 | + |
128 | get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | 127 | get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" |
129 | assert_equal 403, last_response.status | 128 | assert_equal 403, last_response.status |
130 | end | 129 | end |
131 | - | 130 | + |
132 | should 'anonymous return comments of an article' do | 131 | should 'anonymous return comments of an article' do |
133 | article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing") | 132 | article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing") |
134 | article.comments.create!(:body => "some comment", :author => local_person) | 133 | article.comments.create!(:body => "some comment", :author => local_person) |
135 | article.comments.create!(:body => "another comment", :author => local_person) | 134 | article.comments.create!(:body => "another comment", :author => local_person) |
136 | - | 135 | + |
137 | get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | 136 | get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" |
138 | json = JSON.parse(last_response.body) | 137 | json = JSON.parse(last_response.body) |
139 | assert_equal 200, last_response.status | 138 | assert_equal 200, last_response.status |
140 | assert_equal 2, json["comments"].length | 139 | assert_equal 2, json["comments"].length |
141 | end | 140 | end |
142 | - | 141 | + |
143 | should 'anonymous return comment of an article' do | 142 | should 'anonymous return comment of an article' do |
144 | article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing") | 143 | article = fast_create(Article, :profile_id => local_person.id, :name => "Some thing") |
145 | comment = article.comments.create!(:body => "another comment", :author => local_person) | 144 | comment = article.comments.create!(:body => "another comment", :author => local_person) |
146 | - | 145 | + |
147 | get "/api/v1/articles/#{article.id}/comments/#{comment.id}?#{params.to_query}" | 146 | get "/api/v1/articles/#{article.id}/comments/#{comment.id}?#{params.to_query}" |
148 | json = JSON.parse(last_response.body) | 147 | json = JSON.parse(last_response.body) |
149 | assert_equal 200, last_response.status | 148 | assert_equal 200, last_response.status |
test/api/communities_test.rb
@@ -147,7 +147,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -147,7 +147,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
147 | get "/api/v1/communities?#{params.to_query}" | 147 | get "/api/v1/communities?#{params.to_query}" |
148 | json_page_one = JSON.parse(last_response.body) | 148 | json_page_one = JSON.parse(last_response.body) |
149 | 149 | ||
150 | - | ||
151 | assert_includes json_page_one["communities"].map { |a| a["id"] }, community1.id | 150 | assert_includes json_page_one["communities"].map { |a| a["id"] }, community1.id |
152 | assert_not_includes json_page_one["communities"].map { |a| a["id"] }, community2.id | 151 | assert_not_includes json_page_one["communities"].map { |a| a["id"] }, community2.id |
153 | 152 | ||
@@ -172,7 +171,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -172,7 +171,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
172 | end | 171 | end |
173 | 172 | ||
174 | should 'anonymous list only communities' do | 173 | should 'anonymous list only communities' do |
175 | - anonymous_setup | ||
176 | community = fast_create(Community, :environment_id => environment.id) | 174 | community = fast_create(Community, :environment_id => environment.id) |
177 | enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise | 175 | enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise |
178 | get "/api/v1/communities?#{params.to_query}" | 176 | get "/api/v1/communities?#{params.to_query}" |
@@ -182,7 +180,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -182,7 +180,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
182 | end | 180 | end |
183 | 181 | ||
184 | should 'anonymous list all communities' do | 182 | should 'anonymous list all communities' do |
185 | - anonymous_setup | ||
186 | community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) | 183 | community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) |
187 | community2 = fast_create(Community, :environment_id => environment.id) | 184 | community2 = fast_create(Community, :environment_id => environment.id) |
188 | get "/api/v1/communities?#{params.to_query}" | 185 | get "/api/v1/communities?#{params.to_query}" |
@@ -191,7 +188,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -191,7 +188,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
191 | end | 188 | end |
192 | 189 | ||
193 | should 'not, anonymous list invisible communities' do | 190 | should 'not, anonymous list invisible communities' do |
194 | - anonymous_setup | ||
195 | community1 = fast_create(Community, :environment_id => environment.id) | 191 | community1 = fast_create(Community, :environment_id => environment.id) |
196 | fast_create(Community, :environment_id => environment.id, :visible => false) | 192 | fast_create(Community, :environment_id => environment.id, :visible => false) |
197 | 193 | ||
@@ -201,7 +197,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -201,7 +197,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
201 | end | 197 | end |
202 | 198 | ||
203 | should 'anonymous list private communities' do | 199 | should 'anonymous list private communities' do |
204 | - anonymous_setup | ||
205 | community1 = fast_create(Community, :environment_id => environment.id) | 200 | community1 = fast_create(Community, :environment_id => environment.id) |
206 | community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) | 201 | community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) |
207 | 202 | ||
@@ -211,7 +206,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -211,7 +206,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
211 | end | 206 | end |
212 | 207 | ||
213 | should 'not, anonymous create a community' do | 208 | should 'not, anonymous create a community' do |
214 | - anonymous_setup | ||
215 | params[:community] = {:name => 'some'} | 209 | params[:community] = {:name => 'some'} |
216 | post "/api/v1/communities?#{params.to_query}" | 210 | post "/api/v1/communities?#{params.to_query}" |
217 | json = JSON.parse(last_response.body) | 211 | json = JSON.parse(last_response.body) |
@@ -219,7 +213,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -219,7 +213,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
219 | end | 213 | end |
220 | 214 | ||
221 | should 'anonymous get community' do | 215 | should 'anonymous get community' do |
222 | - anonymous_setup | ||
223 | community = fast_create(Community, :environment_id => environment.id) | 216 | community = fast_create(Community, :environment_id => environment.id) |
224 | get "/api/v1/communities/#{community.id}" | 217 | get "/api/v1/communities/#{community.id}" |
225 | json = JSON.parse(last_response.body) | 218 | json = JSON.parse(last_response.body) |
@@ -227,7 +220,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -227,7 +220,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
227 | end | 220 | end |
228 | 221 | ||
229 | should 'not, anonymous get invisible community' do | 222 | should 'not, anonymous get invisible community' do |
230 | - anonymous_setup | ||
231 | community = fast_create(Community, :environment_id => environment.id, :visible => false) | 223 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
232 | get "/api/v1/communities/#{community.id}" | 224 | get "/api/v1/communities/#{community.id}" |
233 | json = JSON.parse(last_response.body) | 225 | json = JSON.parse(last_response.body) |
@@ -235,7 +227,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -235,7 +227,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
235 | end | 227 | end |
236 | 228 | ||
237 | should 'not, anonymous get private communities' do | 229 | should 'not, anonymous get private communities' do |
238 | - anonymous_setup | ||
239 | community = fast_create(Community, :environment_id => environment.id) | 230 | community = fast_create(Community, :environment_id => environment.id) |
240 | fast_create(Community, :environment_id => environment.id, :public_profile => false) | 231 | fast_create(Community, :environment_id => environment.id, :public_profile => false) |
241 | get "/api/v1/communities/#{community.id}" | 232 | get "/api/v1/communities/#{community.id}" |
@@ -244,7 +235,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -244,7 +235,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
244 | end | 235 | end |
245 | 236 | ||
246 | should 'anonymous list communities with pagination' do | 237 | should 'anonymous list communities with pagination' do |
247 | - anonymous_setup | ||
248 | community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) | 238 | community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) |
249 | community2 = fast_create(Community, :created_at => 2.days.ago) | 239 | community2 = fast_create(Community, :created_at => 2.days.ago) |
250 | 240 | ||
@@ -266,7 +256,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -266,7 +256,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
266 | end | 256 | end |
267 | 257 | ||
268 | should 'anonymous list communities with timestamp' do | 258 | should 'anonymous list communities with timestamp' do |
269 | - anonymous_setup | ||
270 | community1 = fast_create(Community, :public_profile => true) | 259 | community1 = fast_create(Community, :public_profile => true) |
271 | community2 = fast_create(Community) | 260 | community2 = fast_create(Community) |
272 | 261 | ||
@@ -282,7 +271,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -282,7 +271,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
282 | end | 271 | end |
283 | 272 | ||
284 | should 'display public custom fields to anonymous' do | 273 | should 'display public custom fields to anonymous' do |
285 | - anonymous_setup | ||
286 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Community", :active => true, :environment => Environment.default) | 274 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Community", :active => true, :environment => Environment.default) |
287 | some_community = fast_create(Community) | 275 | some_community = fast_create(Community) |
288 | some_community.custom_values = { "Rating" => { "value" => "Five stars", "public" => "true"} } | 276 | some_community.custom_values = { "Rating" => { "value" => "Five stars", "public" => "true"} } |
@@ -295,7 +283,6 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -295,7 +283,6 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
295 | end | 283 | end |
296 | 284 | ||
297 | should 'not display private custom fields to anonymous' do | 285 | should 'not display private custom fields to anonymous' do |
298 | - anonymous_setup | ||
299 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Community", :active => true, :environment => Environment.default) | 286 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Community", :active => true, :environment => Environment.default) |
300 | some_community = fast_create(Community) | 287 | some_community = fast_create(Community) |
301 | some_community.custom_values = { "Rating" => { "value" => "Five stars", "public" => "false"} } | 288 | some_community.custom_values = { "Rating" => { "value" => "Five stars", "public" => "false"} } |
@@ -306,5 +293,4 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -306,5 +293,4 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
306 | refute json['community']['additional_data'].has_key?('Rating') | 293 | refute json['community']['additional_data'].has_key?('Rating') |
307 | end | 294 | end |
308 | 295 | ||
309 | - | ||
310 | end | 296 | end |
test/api/enterprises_test.rb
@@ -64,14 +64,14 @@ class EnterprisesTest < ActiveSupport::TestCase | @@ -64,14 +64,14 @@ class EnterprisesTest < ActiveSupport::TestCase | ||
64 | assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} | 64 | assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} |
65 | end | 65 | end |
66 | 66 | ||
67 | - should 'not, logger user list invisible enterprises' do | 67 | + should 'not, logged user list invisible enterprises' do |
68 | login_api | 68 | login_api |
69 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | 69 | enterprise1 = fast_create(Enterprise, :environment_id => environment.id) |
70 | fast_create(Enterprise, :visible => false) | 70 | fast_create(Enterprise, :visible => false) |
71 | 71 | ||
72 | get "/api/v1/enterprises?#{params.to_query}" | 72 | get "/api/v1/enterprises?#{params.to_query}" |
73 | json = JSON.parse(last_response.body) | 73 | json = JSON.parse(last_response.body) |
74 | - assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} | 74 | + assert_equal [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} |
75 | end | 75 | end |
76 | 76 | ||
77 | should 'anonymous list private enterprises' do | 77 | should 'anonymous list private enterprises' do |
test/api/people_test.rb
@@ -61,7 +61,6 @@ class PeopleTest < ActiveSupport::TestCase | @@ -61,7 +61,6 @@ class PeopleTest < ActiveSupport::TestCase | ||
61 | end | 61 | end |
62 | 62 | ||
63 | should 'annoymous not list invisible people' do | 63 | should 'annoymous not list invisible people' do |
64 | - anonymous_setup | ||
65 | invisible_person = fast_create(Person, :visible => false) | 64 | invisible_person = fast_create(Person, :visible => false) |
66 | 65 | ||
67 | get "/api/v1/people?#{params.to_query}" | 66 | get "/api/v1/people?#{params.to_query}" |
@@ -105,7 +104,6 @@ class PeopleTest < ActiveSupport::TestCase | @@ -105,7 +104,6 @@ class PeopleTest < ActiveSupport::TestCase | ||
105 | end | 104 | end |
106 | 105 | ||
107 | should 'anonymous get person' do | 106 | should 'anonymous get person' do |
108 | - anonymous_setup | ||
109 | some_person = fast_create(Person) | 107 | some_person = fast_create(Person) |
110 | 108 | ||
111 | get "/api/v1/people/#{some_person.id}?#{params.to_query}" | 109 | get "/api/v1/people/#{some_person.id}?#{params.to_query}" |
@@ -113,7 +111,6 @@ class PeopleTest < ActiveSupport::TestCase | @@ -113,7 +111,6 @@ class PeopleTest < ActiveSupport::TestCase | ||
113 | assert_equal some_person.id, json['person']['id'] | 111 | assert_equal some_person.id, json['person']['id'] |
114 | end | 112 | end |
115 | 113 | ||
116 | - | ||
117 | should 'people endpoint filter by fields parameter for logged user' do | 114 | should 'people endpoint filter by fields parameter for logged user' do |
118 | login_api | 115 | login_api |
119 | get "/api/v1/people?#{params.to_query}&fields=name" | 116 | get "/api/v1/people?#{params.to_query}&fields=name" |
@@ -156,7 +153,6 @@ class PeopleTest < ActiveSupport::TestCase | @@ -156,7 +153,6 @@ class PeopleTest < ActiveSupport::TestCase | ||
156 | end | 153 | end |
157 | 154 | ||
158 | should 'anonymous not get invisible person' do | 155 | should 'anonymous not get invisible person' do |
159 | - anonymous_setup | ||
160 | person = fast_create(Person, :visible => false) | 156 | person = fast_create(Person, :visible => false) |
161 | 157 | ||
162 | get "/api/v1/people/#{person.id}?#{params.to_query}" | 158 | get "/api/v1/people/#{person.id}?#{params.to_query}" |
test/api/profiles_test.rb
@@ -117,7 +117,6 @@ class ProfilesTest < ActiveSupport::TestCase | @@ -117,7 +117,6 @@ class ProfilesTest < ActiveSupport::TestCase | ||
117 | end | 117 | end |
118 | 118 | ||
119 | should 'display public custom fields to anonymous' do | 119 | should 'display public custom fields to anonymous' do |
120 | - anonymous_setup | ||
121 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Profile", :active => true, :environment => Environment.default) | 120 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Profile", :active => true, :environment => Environment.default) |
122 | some_profile = fast_create(Profile) | 121 | some_profile = fast_create(Profile) |
123 | some_profile.custom_values = { "Rating" => { "value" => "Five stars", "public" => "true"} } | 122 | some_profile.custom_values = { "Rating" => { "value" => "Five stars", "public" => "true"} } |
@@ -130,7 +129,6 @@ class ProfilesTest < ActiveSupport::TestCase | @@ -130,7 +129,6 @@ class ProfilesTest < ActiveSupport::TestCase | ||
130 | end | 129 | end |
131 | 130 | ||
132 | should 'not display private custom fields to anonymous' do | 131 | should 'not display private custom fields to anonymous' do |
133 | - anonymous_setup | ||
134 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Profile", :active => true, :environment => Environment.default) | 132 | CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Profile", :active => true, :environment => Environment.default) |
135 | some_profile = fast_create(Profile) | 133 | some_profile = fast_create(Profile) |
136 | some_profile.custom_values = { "Rating" => { "value" => "Five stars", "public" => "false"} } | 134 | some_profile.custom_values = { "Rating" => { "value" => "Five stars", "public" => "false"} } |
test/api/test_helper.rb
@@ -25,11 +25,6 @@ class ActiveSupport::TestCase | @@ -25,11 +25,6 @@ class ActiveSupport::TestCase | ||
25 | @params = {:private_token => @private_token} | 25 | @params = {:private_token => @private_token} |
26 | end | 26 | end |
27 | 27 | ||
28 | - def anonymous_setup | ||
29 | - @environment = Environment.default | ||
30 | - @params = {} | ||
31 | - end | ||
32 | - | ||
33 | attr_accessor :private_token, :user, :person, :params, :environment | 28 | attr_accessor :private_token, :user, :person, :params, :environment |
34 | 29 | ||
35 | private | 30 | private |