From 410aa5af3b3c8e2d8f23931c4c0e81823e6a49fa Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Thu, 7 Apr 2016 16:22:00 -0300 Subject: [PATCH] Name the logged user in the api tests --- test/api/categories_test.rb | 12 ++++++------ test/api/comments_test.rb | 25 +++++++++++++++++++------ test/api/communities_test.rb | 30 +++++++++++++++--------------- test/api/profiles_test.rb | 6 +++--- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/test/api/categories_test.rb b/test/api/categories_test.rb index 053ff27..e7133a0 100644 --- a/test/api/categories_test.rb +++ b/test/api/categories_test.rb @@ -3,7 +3,7 @@ require_relative 'test_helper' class CategoriesTest < ActiveSupport::TestCase - should 'list categories' do + should 'logged user list categories' do login_api category = fast_create(Category, :environment_id => environment.id) get "/api/v1/categories/?#{params.to_query}" @@ -11,7 +11,7 @@ class CategoriesTest < ActiveSupport::TestCase assert_includes json["categories"].map { |c| c["name"] }, category.name end - should 'get category by id' do + should 'logged user get category by id' do login_api category = fast_create(Category, :environment_id => environment.id) get "/api/v1/categories/#{category.id}/?#{params.to_query}" @@ -19,7 +19,7 @@ class CategoriesTest < ActiveSupport::TestCase assert_equal category.name, json["category"]["name"] end - should 'list parent and children when get category by id' do + should 'logged user list parent and children when get category by id' do login_api parent = fast_create(Category, :environment_id => environment.id) child_1 = fast_create(Category, :environment_id => environment.id) @@ -37,7 +37,7 @@ class CategoriesTest < ActiveSupport::TestCase assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] } end - should 'include parent in categories list if params is true' do + should 'logged user include parent in categories list if params is true' do login_api parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category child_1 = fast_create(Category, :environment_id => environment.id) @@ -60,7 +60,7 @@ class CategoriesTest < ActiveSupport::TestCase json["categories"].map { |c| c['parent'] && c['parent']['id'] } end - should 'include children in categories list if params is true' do + should 'logged user include children in categories list if params is true' do login_api category = fast_create(Category, :environment_id => environment.id) child_1 = fast_create(Category, :environment_id => environment.id) @@ -88,7 +88,7 @@ class CategoriesTest < ActiveSupport::TestCase expose_attributes = %w(id name full_name image display_color) expose_attributes.each do |attr| - should "expose category #{attr} attribute by default" do + should "logged user expose category #{attr} attribute by default" do login_api category = fast_create(Category, :environment_id => environment.id) get "/api/v1/categories/?#{params.to_query}" diff --git a/test/api/comments_test.rb b/test/api/comments_test.rb index bb13faf..b85724c 100644 --- a/test/api/comments_test.rb +++ b/test/api/comments_test.rb @@ -2,7 +2,7 @@ require_relative 'test_helper' class CommentsTest < ActiveSupport::TestCase - should 'not list comments if user has no permission to view the source article' do + should 'logged user not list comments if user has no permission to view the source article' do login_api person = fast_create(Person) article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) @@ -12,7 +12,7 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 403, last_response.status end - should 'not return comment if user has no permission to view the source article' do + should 'logged user not return comment if user has no permission to view the source article' do login_api person = fast_create(Person) article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) @@ -23,7 +23,7 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 403, last_response.status end - should 'not comment an article if user has no permission to view it' do + should 'logged user not comment an article if user has no permission to view it' do login_api person = fast_create(Person) article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) @@ -33,7 +33,7 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 403, last_response.status end - should 'return comments of an article' do + should 'logged user return comments of an article' do login_api article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") article.comments.create!(:body => "some comment", :author => user.person) @@ -45,7 +45,7 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 2, json["comments"].length end - should 'return comment of an article' do + should 'logged user return comment of an article' do login_api article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") comment = article.comments.create!(:body => "another comment", :author => user.person) @@ -56,7 +56,7 @@ class CommentsTest < ActiveSupport::TestCase assert_equal comment.id, json['comment']['id'] end - should 'comment an article' do + should 'logged user comment an article' do login_api article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") body = 'My comment' @@ -113,6 +113,19 @@ class CommentsTest < ActiveSupport::TestCase assert_equal [comment1.id], json["comments"].map { |c| c['id'] } end + should 'logged user 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 + end + should 'call plugin hotspot to filter unavailable comments' do class Plugin1 < Noosfero::Plugin def unavailable_comments(scope) diff --git a/test/api/communities_test.rb b/test/api/communities_test.rb index e05e0fb..c6e28a3 100644 --- a/test/api/communities_test.rb +++ b/test/api/communities_test.rb @@ -6,7 +6,7 @@ class CommunitiesTest < ActiveSupport::TestCase Community.delete_all end - should 'list only communities' do + should 'logged user list only communities' do login_api community = fast_create(Community, :environment_id => environment.id) enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise @@ -16,7 +16,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_includes json['communities'].map {|c| c['id']}, community.id end - should 'list all communities' do + should 'logged user list all communities' do login_api community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) community2 = fast_create(Community, :environment_id => environment.id) @@ -25,7 +25,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} end - should 'not list invisible communities' do + should 'logged user not list invisible communities' do login_api community1 = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id, :visible => false) @@ -35,7 +35,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal [community1.id], json['communities'].map {|c| c['id']} end - should 'list private communities' do + should 'logged user list private communities' do login_api community1 = fast_create(Community, :environment_id => environment.id) community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) @@ -45,7 +45,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal [community1.id, community2.id], json['communities'].map {|c| c['id']} end - should 'list private community for members' do + should 'logged user list private community for members' do login_api c1 = fast_create(Community, :environment_id => environment.id) c2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) @@ -56,7 +56,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [c1.id, c2.id], json['communities'].map {|c| c['id']} end - should 'create a community' do + should 'logged user create a community' do login_api params[:community] = {:name => 'some'} post "/api/v1/communities?#{params.to_query}" @@ -64,14 +64,14 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal 'some', json['community']['name'] end - should 'return 400 status for invalid community creation' do + should 'logged user return 400 status for invalid community creation' do login_api post "/api/v1/communities?#{params.to_query}" json = JSON.parse(last_response.body) assert_equal 400, last_response.status end - should 'get community' do + should 'logged user get community' do login_api community = fast_create(Community, :environment_id => environment.id) @@ -80,7 +80,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal community.id, json['community']['id'] end - should 'not get invisible community' do + should 'logged user not 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 'not get private communities without permission' do + should 'logged user not 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) @@ -99,7 +99,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal community.id, json['community']['id'] end - should 'get private community for members' do + should 'logged user get private community for members' do login_api community = fast_create(Community, :environment_id => environment.id, :public_profile => false, :visible => true) community.add_member(person) @@ -109,7 +109,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equal community.id, json['community']['id'] end - should 'list person communities' do + should 'logged user list person communities' do login_api community = fast_create(Community, :environment_id => environment.id) fast_create(Community, :environment_id => environment.id) @@ -120,7 +120,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community.id], json['communities'].map {|c| c['id']} end - should 'not list person communities invisible' do + should 'logged user not 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) @@ -132,7 +132,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [c1.id], json['communities'].map {|c| c['id']} end - should 'list communities with pagination' do + should 'logged user list communities with pagination' do login_api community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago) community2 = fast_create(Community, :created_at => 2.days.ago) @@ -155,7 +155,7 @@ class CommunitiesTest < ActiveSupport::TestCase assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id end - should 'list communities with timestamp' do + should 'logged user list communities with timestamp' do login_api community1 = fast_create(Community, :public_profile => true) community2 = fast_create(Community) diff --git a/test/api/profiles_test.rb b/test/api/profiles_test.rb index fddb3c7..8cbcb96 100644 --- a/test/api/profiles_test.rb +++ b/test/api/profiles_test.rb @@ -6,7 +6,7 @@ class ProfilesTest < ActiveSupport::TestCase Profile.delete_all end - should 'list all profiles' do + should 'logged user list all profiles' do login_api person1 = fast_create(Person) person2 = fast_create(Person) @@ -16,7 +16,7 @@ class ProfilesTest < ActiveSupport::TestCase assert_equivalent [person.id, person1.id, person2.id, community.id], json.map {|p| p['id']} end - should 'get person from profile id' do + should 'logged user get person from profile id' do login_api some_person = fast_create(Person) get "/api/v1/profiles/#{some_person.id}?#{params.to_query}" @@ -24,7 +24,7 @@ class ProfilesTest < ActiveSupport::TestCase assert_equal some_person.id, json['id'] end - should 'get community from profile id' do + should 'logged user get community from profile id' do login_api community = fast_create(Community) get "/api/v1/profiles/#{community.id}?#{params.to_query}" -- libgit2 0.21.2