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