Commit 286182fe900413aeb8fe5bc928447bd3ba49d4de
1 parent
e208abbd
Exists in
api_visitor
Renamed visitor to anonymous
Showing
5 changed files
with
88 additions
and
98 deletions
Show diff stats
test/unit/api/categories_test.rb
| ... | ... | @@ -97,26 +97,24 @@ class CategoriesTest < ActiveSupport::TestCase |
| 97 | 97 | end |
| 98 | 98 | end |
| 99 | 99 | |
| 100 | - ############## Visitors' tests #######################################################################33 | |
| 101 | - | |
| 102 | - should 'visitor list categories' do | |
| 103 | - visitor_setup | |
| 100 | + should 'anonymous list categories' do | |
| 101 | + anonymous_setup | |
| 104 | 102 | category = fast_create(Category, :environment_id => environment.id) |
| 105 | 103 | get "/api/v1/categories/?#{params.to_query}" |
| 106 | 104 | json = JSON.parse(last_response.body) |
| 107 | 105 | assert_includes json["categories"].map { |c| c["name"] }, category.name |
| 108 | 106 | end |
| 109 | 107 | |
| 110 | - should 'visitor get category by id' do | |
| 111 | - visitor_setup | |
| 108 | + should 'anonymous get category by id' do | |
| 109 | + anonymous_setup | |
| 112 | 110 | category = fast_create(Category, :environment_id => environment.id) |
| 113 | 111 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" |
| 114 | 112 | json = JSON.parse(last_response.body) |
| 115 | 113 | assert_equal category.name, json["category"]["name"] |
| 116 | 114 | end |
| 117 | 115 | |
| 118 | - should 'visitor list parent and children when get category by id' do | |
| 119 | - visitor_setup | |
| 116 | + should 'anonymous list parent and children when get category by id' do | |
| 117 | + anonymous_setup | |
| 120 | 118 | parent = fast_create(Category, :environment_id => environment.id) |
| 121 | 119 | child_1 = fast_create(Category, :environment_id => environment.id) |
| 122 | 120 | child_2 = fast_create(Category, :environment_id => environment.id) |
| ... | ... | @@ -133,8 +131,8 @@ class CategoriesTest < ActiveSupport::TestCase |
| 133 | 131 | assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } |
| 134 | 132 | end |
| 135 | 133 | |
| 136 | - should 'visitor include parent in categories list if params is true' do | |
| 137 | - visitor_setup | |
| 134 | + should 'anonymous include parent in categories list if params is true' do | |
| 135 | + anonymous_setup | |
| 138 | 136 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category |
| 139 | 137 | child_1 = fast_create(Category, :environment_id => environment.id) |
| 140 | 138 | child_2 = fast_create(Category, :environment_id => environment.id) |
| ... | ... | @@ -156,8 +154,8 @@ class CategoriesTest < ActiveSupport::TestCase |
| 156 | 154 | json["categories"].map { |c| c['parent'] && c['parent']['id'] } |
| 157 | 155 | end |
| 158 | 156 | |
| 159 | - should 'visitor include children in categories list if params is true' do | |
| 160 | - visitor_setup | |
| 157 | + should 'anonymous include children in categories list if params is true' do | |
| 158 | + anonymous_setup | |
| 161 | 159 | category = fast_create(Category, :environment_id => environment.id) |
| 162 | 160 | child_1 = fast_create(Category, :environment_id => environment.id) |
| 163 | 161 | child_2 = fast_create(Category, :environment_id => environment.id) |
| ... | ... | @@ -182,8 +180,8 @@ class CategoriesTest < ActiveSupport::TestCase |
| 182 | 180 | end |
| 183 | 181 | |
| 184 | 182 | expose_attributes.each do |attr| |
| 185 | - should "visitor expose category #{attr} attribute by default" do | |
| 186 | - visitor_setup | |
| 183 | + should "anonymous expose category #{attr} attribute by default" do | |
| 184 | + anonymous_setup | |
| 187 | 185 | category = fast_create(Category, :environment_id => environment.id) |
| 188 | 186 | get "/api/v1/categories/?#{params.to_query}" |
| 189 | 187 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -191,6 +189,6 @@ class CategoriesTest < ActiveSupport::TestCase |
| 191 | 189 | end |
| 192 | 190 | end |
| 193 | 191 | |
| 194 | - ################################# End visitors' test #################################################################################### | |
| 192 | + | |
| 195 | 193 | |
| 196 | 194 | end | ... | ... |
test/unit/api/comments_test.rb
| ... | ... | @@ -69,68 +69,64 @@ class CommentsTest < ActiveSupport::TestCase |
| 69 | 69 | end |
| 70 | 70 | |
| 71 | 71 | should 'comment creation define the source' do |
| 72 | - login_api | |
| 73 | - amount = Comment.count | |
| 74 | - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
| 75 | - body = 'My comment' | |
| 76 | - params.merge!({:body => body}) | |
| 77 | - | |
| 78 | - post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 79 | - assert_equal amount + 1, Comment.count | |
| 80 | - comment = Comment.last | |
| 81 | - assert_not_nil comment.source | |
| 72 | + login_api | |
| 73 | + amount = Comment.count | |
| 74 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
| 75 | + body = 'My comment' | |
| 76 | + params.merge!({:body => body}) | |
| 77 | + | |
| 78 | + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 79 | + assert_equal amount + 1, Comment.count | |
| 80 | + comment = Comment.last | |
| 81 | + assert_not_nil comment.source | |
| 82 | 82 | end |
| 83 | 83 | |
| 84 | -##################### Visitors' tests ############################################### | |
| 85 | - | |
| 86 | -should 'not visitor list comments if has no permission to view the source article' do | |
| 87 | - visitor_setup | |
| 88 | - person = fast_create(Person) | |
| 89 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) | |
| 90 | - assert !article.published? | |
| 84 | + should 'not anonymous list comments if has no permission to view the source article' do | |
| 85 | + anonymous_setup | |
| 86 | + person = fast_create(Person) | |
| 87 | + article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) | |
| 88 | + assert !article.published? | |
| 91 | 89 | |
| 92 | - get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 93 | - assert_equal 403, last_response.status | |
| 94 | -end | |
| 90 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 91 | + assert_equal 403, last_response.status | |
| 92 | + end | |
| 95 | 93 | |
| 96 | -should 'visitor return comments of an article' do | |
| 97 | - visitor_setup | |
| 98 | - person = fast_create(Person) | |
| 99 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 100 | - article.comments.create!(:body => "some comment", :author => person) | |
| 101 | - article.comments.create!(:body => "another comment", :author => person) | |
| 102 | - | |
| 103 | - get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 104 | - json = JSON.parse(last_response.body) | |
| 105 | - assert_equal 200, last_response.status | |
| 106 | - assert_equal 2, json["comments"].length | |
| 107 | -end | |
| 94 | + should 'anonymous return comments of an article' do | |
| 95 | + anonymous_setup | |
| 96 | + person = fast_create(Person) | |
| 97 | + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 98 | + article.comments.create!(:body => "some comment", :author => person) | |
| 99 | + article.comments.create!(:body => "another comment", :author => person) | |
| 108 | 100 | |
| 109 | -should 'visitor return comment of an article' do | |
| 110 | - visitor_setup | |
| 111 | - person = fast_create(Person) | |
| 112 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 113 | - comment = article.comments.create!(:body => "another comment", :author => person) | |
| 101 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 102 | + json = JSON.parse(last_response.body) | |
| 103 | + assert_equal 200, last_response.status | |
| 104 | + assert_equal 2, json["comments"].length | |
| 105 | + end | |
| 114 | 106 | |
| 115 | - get "/api/v1/articles/#{article.id}/comments/#{comment.id}?#{params.to_query}" | |
| 116 | - json = JSON.parse(last_response.body) | |
| 117 | - assert_equal 200, last_response.status | |
| 118 | - assert_equal comment.id, json['comment']['id'] | |
| 119 | -end | |
| 107 | + should 'anonymous return comment of an article' do | |
| 108 | + anonymous_setup | |
| 109 | + person = fast_create(Person) | |
| 110 | + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 111 | + comment = article.comments.create!(:body => "another comment", :author => person) | |
| 120 | 112 | |
| 121 | -should 'not visitor comment an article (at least so far...)' do | |
| 122 | - visitor_setup | |
| 123 | - person = fast_create(Person) | |
| 124 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 125 | - body = 'My comment' | |
| 126 | - name = "John Doe" | |
| 127 | - email = "JohnDoe@gmail.com" | |
| 128 | - params.merge!({:body => body, name: name, email: email}) | |
| 129 | - post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 130 | - json = JSON.parse(last_response.body) | |
| 131 | - assert_equal 401, last_response.status | |
| 132 | -end | |
| 113 | + get "/api/v1/articles/#{article.id}/comments/#{comment.id}?#{params.to_query}" | |
| 114 | + json = JSON.parse(last_response.body) | |
| 115 | + assert_equal 200, last_response.status | |
| 116 | + assert_equal comment.id, json['comment']['id'] | |
| 117 | + end | |
| 133 | 118 | |
| 134 | -################################## End Visitors's tests ############################################################ | |
| 119 | + should 'not anonymous comment an article (at least so far...)' do | |
| 120 | + anonymous_setup | |
| 121 | + person = fast_create(Person) | |
| 122 | + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 123 | + body = 'My comment' | |
| 124 | + name = "John Doe" | |
| 125 | + email = "JohnDoe@gmail.com" | |
| 126 | + params.merge!({:body => body, name: name, email: email}) | |
| 127 | + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
| 128 | + json = JSON.parse(last_response.body) | |
| 129 | + assert_equal 401, last_response.status | |
| 130 | + end | |
| 135 | 131 | |
| 136 | 132 | end | ... | ... |
test/unit/api/communities_test.rb
| ... | ... | @@ -171,10 +171,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 171 | 171 | assert_not_includes json["communities"].map { |a| a["id"] }, community2.id |
| 172 | 172 | end |
| 173 | 173 | |
| 174 | - ################### Visitor's tests ######################################3 | |
| 175 | - | |
| 176 | - should 'visitor list only communities' do | |
| 177 | - visitor_setup | |
| 174 | + should 'anonymous list only communities' do | |
| 175 | + anonymous_setup | |
| 178 | 176 | community = fast_create(Community, :environment_id => environment.id) |
| 179 | 177 | enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise |
| 180 | 178 | get "/api/v1/communities?#{params.to_query}" |
| ... | ... | @@ -183,8 +181,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 183 | 181 | assert_includes json['communities'].map {|c| c['id']}, community.id |
| 184 | 182 | end |
| 185 | 183 | |
| 186 | - should 'visitor list all communities' do | |
| 187 | - visitor_setup | |
| 184 | + should 'anonymous list all communities' do | |
| 185 | + anonymous_setup | |
| 188 | 186 | community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) |
| 189 | 187 | community2 = fast_create(Community, :environment_id => environment.id) |
| 190 | 188 | get "/api/v1/communities?#{params.to_query}" |
| ... | ... | @@ -192,8 +190,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 192 | 190 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
| 193 | 191 | end |
| 194 | 192 | |
| 195 | - should 'not visitor list invisible communities' do | |
| 196 | - visitor_setup | |
| 193 | + should 'not anonymous list invisible communities' do | |
| 194 | + anonymous_setup | |
| 197 | 195 | community1 = fast_create(Community, :environment_id => environment.id) |
| 198 | 196 | fast_create(Community, :environment_id => environment.id, :visible => false) |
| 199 | 197 | |
| ... | ... | @@ -202,8 +200,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 202 | 200 | assert_equal [community1.id], json['communities'].map {|c| c['id']} |
| 203 | 201 | end |
| 204 | 202 | |
| 205 | - should 'visitor list private communities' do | |
| 206 | - visitor_setup | |
| 203 | + should 'anonymous list private communities' do | |
| 204 | + anonymous_setup | |
| 207 | 205 | community1 = fast_create(Community, :environment_id => environment.id) |
| 208 | 206 | community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) |
| 209 | 207 | |
| ... | ... | @@ -214,32 +212,32 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 214 | 212 | |
| 215 | 213 | |
| 216 | 214 | |
| 217 | - should 'not visitor create a community' do | |
| 218 | - visitor_setup | |
| 215 | + should 'not anonymous create a community' do | |
| 216 | + anonymous_setup | |
| 219 | 217 | params[:community] = {:name => 'some'} |
| 220 | 218 | post "/api/v1/communities?#{params.to_query}" |
| 221 | 219 | json = JSON.parse(last_response.body) |
| 222 | 220 | assert_equal 401, last_response.status |
| 223 | 221 | end |
| 224 | 222 | |
| 225 | - should 'visitor get community' do | |
| 226 | - visitor_setup | |
| 223 | + should 'anonymous get community' do | |
| 224 | + anonymous_setup | |
| 227 | 225 | community = fast_create(Community, :environment_id => environment.id) |
| 228 | 226 | get "/api/v1/communities/#{community.id}" |
| 229 | 227 | json = JSON.parse(last_response.body) |
| 230 | 228 | assert_equal community.id, json['community']['id'] |
| 231 | 229 | end |
| 232 | 230 | |
| 233 | - should 'not visitor get invisible community' do | |
| 234 | - visitor_setup | |
| 231 | + should 'not anonymous get invisible community' do | |
| 232 | + anonymous_setup | |
| 235 | 233 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
| 236 | 234 | get "/api/v1/communities/#{community.id}" |
| 237 | 235 | json = JSON.parse(last_response.body) |
| 238 | 236 | assert json['community'].blank? |
| 239 | 237 | end |
| 240 | 238 | |
| 241 | - should 'visitor not get private communities' do | |
| 242 | - visitor_setup | |
| 239 | + should 'anonymous not get private communities' do | |
| 240 | + anonymous_setup | |
| 243 | 241 | community = fast_create(Community, :environment_id => environment.id) |
| 244 | 242 | fast_create(Community, :environment_id => environment.id, :public_profile => false) |
| 245 | 243 | get "/api/v1/communities/#{community.id}" |
| ... | ... | @@ -247,8 +245,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 247 | 245 | assert_equal community.id, json['community']['id'] |
| 248 | 246 | end |
| 249 | 247 | |
| 250 | - should 'visitor list communities with pagination' do | |
| 251 | - visitor_setup | |
| 248 | + should 'anonymous list communities with pagination' do | |
| 249 | + anonymous_setup | |
| 252 | 250 | community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) |
| 253 | 251 | community2 = fast_create(Community, :created_at => 2.days.ago) |
| 254 | 252 | |
| ... | ... | @@ -269,8 +267,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 269 | 267 | assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id |
| 270 | 268 | end |
| 271 | 269 | |
| 272 | - should 'visitor list communities with timestamp' do | |
| 273 | - visitor_setup | |
| 270 | + should 'anonymous list communities with timestamp' do | |
| 271 | + anonymous_setup | |
| 274 | 272 | community1 = fast_create(Community, :public_profile => true) |
| 275 | 273 | community2 = fast_create(Community) |
| 276 | 274 | |
| ... | ... | @@ -285,6 +283,4 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 285 | 283 | assert_not_includes json["communities"].map { |a| a["id"] }, community2.id |
| 286 | 284 | end |
| 287 | 285 | |
| 288 | - ###################End Visitor's tests ######################################3 | |
| 289 | - | |
| 290 | 286 | end | ... | ... |
test/unit/api/profiles_test.rb
| ... | ... | @@ -32,7 +32,7 @@ class ProfilesTest < ActiveSupport::TestCase |
| 32 | 32 | assert_equal community.id, json['id'] |
| 33 | 33 | end |
| 34 | 34 | |
| 35 | - should 'visitor list all profiles' do | |
| 35 | + should 'anonymous list all profiles' do | |
| 36 | 36 | person1 = fast_create(Person) |
| 37 | 37 | person2 = fast_create(Person) |
| 38 | 38 | community = fast_create(Community) |
| ... | ... | @@ -41,14 +41,14 @@ class ProfilesTest < ActiveSupport::TestCase |
| 41 | 41 | assert_equivalent [person1.id, person2.id, community.id], json.map {|p| p['id']} |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | - should 'visitor get person from profile id' do | |
| 44 | + should 'anonymous get person from profile id' do | |
| 45 | 45 | some_person = fast_create(Person) |
| 46 | 46 | get "/api/v1/profiles/#{some_person.id}" |
| 47 | 47 | json = JSON.parse(last_response.body) |
| 48 | 48 | assert_equal some_person.id, json['id'] |
| 49 | 49 | end |
| 50 | 50 | |
| 51 | - should 'visitor get community from profile id' do | |
| 51 | + should 'anonymous get community from profile id' do | |
| 52 | 52 | community = fast_create(Community) |
| 53 | 53 | get "/api/v1/profiles/#{community.id}" |
| 54 | 54 | json = JSON.parse(last_response.body) | ... | ... |
test/unit/api/test_helper.rb