From 286182fe900413aeb8fe5bc928447bd3ba49d4de Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Thu, 7 Apr 2016 15:19:20 -0300 Subject: [PATCH] Renamed visitor to anonymous --- test/unit/api/categories_test.rb | 28 +++++++++++++--------------- test/unit/api/comments_test.rb | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------- test/unit/api/communities_test.rb | 44 ++++++++++++++++++++------------------------ test/unit/api/profiles_test.rb | 6 +++--- test/unit/api/test_helper.rb | 2 +- 5 files changed, 88 insertions(+), 98 deletions(-) diff --git a/test/unit/api/categories_test.rb b/test/unit/api/categories_test.rb index d5a8bb8..053ff27 100644 --- a/test/unit/api/categories_test.rb +++ b/test/unit/api/categories_test.rb @@ -97,26 +97,24 @@ class CategoriesTest < ActiveSupport::TestCase end end - ############## Visitors' tests #######################################################################33 - - should 'visitor list categories' do - visitor_setup + should 'anonymous list categories' do + anonymous_setup category = fast_create(Category, :environment_id => environment.id) get "/api/v1/categories/?#{params.to_query}" json = JSON.parse(last_response.body) assert_includes json["categories"].map { |c| c["name"] }, category.name end - should 'visitor get category by id' do - visitor_setup + should 'anonymous get category by id' do + anonymous_setup category = fast_create(Category, :environment_id => environment.id) get "/api/v1/categories/#{category.id}/?#{params.to_query}" json = JSON.parse(last_response.body) assert_equal category.name, json["category"]["name"] end - should 'visitor list parent and children when get category by id' do - visitor_setup + should 'anonymous list parent and children when get category by id' do + anonymous_setup parent = fast_create(Category, :environment_id => environment.id) child_1 = fast_create(Category, :environment_id => environment.id) child_2 = fast_create(Category, :environment_id => environment.id) @@ -133,8 +131,8 @@ class CategoriesTest < ActiveSupport::TestCase assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } end - should 'visitor include parent in categories list if params is true' do - visitor_setup + should 'anonymous include parent in categories list if params is true' do + anonymous_setup parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category child_1 = fast_create(Category, :environment_id => environment.id) child_2 = fast_create(Category, :environment_id => environment.id) @@ -156,8 +154,8 @@ class CategoriesTest < ActiveSupport::TestCase json["categories"].map { |c| c['parent'] && c['parent']['id'] } end - should 'visitor include children in categories list if params is true' do - visitor_setup + should 'anonymous include children in categories list if params is true' do + anonymous_setup category = fast_create(Category, :environment_id => environment.id) child_1 = fast_create(Category, :environment_id => environment.id) child_2 = fast_create(Category, :environment_id => environment.id) @@ -182,8 +180,8 @@ class CategoriesTest < ActiveSupport::TestCase end expose_attributes.each do |attr| - should "visitor expose category #{attr} attribute by default" do - visitor_setup + should "anonymous expose category #{attr} attribute by default" do + anonymous_setup category = fast_create(Category, :environment_id => environment.id) get "/api/v1/categories/?#{params.to_query}" json = JSON.parse(last_response.body) @@ -191,6 +189,6 @@ class CategoriesTest < ActiveSupport::TestCase end end - ################################# End visitors' test #################################################################################### + end diff --git a/test/unit/api/comments_test.rb b/test/unit/api/comments_test.rb index de41cfa..1320079 100644 --- a/test/unit/api/comments_test.rb +++ b/test/unit/api/comments_test.rb @@ -69,68 +69,64 @@ class CommentsTest < ActiveSupport::TestCase end should 'comment creation define the source' do - login_api - amount = Comment.count - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") - body = 'My comment' - params.merge!({:body => body}) - - post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" - assert_equal amount + 1, Comment.count - comment = Comment.last - assert_not_nil comment.source + login_api + amount = Comment.count + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + body = 'My comment' + params.merge!({:body => body}) + + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + assert_equal amount + 1, Comment.count + comment = Comment.last + assert_not_nil comment.source end -##################### Visitors' tests ############################################### - -should 'not visitor list comments if has no permission to view the source article' do - visitor_setup - person = fast_create(Person) - article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) - assert !article.published? + should 'not anonymous list comments if has no permission to view the source article' do + anonymous_setup + person = fast_create(Person) + article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) + assert !article.published? - get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" - assert_equal 403, last_response.status -end + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + assert_equal 403, last_response.status + end -should 'visitor return comments of an article' do - visitor_setup - person = fast_create(Person) - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") - article.comments.create!(:body => "some comment", :author => person) - article.comments.create!(:body => "another comment", :author => person) - - get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal 2, json["comments"].length -end + should 'anonymous return comments of an article' do + anonymous_setup + person = fast_create(Person) + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") + article.comments.create!(:body => "some comment", :author => person) + article.comments.create!(:body => "another comment", :author => person) -should 'visitor return comment of an article' do - visitor_setup - person = fast_create(Person) - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") - comment = article.comments.create!(:body => "another comment", :author => person) + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 2, json["comments"].length + end - get "/api/v1/articles/#{article.id}/comments/#{comment.id}?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal comment.id, json['comment']['id'] -end + should 'anonymous return comment of an article' do + anonymous_setup + person = fast_create(Person) + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") + comment = article.comments.create!(:body => "another comment", :author => person) -should 'not visitor comment an article (at least so far...)' do - visitor_setup - person = fast_create(Person) - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") - body = 'My comment' - name = "John Doe" - email = "JohnDoe@gmail.com" - params.merge!({:body => body, name: name, email: email}) - post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equal 401, last_response.status -end + get "/api/v1/articles/#{article.id}/comments/#{comment.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal comment.id, json['comment']['id'] + end -################################## End Visitors's tests ############################################################ + should 'not anonymous comment an article (at least so far...)' do + anonymous_setup + person = fast_create(Person) + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") + body = 'My comment' + name = "John Doe" + email = "JohnDoe@gmail.com" + params.merge!({:body => body, name: name, email: email}) + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal 401, last_response.status + end end diff --git a/test/unit/api/communities_test.rb b/test/unit/api/communities_test.rb index 8f93f76..e05e0fb 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -171,10 +171,8 @@ class CommunitiesTest < ActiveSupport::TestCase assert_not_includes json["communities"].map { |a| a["id"] }, community2.id end - ################### Visitor's tests ######################################3 - - should 'visitor list only communities' do - visitor_setup + should 'anonymous list only communities' do + anonymous_setup community = fast_create(Community, :environment_id => environment.id) enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise get "/api/v1/communities?#{params.to_query}" @@ -183,8 +181,8 @@ class CommunitiesTest < ActiveSupport::TestCase assert_includes json['communities'].map {|c| c['id']}, community.id end - should 'visitor list all communities' do - visitor_setup + should 'anonymous list all communities' do + anonymous_setup community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) community2 = fast_create(Community, :environment_id => environment.id) get "/api/v1/communities?#{params.to_query}" @@ -192,8 +190,8 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} end - should 'not visitor list invisible communities' do - visitor_setup + should 'not anonymous list invisible communities' do + anonymous_setup community1 = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id, :visible => false) @@ -202,8 +200,8 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal [community1.id], json['communities'].map {|c| c['id']} end - should 'visitor list private communities' do - visitor_setup + should 'anonymous list private communities' do + anonymous_setup community1 = fast_create(Community, :environment_id => environment.id) community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) @@ -214,32 +212,32 @@ class CommunitiesTest < ActiveSupport::TestCase - should 'not visitor create a community' do - visitor_setup + should 'not anonymous create a community' do + anonymous_setup params[:community] = {:name => 'some'} post "/api/v1/communities?#{params.to_query}" json = JSON.parse(last_response.body) assert_equal 401, last_response.status end - should 'visitor get community' do - visitor_setup + should 'anonymous get community' do + anonymous_setup community = fast_create(Community, :environment_id => environment.id) get "/api/v1/communities/#{community.id}" json = JSON.parse(last_response.body) assert_equal community.id, json['community']['id'] end - should 'not visitor get invisible community' do - visitor_setup + should 'not anonymous get invisible community' do + anonymous_setup community = fast_create(Community, :environment_id => environment.id, :visible => false) get "/api/v1/communities/#{community.id}" json = JSON.parse(last_response.body) assert json['community'].blank? end - should 'visitor not get private communities' do - visitor_setup + should 'anonymous not get private communities' do + anonymous_setup community = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id, :public_profile => false) get "/api/v1/communities/#{community.id}" @@ -247,8 +245,8 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal community.id, json['community']['id'] end - should 'visitor list communities with pagination' do - visitor_setup + should 'anonymous list communities with pagination' do + anonymous_setup community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) community2 = fast_create(Community, :created_at => 2.days.ago) @@ -269,8 +267,8 @@ class CommunitiesTest < ActiveSupport::TestCase assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id end - should 'visitor list communities with timestamp' do - visitor_setup + should 'anonymous list communities with timestamp' do + anonymous_setup community1 = fast_create(Community, :public_profile => true) community2 = fast_create(Community) @@ -285,6 +283,4 @@ class CommunitiesTest < ActiveSupport::TestCase assert_not_includes json["communities"].map { |a| a["id"] }, community2.id end - ###################End Visitor's tests ######################################3 - end diff --git a/test/unit/api/profiles_test.rb b/test/unit/api/profiles_test.rb index 6c21b8d..551a2cb 100644 --- a/test/unit/api/profiles_test.rb +++ b/test/unit/api/profiles_test.rb @@ -32,7 +32,7 @@ class ProfilesTest < ActiveSupport::TestCase assert_equal community.id, json['id'] end - should 'visitor list all profiles' do + should 'anonymous list all profiles' do person1 = fast_create(Person) person2 = fast_create(Person) community = fast_create(Community) @@ -41,14 +41,14 @@ class ProfilesTest < ActiveSupport::TestCase assert_equivalent [person1.id, person2.id, community.id], json.map {|p| p['id']} end - should 'visitor get person from profile id' do + should 'anonymous get person from profile id' do some_person = fast_create(Person) get "/api/v1/profiles/#{some_person.id}" json = JSON.parse(last_response.body) assert_equal some_person.id, json['id'] end - should 'visitor get community from profile id' do + should 'anonymous get community from profile id' do community = fast_create(Community) get "/api/v1/profiles/#{community.id}" json = JSON.parse(last_response.body) diff --git a/test/unit/api/test_helper.rb b/test/unit/api/test_helper.rb index fb4ad76..bc2795f 100644 --- a/test/unit/api/test_helper.rb +++ b/test/unit/api/test_helper.rb @@ -25,7 +25,7 @@ class ActiveSupport::TestCase @params = {:private_token => @private_token} end - def visitor_setup + def anonymous_setup @environment = Environment.default @params = {} end -- libgit2 0.21.2