From 085aaaa9185809b174b4ad05bd1cb7e691dce599 Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Thu, 14 Apr 2016 17:18:08 -0300 Subject: [PATCH] Fix merge problems with master and other small fixes --- test/api/comments_test.rb | 35 ++++++++++++++++++++++++++++++----- test/api/communities_test.rb | 18 ++++++++---------- test/api/enterprises_test.rb | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ test/api/profiles_test.rb | 1 - 4 files changed, 131 insertions(+), 22 deletions(-) diff --git a/test/api/comments_test.rb b/test/api/comments_test.rb index b85724c..3792ea7 100644 --- a/test/api/comments_test.rb +++ b/test/api/comments_test.rb @@ -154,8 +154,8 @@ class CommentsTest < ActiveSupport::TestCase assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} end - should 'not visitor list comments if has no permission to view the source article' do - visitor_setup + 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? @@ -188,9 +188,9 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 200, last_response.status assert_equal comment.id, json['comment']['id'] end - - should 'not visitor comment an article (at least so far...)' do - visitor_setup + + 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' @@ -202,4 +202,29 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 401, last_response.status end + should 'paginate comments' do + login_api + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + 5.times { article.comments.create!(:body => "some comment", :author => user.person) } + params[:per_page] = 3 + + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 3, json["comments"].length + end + + should 'return only root comments' do + login_api + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + comment1 = article.comments.create!(:body => "some comment", :author => user.person) + comment2 = article.comments.create!(:body => "another comment", :author => user.person, :reply_of_id => comment1.id) + params[:without_reply] = true + + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal [comment1.id], json["comments"].map { |c| c['id'] } + end + end diff --git a/test/api/communities_test.rb b/test/api/communities_test.rb index 5269522..bbf2d15 100644 --- a/test/api/communities_test.rb +++ b/test/api/communities_test.rb @@ -25,7 +25,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} end - should 'logged user not list invisible communities' do + should 'not, logged user list invisible communities' do login_api community1 = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id, :visible => false) @@ -80,7 +80,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal community.id, json['community']['id'] end - should 'logged user not get invisible community' do + should 'not, logged user get invisible community' do login_api community = fast_create(Community, :environment_id => environment.id, :visible => false) @@ -89,7 +89,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert json['community'].blank? end - should 'logged user not get private communities without permission' do + should 'not, logged user get private communities without permission' do login_api community = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id, :public_profile => false) @@ -120,7 +120,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community.id], json['communities'].map {|c| c['id']} end - should 'logged user not list person communities invisible' do + should 'not, logged user list person communities invisible' do login_api c1 = fast_create(Community, :environment_id => environment.id) c2 = fast_create(Community, :environment_id => environment.id, :visible => false) @@ -190,7 +190,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} end - should 'not anonymous list invisible communities' do + 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) @@ -210,9 +210,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal [community1.id, community2.id], json['communities'].map {|c| c['id']} end - - - should 'not anonymous create a community' do + should 'not, anonymous create a community' do anonymous_setup params[:community] = {:name => 'some'} post "/api/v1/communities?#{params.to_query}" @@ -228,7 +226,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal community.id, json['community']['id'] end - should 'not anonymous get invisible community' do + 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}" @@ -236,7 +234,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert json['community'].blank? end - should 'anonymous not get private communities' do + should 'not, anonymous get private communities' do anonymous_setup community = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id, :public_profile => false) diff --git a/test/api/enterprises_test.rb b/test/api/enterprises_test.rb index 2dcd13e..cd852b1 100644 --- a/test/api/enterprises_test.rb +++ b/test/api/enterprises_test.rb @@ -4,10 +4,20 @@ class EnterprisesTest < ActiveSupport::TestCase def setup Enterprise.delete_all + end + + should 'logger user list only enterprises' do login_api + community = fast_create(Community, :environment_id => environment.id) # should not list this community + enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) + get "/api/v1/enterprises?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id + assert_not_includes json['enterprises'].map {|c| c['id']}, community.id end - should 'list only enterprises' do + should 'anonymous list only enterprises' do + anonymous_setup community = fast_create(Community, :environment_id => environment.id) # should not list this community enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) get "/api/v1/enterprises?#{params.to_query}" @@ -16,7 +26,17 @@ class EnterprisesTest < ActiveSupport::TestCase assert_not_includes json['enterprises'].map {|c| c['id']}, community.id end - should 'list all enterprises' do + should 'anonymous list all enterprises' do + anonymous_setup + enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) + enterprise2 = fast_create(Enterprise, :environment_id => environment.id) + get "/api/v1/enterprises?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} + end + + should 'logger user list all enterprises' do + login_api enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) enterprise2 = fast_create(Enterprise, :environment_id => environment.id) get "/api/v1/enterprises?#{params.to_query}" @@ -25,6 +45,27 @@ class EnterprisesTest < ActiveSupport::TestCase end should 'not list invisible enterprises' do + login_api + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) + fast_create(Enterprise, :visible => false) + + get "/api/v1/enterprises?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} + end + + should 'not, anonymous list invisible enterprises' do + anonymous_setup + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) + fast_create(Enterprise, :visible => false) + + get "/api/v1/enterprises?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} + end + + should 'not, logger user list invisible enterprises' do + login_api enterprise1 = fast_create(Enterprise, :environment_id => environment.id) fast_create(Enterprise, :visible => false) @@ -33,7 +74,8 @@ class EnterprisesTest < ActiveSupport::TestCase assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']} end - should 'list private enterprises' do + should 'anonymous list private enterprises' do + anonymous_setup enterprise1 = fast_create(Enterprise, :environment_id => environment.id) enterprise2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) @@ -42,7 +84,18 @@ class EnterprisesTest < ActiveSupport::TestCase assert_equal [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} end - should 'list private enterprise for members' do + should 'logged user list private enterprises' do + login_api + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) + enterprise2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) + + get "/api/v1/enterprises?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} + end + + should 'logged user list private enterprise for members' do + login_api c1 = fast_create(Enterprise, :environment_id => environment.id) c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) c2.add_member(person) @@ -52,7 +105,17 @@ class EnterprisesTest < ActiveSupport::TestCase assert_equivalent [c1.id, c2.id], json['enterprises'].map {|c| c['id']} end - should 'get enterprise' do + should 'anonymous get enterprise' do + anonymous_setup + enterprise = fast_create(Enterprise, :environment_id => environment.id) + + get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal enterprise.id, json['enterprise']['id'] + end + + should 'logged user get enterprise' do + login_api enterprise = fast_create(Enterprise, :environment_id => environment.id) get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" @@ -60,7 +123,17 @@ class EnterprisesTest < ActiveSupport::TestCase assert_equal enterprise.id, json['enterprise']['id'] end - should 'not get invisible enterprise' do + should 'not, logger user get invisible enterprise' do + login_api + enterprise = fast_create(Enterprise, :visible => false) + + get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert json['enterprise'].blank? + end + + should 'not, anonymous get invisible enterprise' do + anonymous_setup enterprise = fast_create(Enterprise, :visible => false) get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" @@ -69,6 +142,17 @@ class EnterprisesTest < ActiveSupport::TestCase end should 'not get private enterprises without permission' do + login_api + enterprise = fast_create(Enterprise, :environment_id => environment.id) + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) + + get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal enterprise.id, json['enterprise']['id'] + end + + should 'not, anonymous get private enterprises' do + anonymous_setup enterprise = fast_create(Enterprise, :environment_id => environment.id) fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) @@ -78,6 +162,7 @@ class EnterprisesTest < ActiveSupport::TestCase end should 'get private enterprise for members' do + login_api enterprise = fast_create(Enterprise, :public_profile => false) enterprise.add_member(person) @@ -87,6 +172,7 @@ class EnterprisesTest < ActiveSupport::TestCase end should 'list person enterprises' do + login_api enterprise = fast_create(Enterprise, :environment_id => environment.id) fast_create(Enterprise, :environment_id => environment.id) enterprise.add_member(person) @@ -97,6 +183,7 @@ class EnterprisesTest < ActiveSupport::TestCase end should 'not list person enterprises invisible' do + login_api c1 = fast_create(Enterprise, :environment_id => environment.id) c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false) c1.add_member(person) diff --git a/test/api/profiles_test.rb b/test/api/profiles_test.rb index 95d16ba..26e3272 100644 --- a/test/api/profiles_test.rb +++ b/test/api/profiles_test.rb @@ -128,5 +128,4 @@ class ProfilesTest < ActiveSupport::TestCase refute json.has_key?('Rating') end - end -- libgit2 0.21.2