Commit 2fc43667e59fba1a28a92721b80602b2f5baa021
Committed by
Leandro Santos
1 parent
99bf0aae
Exists in
staging
and in
31 other branches
Renamed visitor to anonymous
Showing
4 changed files
with
37 additions
and
43 deletions
Show diff stats
test/api/categories_test.rb
| @@ -97,26 +97,24 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -97,26 +97,24 @@ class CategoriesTest < ActiveSupport::TestCase | ||
| 97 | end | 97 | end |
| 98 | end | 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 | category = fast_create(Category, :environment_id => environment.id) | 102 | category = fast_create(Category, :environment_id => environment.id) |
| 105 | get "/api/v1/categories/?#{params.to_query}" | 103 | get "/api/v1/categories/?#{params.to_query}" |
| 106 | json = JSON.parse(last_response.body) | 104 | json = JSON.parse(last_response.body) |
| 107 | assert_includes json["categories"].map { |c| c["name"] }, category.name | 105 | assert_includes json["categories"].map { |c| c["name"] }, category.name |
| 108 | end | 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 | category = fast_create(Category, :environment_id => environment.id) | 110 | category = fast_create(Category, :environment_id => environment.id) |
| 113 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" | 111 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" |
| 114 | json = JSON.parse(last_response.body) | 112 | json = JSON.parse(last_response.body) |
| 115 | assert_equal category.name, json["category"]["name"] | 113 | assert_equal category.name, json["category"]["name"] |
| 116 | end | 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 | parent = fast_create(Category, :environment_id => environment.id) | 118 | parent = fast_create(Category, :environment_id => environment.id) |
| 121 | child_1 = fast_create(Category, :environment_id => environment.id) | 119 | child_1 = fast_create(Category, :environment_id => environment.id) |
| 122 | child_2 = fast_create(Category, :environment_id => environment.id) | 120 | child_2 = fast_create(Category, :environment_id => environment.id) |
| @@ -133,8 +131,8 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -133,8 +131,8 @@ class CategoriesTest < ActiveSupport::TestCase | ||
| 133 | assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } | 131 | assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } |
| 134 | end | 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 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category | 136 | parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category |
| 139 | child_1 = fast_create(Category, :environment_id => environment.id) | 137 | child_1 = fast_create(Category, :environment_id => environment.id) |
| 140 | child_2 = fast_create(Category, :environment_id => environment.id) | 138 | child_2 = fast_create(Category, :environment_id => environment.id) |
| @@ -156,8 +154,8 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -156,8 +154,8 @@ class CategoriesTest < ActiveSupport::TestCase | ||
| 156 | json["categories"].map { |c| c['parent'] && c['parent']['id'] } | 154 | json["categories"].map { |c| c['parent'] && c['parent']['id'] } |
| 157 | end | 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 | category = fast_create(Category, :environment_id => environment.id) | 159 | category = fast_create(Category, :environment_id => environment.id) |
| 162 | child_1 = fast_create(Category, :environment_id => environment.id) | 160 | child_1 = fast_create(Category, :environment_id => environment.id) |
| 163 | child_2 = fast_create(Category, :environment_id => environment.id) | 161 | child_2 = fast_create(Category, :environment_id => environment.id) |
| @@ -182,8 +180,8 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -182,8 +180,8 @@ class CategoriesTest < ActiveSupport::TestCase | ||
| 182 | end | 180 | end |
| 183 | 181 | ||
| 184 | expose_attributes.each do |attr| | 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 | category = fast_create(Category, :environment_id => environment.id) | 185 | category = fast_create(Category, :environment_id => environment.id) |
| 188 | get "/api/v1/categories/?#{params.to_query}" | 186 | get "/api/v1/categories/?#{params.to_query}" |
| 189 | json = JSON.parse(last_response.body) | 187 | json = JSON.parse(last_response.body) |
| @@ -191,6 +189,6 @@ class CategoriesTest < ActiveSupport::TestCase | @@ -191,6 +189,6 @@ class CategoriesTest < ActiveSupport::TestCase | ||
| 191 | end | 189 | end |
| 192 | end | 190 | end |
| 193 | 191 | ||
| 194 | - ################################# End visitors' test #################################################################################### | 192 | + |
| 195 | 193 | ||
| 196 | end | 194 | end |
test/api/communities_test.rb
| @@ -171,10 +171,8 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -171,10 +171,8 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 171 | assert_not_includes json["communities"].map { |a| a["id"] }, community2.id | 171 | assert_not_includes json["communities"].map { |a| a["id"] }, community2.id |
| 172 | end | 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 | community = fast_create(Community, :environment_id => environment.id) | 176 | community = fast_create(Community, :environment_id => environment.id) |
| 179 | enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise | 177 | enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise |
| 180 | get "/api/v1/communities?#{params.to_query}" | 178 | get "/api/v1/communities?#{params.to_query}" |
| @@ -183,8 +181,8 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -183,8 +181,8 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 183 | assert_includes json['communities'].map {|c| c['id']}, community.id | 181 | assert_includes json['communities'].map {|c| c['id']}, community.id |
| 184 | end | 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 | community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) | 186 | community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) |
| 189 | community2 = fast_create(Community, :environment_id => environment.id) | 187 | community2 = fast_create(Community, :environment_id => environment.id) |
| 190 | get "/api/v1/communities?#{params.to_query}" | 188 | get "/api/v1/communities?#{params.to_query}" |
| @@ -192,8 +190,8 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -192,8 +190,8 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 192 | 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']} |
| 193 | end | 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 | community1 = fast_create(Community, :environment_id => environment.id) | 195 | community1 = fast_create(Community, :environment_id => environment.id) |
| 198 | fast_create(Community, :environment_id => environment.id, :visible => false) | 196 | fast_create(Community, :environment_id => environment.id, :visible => false) |
| 199 | 197 | ||
| @@ -202,8 +200,8 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -202,8 +200,8 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 202 | assert_equal [community1.id], json['communities'].map {|c| c['id']} | 200 | assert_equal [community1.id], json['communities'].map {|c| c['id']} |
| 203 | end | 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 | community1 = fast_create(Community, :environment_id => environment.id) | 205 | community1 = fast_create(Community, :environment_id => environment.id) |
| 208 | community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) | 206 | community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) |
| 209 | 207 | ||
| @@ -214,32 +212,32 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -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 | params[:community] = {:name => 'some'} | 217 | params[:community] = {:name => 'some'} |
| 220 | post "/api/v1/communities?#{params.to_query}" | 218 | post "/api/v1/communities?#{params.to_query}" |
| 221 | json = JSON.parse(last_response.body) | 219 | json = JSON.parse(last_response.body) |
| 222 | assert_equal 401, last_response.status | 220 | assert_equal 401, last_response.status |
| 223 | end | 221 | end |
| 224 | 222 | ||
| 225 | - should 'visitor get community' do | ||
| 226 | - visitor_setup | 223 | + should 'anonymous get community' do |
| 224 | + anonymous_setup | ||
| 227 | community = fast_create(Community, :environment_id => environment.id) | 225 | community = fast_create(Community, :environment_id => environment.id) |
| 228 | get "/api/v1/communities/#{community.id}" | 226 | get "/api/v1/communities/#{community.id}" |
| 229 | json = JSON.parse(last_response.body) | 227 | json = JSON.parse(last_response.body) |
| 230 | assert_equal community.id, json['community']['id'] | 228 | assert_equal community.id, json['community']['id'] |
| 231 | end | 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 | community = fast_create(Community, :environment_id => environment.id, :visible => false) | 233 | community = fast_create(Community, :environment_id => environment.id, :visible => false) |
| 236 | get "/api/v1/communities/#{community.id}" | 234 | get "/api/v1/communities/#{community.id}" |
| 237 | json = JSON.parse(last_response.body) | 235 | json = JSON.parse(last_response.body) |
| 238 | assert json['community'].blank? | 236 | assert json['community'].blank? |
| 239 | end | 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 | community = fast_create(Community, :environment_id => environment.id) | 241 | community = fast_create(Community, :environment_id => environment.id) |
| 244 | fast_create(Community, :environment_id => environment.id, :public_profile => false) | 242 | fast_create(Community, :environment_id => environment.id, :public_profile => false) |
| 245 | get "/api/v1/communities/#{community.id}" | 243 | get "/api/v1/communities/#{community.id}" |
| @@ -247,8 +245,8 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -247,8 +245,8 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 247 | assert_equal community.id, json['community']['id'] | 245 | assert_equal community.id, json['community']['id'] |
| 248 | end | 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 | community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) | 250 | community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) |
| 253 | community2 = fast_create(Community, :created_at => 2.days.ago) | 251 | community2 = fast_create(Community, :created_at => 2.days.ago) |
| 254 | 252 | ||
| @@ -269,8 +267,8 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -269,8 +267,8 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 269 | assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id | 267 | assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id |
| 270 | end | 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 | community1 = fast_create(Community, :public_profile => true) | 272 | community1 = fast_create(Community, :public_profile => true) |
| 275 | community2 = fast_create(Community) | 273 | community2 = fast_create(Community) |
| 276 | 274 | ||
| @@ -285,6 +283,4 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -285,6 +283,4 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 285 | assert_not_includes json["communities"].map { |a| a["id"] }, community2.id | 283 | assert_not_includes json["communities"].map { |a| a["id"] }, community2.id |
| 286 | end | 284 | end |
| 287 | 285 | ||
| 288 | - ###################End Visitor's tests ######################################3 | ||
| 289 | - | ||
| 290 | end | 286 | end |
test/api/profiles_test.rb
| @@ -80,7 +80,7 @@ class ProfilesTest < ActiveSupport::TestCase | @@ -80,7 +80,7 @@ class ProfilesTest < ActiveSupport::TestCase | ||
| 80 | 80 | ||
| 81 | end | 81 | end |
| 82 | 82 | ||
| 83 | - should 'visitor list all profiles' do | 83 | + should 'anonymous list all profiles' do |
| 84 | person1 = fast_create(Person) | 84 | person1 = fast_create(Person) |
| 85 | person2 = fast_create(Person) | 85 | person2 = fast_create(Person) |
| 86 | community = fast_create(Community) | 86 | community = fast_create(Community) |
| @@ -89,14 +89,14 @@ class ProfilesTest < ActiveSupport::TestCase | @@ -89,14 +89,14 @@ class ProfilesTest < ActiveSupport::TestCase | ||
| 89 | assert_equivalent [person1.id, person2.id, community.id], json.map {|p| p['id']} | 89 | assert_equivalent [person1.id, person2.id, community.id], json.map {|p| p['id']} |
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | - should 'visitor get person from profile id' do | 92 | + should 'anonymous get person from profile id' do |
| 93 | some_person = fast_create(Person) | 93 | some_person = fast_create(Person) |
| 94 | get "/api/v1/profiles/#{some_person.id}" | 94 | get "/api/v1/profiles/#{some_person.id}" |
| 95 | json = JSON.parse(last_response.body) | 95 | json = JSON.parse(last_response.body) |
| 96 | assert_equal some_person.id, json['id'] | 96 | assert_equal some_person.id, json['id'] |
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | - should 'visitor get community from profile id' do | 99 | + should 'anonymous get community from profile id' do |
| 100 | community = fast_create(Community) | 100 | community = fast_create(Community) |
| 101 | get "/api/v1/profiles/#{community.id}" | 101 | get "/api/v1/profiles/#{community.id}" |
| 102 | json = JSON.parse(last_response.body) | 102 | json = JSON.parse(last_response.body) |
test/api/test_helper.rb
| @@ -25,7 +25,7 @@ class ActiveSupport::TestCase | @@ -25,7 +25,7 @@ class ActiveSupport::TestCase | ||
| 25 | @params = {:private_token => @private_token} | 25 | @params = {:private_token => @private_token} |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | - def visitor_setup | 28 | + def anonymous_setup |
| 29 | @environment = Environment.default | 29 | @environment = Environment.default |
| 30 | @params = {} | 30 | @params = {} |
| 31 | end | 31 | end |