Commit 410aa5af3b3c8e2d8f23931c4c0e81823e6a49fa

Authored by Evandro Junior
Committed by Leandro Santos
1 parent 2fc43667

Name the logged user in the api tests

test/api/categories_test.rb
... ... @@ -3,7 +3,7 @@ require_relative 'test_helper'
3 3 class CategoriesTest < ActiveSupport::TestCase
4 4  
5 5  
6   - should 'list categories' do
  6 + should 'logged user list categories' do
7 7 login_api
8 8 category = fast_create(Category, :environment_id => environment.id)
9 9 get "/api/v1/categories/?#{params.to_query}"
... ... @@ -11,7 +11,7 @@ class CategoriesTest &lt; ActiveSupport::TestCase
11 11 assert_includes json["categories"].map { |c| c["name"] }, category.name
12 12 end
13 13  
14   - should 'get category by id' do
  14 + should 'logged user get category by id' do
15 15 login_api
16 16 category = fast_create(Category, :environment_id => environment.id)
17 17 get "/api/v1/categories/#{category.id}/?#{params.to_query}"
... ... @@ -19,7 +19,7 @@ class CategoriesTest &lt; ActiveSupport::TestCase
19 19 assert_equal category.name, json["category"]["name"]
20 20 end
21 21  
22   - should 'list parent and children when get category by id' do
  22 + should 'logged user list parent and children when get category by id' do
23 23 login_api
24 24 parent = fast_create(Category, :environment_id => environment.id)
25 25 child_1 = fast_create(Category, :environment_id => environment.id)
... ... @@ -37,7 +37,7 @@ class CategoriesTest &lt; ActiveSupport::TestCase
37 37 assert_equivalent [child_1.id, child_2.id], json['category']['children'].map { |c| c['id'] }
38 38 end
39 39  
40   - should 'include parent in categories list if params is true' do
  40 + should 'logged user include parent in categories list if params is true' do
41 41 login_api
42 42 parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category
43 43 child_1 = fast_create(Category, :environment_id => environment.id)
... ... @@ -60,7 +60,7 @@ class CategoriesTest &lt; ActiveSupport::TestCase
60 60 json["categories"].map { |c| c['parent'] && c['parent']['id'] }
61 61 end
62 62  
63   - should 'include children in categories list if params is true' do
  63 + should 'logged user include children in categories list if params is true' do
64 64 login_api
65 65 category = fast_create(Category, :environment_id => environment.id)
66 66 child_1 = fast_create(Category, :environment_id => environment.id)
... ... @@ -88,7 +88,7 @@ class CategoriesTest &lt; ActiveSupport::TestCase
88 88 expose_attributes = %w(id name full_name image display_color)
89 89  
90 90 expose_attributes.each do |attr|
91   - should "expose category #{attr} attribute by default" do
  91 + should "logged user expose category #{attr} attribute by default" do
92 92 login_api
93 93 category = fast_create(Category, :environment_id => environment.id)
94 94 get "/api/v1/categories/?#{params.to_query}"
... ...
test/api/comments_test.rb
... ... @@ -2,7 +2,7 @@ require_relative &#39;test_helper&#39;
2 2  
3 3 class CommentsTest < ActiveSupport::TestCase
4 4  
5   - should 'not list comments if user has no permission to view the source article' do
  5 + should 'logged user not list comments if user has no permission to view the source article' do
6 6 login_api
7 7 person = fast_create(Person)
8 8 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
... ... @@ -12,7 +12,7 @@ class CommentsTest &lt; ActiveSupport::TestCase
12 12 assert_equal 403, last_response.status
13 13 end
14 14  
15   - should 'not return comment if user has no permission to view the source article' do
  15 + should 'logged user not return comment if user has no permission to view the source article' do
16 16 login_api
17 17 person = fast_create(Person)
18 18 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
... ... @@ -23,7 +23,7 @@ class CommentsTest &lt; ActiveSupport::TestCase
23 23 assert_equal 403, last_response.status
24 24 end
25 25  
26   - should 'not comment an article if user has no permission to view it' do
  26 + should 'logged user not comment an article if user has no permission to view it' do
27 27 login_api
28 28 person = fast_create(Person)
29 29 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
... ... @@ -33,7 +33,7 @@ class CommentsTest &lt; ActiveSupport::TestCase
33 33 assert_equal 403, last_response.status
34 34 end
35 35  
36   - should 'return comments of an article' do
  36 + should 'logged user return comments of an article' do
37 37 login_api
38 38 article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
39 39 article.comments.create!(:body => "some comment", :author => user.person)
... ... @@ -45,7 +45,7 @@ class CommentsTest &lt; ActiveSupport::TestCase
45 45 assert_equal 2, json["comments"].length
46 46 end
47 47  
48   - should 'return comment of an article' do
  48 + should 'logged user return comment of an article' do
49 49 login_api
50 50 article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
51 51 comment = article.comments.create!(:body => "another comment", :author => user.person)
... ... @@ -56,7 +56,7 @@ class CommentsTest &lt; ActiveSupport::TestCase
56 56 assert_equal comment.id, json['comment']['id']
57 57 end
58 58  
59   - should 'comment an article' do
  59 + should 'logged user comment an article' do
60 60 login_api
61 61 article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
62 62 body = 'My comment'
... ... @@ -113,6 +113,19 @@ class CommentsTest &lt; ActiveSupport::TestCase
113 113 assert_equal [comment1.id], json["comments"].map { |c| c['id'] }
114 114 end
115 115  
  116 + should 'logged user comment creation define the source' do
  117 + login_api
  118 + amount = Comment.count
  119 + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  120 + body = 'My comment'
  121 + params.merge!({:body => body})
  122 +
  123 + post "/api/v1/articles/#{article.id}/comments?#{params.to_query}"
  124 + assert_equal amount + 1, Comment.count
  125 + comment = Comment.last
  126 + assert_not_nil comment.source
  127 + end
  128 +
116 129 should 'call plugin hotspot to filter unavailable comments' do
117 130 class Plugin1 < Noosfero::Plugin
118 131 def unavailable_comments(scope)
... ...
test/api/communities_test.rb
... ... @@ -6,7 +6,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
6 6 Community.delete_all
7 7 end
8 8  
9   - should 'list only communities' do
  9 + should 'logged user list only communities' do
10 10 login_api
11 11 community = fast_create(Community, :environment_id => environment.id)
12 12 enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise
... ... @@ -16,7 +16,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
16 16 assert_includes json['communities'].map {|c| c['id']}, community.id
17 17 end
18 18  
19   - should 'list all communities' do
  19 + should 'logged user list all communities' do
20 20 login_api
21 21 community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true)
22 22 community2 = fast_create(Community, :environment_id => environment.id)
... ... @@ -25,7 +25,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
25 25 assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']}
26 26 end
27 27  
28   - should 'not list invisible communities' do
  28 + should 'logged user not list invisible communities' do
29 29 login_api
30 30 community1 = fast_create(Community, :environment_id => environment.id)
31 31 fast_create(Community, :environment_id => environment.id, :visible => false)
... ... @@ -35,7 +35,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
35 35 assert_equal [community1.id], json['communities'].map {|c| c['id']}
36 36 end
37 37  
38   - should 'list private communities' do
  38 + should 'logged user list private communities' do
39 39 login_api
40 40 community1 = fast_create(Community, :environment_id => environment.id)
41 41 community2 = fast_create(Community, :environment_id => environment.id, :public_profile => false)
... ... @@ -45,7 +45,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
45 45 assert_equal [community1.id, community2.id], json['communities'].map {|c| c['id']}
46 46 end
47 47  
48   - should 'list private community for members' do
  48 + should 'logged user list private community for members' do
49 49 login_api
50 50 c1 = fast_create(Community, :environment_id => environment.id)
51 51 c2 = fast_create(Community, :environment_id => environment.id, :public_profile => false)
... ... @@ -56,7 +56,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
56 56 assert_equivalent [c1.id, c2.id], json['communities'].map {|c| c['id']}
57 57 end
58 58  
59   - should 'create a community' do
  59 + should 'logged user create a community' do
60 60 login_api
61 61 params[:community] = {:name => 'some'}
62 62 post "/api/v1/communities?#{params.to_query}"
... ... @@ -64,14 +64,14 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
64 64 assert_equal 'some', json['community']['name']
65 65 end
66 66  
67   - should 'return 400 status for invalid community creation' do
  67 + should 'logged user return 400 status for invalid community creation' do
68 68 login_api
69 69 post "/api/v1/communities?#{params.to_query}"
70 70 json = JSON.parse(last_response.body)
71 71 assert_equal 400, last_response.status
72 72 end
73 73  
74   - should 'get community' do
  74 + should 'logged user get community' do
75 75 login_api
76 76 community = fast_create(Community, :environment_id => environment.id)
77 77  
... ... @@ -80,7 +80,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
80 80 assert_equal community.id, json['community']['id']
81 81 end
82 82  
83   - should 'not get invisible community' do
  83 + should 'logged user not get invisible community' do
84 84 login_api
85 85 community = fast_create(Community, :environment_id => environment.id, :visible => false)
86 86  
... ... @@ -89,7 +89,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
89 89 assert json['community'].blank?
90 90 end
91 91  
92   - should 'not get private communities without permission' do
  92 + should 'logged user not get private communities without permission' do
93 93 login_api
94 94 community = fast_create(Community, :environment_id => environment.id)
95 95 fast_create(Community, :environment_id => environment.id, :public_profile => false)
... ... @@ -99,7 +99,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
99 99 assert_equal community.id, json['community']['id']
100 100 end
101 101  
102   - should 'get private community for members' do
  102 + should 'logged user get private community for members' do
103 103 login_api
104 104 community = fast_create(Community, :environment_id => environment.id, :public_profile => false, :visible => true)
105 105 community.add_member(person)
... ... @@ -109,7 +109,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
109 109 assert_equal community.id, json['community']['id']
110 110 end
111 111  
112   - should 'list person communities' do
  112 + should 'logged user list person communities' do
113 113 login_api
114 114 community = fast_create(Community, :environment_id => environment.id)
115 115 fast_create(Community, :environment_id => environment.id)
... ... @@ -120,7 +120,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
120 120 assert_equivalent [community.id], json['communities'].map {|c| c['id']}
121 121 end
122 122  
123   - should 'not list person communities invisible' do
  123 + should 'logged user not list person communities invisible' do
124 124 login_api
125 125 c1 = fast_create(Community, :environment_id => environment.id)
126 126 c2 = fast_create(Community, :environment_id => environment.id, :visible => false)
... ... @@ -132,7 +132,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
132 132 assert_equivalent [c1.id], json['communities'].map {|c| c['id']}
133 133 end
134 134  
135   - should 'list communities with pagination' do
  135 + should 'logged user list communities with pagination' do
136 136 login_api
137 137 community1 = fast_create(Community, :public_profile => true, :created_at => 1.day.ago)
138 138 community2 = fast_create(Community, :created_at => 2.days.ago)
... ... @@ -155,7 +155,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
155 155 assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id
156 156 end
157 157  
158   - should 'list communities with timestamp' do
  158 + should 'logged user list communities with timestamp' do
159 159 login_api
160 160 community1 = fast_create(Community, :public_profile => true)
161 161 community2 = fast_create(Community)
... ...
test/api/profiles_test.rb
... ... @@ -6,7 +6,7 @@ class ProfilesTest &lt; ActiveSupport::TestCase
6 6 Profile.delete_all
7 7 end
8 8  
9   - should 'list all profiles' do
  9 + should 'logged user list all profiles' do
10 10 login_api
11 11 person1 = fast_create(Person)
12 12 person2 = fast_create(Person)
... ... @@ -16,7 +16,7 @@ class ProfilesTest &lt; ActiveSupport::TestCase
16 16 assert_equivalent [person.id, person1.id, person2.id, community.id], json.map {|p| p['id']}
17 17 end
18 18  
19   - should 'get person from profile id' do
  19 + should 'logged user get person from profile id' do
20 20 login_api
21 21 some_person = fast_create(Person)
22 22 get "/api/v1/profiles/#{some_person.id}?#{params.to_query}"
... ... @@ -24,7 +24,7 @@ class ProfilesTest &lt; ActiveSupport::TestCase
24 24 assert_equal some_person.id, json['id']
25 25 end
26 26  
27   - should 'get community from profile id' do
  27 + should 'logged user get community from profile id' do
28 28 login_api
29 29 community = fast_create(Community)
30 30 get "/api/v1/profiles/#{community.id}?#{params.to_query}"
... ...