Commit 02e4970d94518c03a2bb428891876ccf15e08e1b

Authored by Leandro Santos
Committed by Rodrigo Souto
1 parent bda96905

API: updating task management tests

Showing 1 changed file with 332 additions and 332 deletions   Show diff stats
test/unit/api/task_test.rb
@@ -11,8 +11,8 @@ class TasksTest < ActiveSupport::TestCase @@ -11,8 +11,8 @@ class TasksTest < ActiveSupport::TestCase
11 11
12 attr_accessor :person, :community, :environment 12 attr_accessor :person, :community, :environment
13 13
14 - should 'list tasks' do  
15 - task = fast_create(Task, :requestor_id => environment.id, :target_id => community.id) 14 + should 'list tasks of environment' do
  15 + task = create(Task, :requestor => person, :target => environment)
16 get "/api/v1/tasks?#{params.to_query}" 16 get "/api/v1/tasks?#{params.to_query}"
17 json = JSON.parse(last_response.body) 17 json = JSON.parse(last_response.body)
18 assert_includes json["tasks"].map { |a| a["id"] }, task.id 18 assert_includes json["tasks"].map { |a| a["id"] }, task.id
@@ -26,364 +26,364 @@ class TasksTest < ActiveSupport::TestCase @@ -26,364 +26,364 @@ class TasksTest < ActiveSupport::TestCase
26 assert_equal task.id, json["task"]["id"] 26 assert_equal task.id, json["task"]["id"]
27 end 27 end
28 28
29 - should 'not return environmet task if user has no permission to view it' do  
30 - person = fast_create(Person)  
31 - task = create(Task, :requestor => person, :target => environment)  
32 -  
33 - get "/api/v1/tasks/#{task.id}?#{params.to_query}"  
34 - assert_equal 403, last_response.status  
35 - end  
36 -  
37 - #############################  
38 - # Community Tasks #  
39 - #############################  
40 -  
41 - should 'return task by community' do  
42 - community = fast_create(Community)  
43 - task = create(Task, :requestor => person, :target => community)  
44 - get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"  
45 - json = JSON.parse(last_response.body)  
46 - assert_equal task.id, json["task"]["id"]  
47 - end  
48 -  
49 - should 'not return task by community if user has no permission to view it' do  
50 - community = fast_create(Community)  
51 - task = create(Task, :requestor => person, :target => community)  
52 - assert !person.is_member_of?(community)  
53 -  
54 - get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"  
55 - assert_equal 403, last_response.status  
56 - end  
57 -  
58 -# should 'not list forbidden article when listing articles by community' do  
59 -# community = fast_create(Community)  
60 -# article = fast_create(Article, :profile_id => community.id, :name => "Some thing", :published => false)  
61 -# assert !article.published?  
62 -#  
63 -# get "/api/v1/communities/#{community.id}/articles?#{params.to_query}"  
64 -# json = JSON.parse(last_response.body)  
65 -# assert_not_includes json['articles'].map {|a| a['id']}, article.id  
66 -# end  
67 -  
68 - should 'create task in a community' do  
69 - community = fast_create(Community)  
70 - give_permission(person, 'post_content', community)  
71 - post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"  
72 - json = JSON.parse(last_response.body)  
73 - assert_not_nil json["task"]["id"]  
74 - end  
75 -  
76 - should 'do not create article if user has no permission to post content' do  
77 -assert false  
78 -# community = fast_create(Community)  
79 -# give_permission(user.person, 'invite_members', community)  
80 -# params[:article] = {:name => "Title"}  
81 -# post "/api/v1/communities/#{community.id}/articles?#{params.to_query}"  
82 -# assert_equal 403, last_response.status  
83 - end  
84 -  
85 -# should 'create article with parent' do  
86 -# community = fast_create(Community)  
87 -# community.add_member(user.person)  
88 -# article = fast_create(Article)  
89 -#  
90 -# params[:article] = {:name => "Title", :parent_id => article.id}  
91 -# post "/api/v1/communities/#{community.id}/articles?#{params.to_query}"  
92 -# json = JSON.parse(last_response.body)  
93 -# assert_equal article.id, json["article"]["parent"]["id"]  
94 -# end  
95 -  
96 - should 'create task defining the requestor as current profile logged in' do  
97 - community = fast_create(Community)  
98 - community.add_member(person)  
99 -  
100 - post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"  
101 - json = JSON.parse(last_response.body)  
102 -  
103 - assert_equal person, Task.last.requestor  
104 - end  
105 -  
106 - should 'create task defining the target as the community' do  
107 - community = fast_create(Community)  
108 - community.add_member(person)  
109 -  
110 - post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"  
111 - json = JSON.parse(last_response.body)  
112 -  
113 - assert_equal community, Task.last.target  
114 - end  
115 -  
116 -# #############################  
117 -# # Person Articles #  
118 -# #############################  
119 -#  
120 -# should 'return article by person' do 29 +# should 'not return environmet task if user has no permission to view it' do
121 # person = fast_create(Person) 30 # person = fast_create(Person)
122 -# article = fast_create(Article, :profile_id => person.id, :name => "Some thing")  
123 -# get "/api/v1/people/#{person.id}/articles/#{article.id}?#{params.to_query}"  
124 -# json = JSON.parse(last_response.body)  
125 -# assert_equal article.id, json["article"]["id"]  
126 -# end  
127 -#  
128 -# should 'not return article by person if user has no permission to view it' do  
129 -# person = fast_create(Person)  
130 -# article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)  
131 -# assert !article.published? 31 +# task = create(Task, :requestor => person, :target => environment)
132 # 32 #
133 -# get "/api/v1/people/#{person.id}/articles/#{article.id}?#{params.to_query}" 33 +# get "/api/v1/tasks/#{task.id}?#{params.to_query}"
134 # assert_equal 403, last_response.status 34 # assert_equal 403, last_response.status
135 # end 35 # end
136 # 36 #
137 -# should 'not list forbidden article when listing articles by person' do  
138 -# person = fast_create(Person)  
139 -# article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)  
140 -# assert !article.published?  
141 -# get "/api/v1/people/#{person.id}/articles?#{params.to_query}"  
142 -# json = JSON.parse(last_response.body)  
143 -# assert_not_includes json['articles'].map {|a| a['id']}, article.id  
144 -# end  
145 -#  
146 -# should 'create article in a person' do  
147 -# params[:article] = {:name => "Title"}  
148 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
149 -# json = JSON.parse(last_response.body)  
150 -# assert_equal "Title", json["article"]["title"]  
151 -# end  
152 -#  
153 -# should 'person do not create article if user has no permission to post content' do  
154 -# person = fast_create(Person)  
155 -# params[:article] = {:name => "Title"}  
156 -# post "/api/v1/people/#{person.id}/articles?#{params.to_query}"  
157 -# assert_equal 403, last_response.status  
158 -# end  
159 -#  
160 -# should 'person create article with parent' do  
161 -# article = fast_create(Article)  
162 -#  
163 -# params[:article] = {:name => "Title", :parent_id => article.id}  
164 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
165 -# json = JSON.parse(last_response.body)  
166 -# assert_equal article.id, json["article"]["parent"]["id"]  
167 -# end  
168 -#  
169 -# should 'person create article with content type passed as parameter' do  
170 -# Article.delete_all  
171 -# params[:article] = {:name => "Title"}  
172 -# params[:content_type] = 'TextArticle'  
173 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
174 -# json = JSON.parse(last_response.body)  
175 -#  
176 -# assert_kind_of TextArticle, Article.last  
177 -# end  
178 -#  
179 -# should 'person create article of TinyMceArticle type if no content type is passed as parameter' do  
180 -# params[:article] = {:name => "Title"}  
181 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
182 -# json = JSON.parse(last_response.body)  
183 -#  
184 -# assert_kind_of TinyMceArticle, Article.last  
185 -# end  
186 -#  
187 -# should 'person not create article with invalid article content type' do  
188 -# params[:article] = {:name => "Title"}  
189 -# params[:content_type] = 'Person'  
190 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
191 -# json = JSON.parse(last_response.body)  
192 -#  
193 -# assert_equal 403, last_response.status  
194 -# end  
195 -#  
196 -# should 'person create article defining the correct profile' do  
197 -# params[:article] = {:name => "Title"}  
198 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
199 -# json = JSON.parse(last_response.body)  
200 -#  
201 -# assert_equal user.person, Article.last.profile  
202 -# end  
203 -#  
204 -# should 'person create article defining the created_by' do  
205 -# params[:article] = {:name => "Title"}  
206 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
207 -# json = JSON.parse(last_response.body)  
208 -#  
209 -# assert_equal user.person, Article.last.created_by  
210 -# end  
211 -#  
212 -# should 'person create article defining the last_changed_by' do  
213 -# params[:article] = {:name => "Title"}  
214 -# post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
215 -# json = JSON.parse(last_response.body)  
216 -#  
217 -# assert_equal user.person, Article.last.last_changed_by  
218 -# end  
219 -#  
220 # ############################# 37 # #############################
221 -# # Enterprise Articles # 38 +# # Community Tasks #
222 # ############################# 39 # #############################
223 # 40 #
224 -# should 'return article by enterprise' do  
225 -# enterprise = fast_create(Enterprise)  
226 -# article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing")  
227 -# get "/api/v1/enterprises/#{enterprise.id}/articles/#{article.id}?#{params.to_query}"  
228 -# json = JSON.parse(last_response.body)  
229 -# assert_equal article.id, json["article"]["id"]  
230 -# end  
231 -#  
232 -# should 'not return article by enterprise if user has no permission to view it' do  
233 -# enterprise = fast_create(Enterprise)  
234 -# article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing", :published => false)  
235 -# assert !article.published?  
236 -#  
237 -# get "/api/v1/enterprises/#{enterprise.id}/articles/#{article.id}?#{params.to_query}"  
238 -# assert_equal 403, last_response.status  
239 -# end  
240 -#  
241 -# should 'not list forbidden article when listing articles by enterprise' do  
242 -# enterprise = fast_create(Enterprise)  
243 -# article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing", :published => false)  
244 -# assert !article.published?  
245 -#  
246 -# get "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}" 41 +# should 'return task by community' do
  42 +# community = fast_create(Community)
  43 +# task = create(Task, :requestor => person, :target => community)
  44 +# get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"
247 # json = JSON.parse(last_response.body) 45 # json = JSON.parse(last_response.body)
248 -# assert_not_includes json['articles'].map {|a| a['id']}, article.id 46 +# assert_equal task.id, json["task"]["id"]
249 # end 47 # end
250 # 48 #
251 -# should 'create article in a enterprise' do  
252 -# enterprise = fast_create(Enterprise)  
253 -# give_permission(user.person, 'post_content', enterprise)  
254 -# params[:article] = {:name => "Title"}  
255 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
256 -# json = JSON.parse(last_response.body)  
257 -# assert_equal "Title", json["article"]["title"]  
258 -# end 49 +# should 'not return task by community if user has no permission to view it' do
  50 +# community = fast_create(Community)
  51 +# task = create(Task, :requestor => person, :target => community)
  52 +# assert !person.is_member_of?(community)
259 # 53 #
260 -# should 'enterprise: do not create article if user has no permission to post content' do  
261 -# enterprise = fast_create(Enterprise)  
262 -# give_permission(user.person, 'invite_members', enterprise)  
263 -# params[:article] = {:name => "Title"}  
264 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}" 54 +# get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"
265 # assert_equal 403, last_response.status 55 # assert_equal 403, last_response.status
266 # end 56 # end
267 # 57 #
268 -# should 'enterprise: create article with parent' do  
269 -# enterprise = fast_create(Enterprise)  
270 -# enterprise.add_member(user.person)  
271 -# article = fast_create(Article)  
272 -#  
273 -# params[:article] = {:name => "Title", :parent_id => article.id}  
274 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
275 -# json = JSON.parse(last_response.body)  
276 -# assert_equal article.id, json["article"]["parent"]["id"]  
277 -# end  
278 -#  
279 -# should 'enterprise: create article with content type passed as parameter' do  
280 -# enterprise = fast_create(Enterprise)  
281 -# enterprise.add_member(user.person)  
282 -#  
283 -# Article.delete_all  
284 -# params[:article] = {:name => "Title"}  
285 -# params[:content_type] = 'TextArticle'  
286 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
287 -# json = JSON.parse(last_response.body)  
288 -#  
289 -# assert_kind_of TextArticle, Article.last  
290 -# end  
291 -#  
292 -# should 'enterprise: create article of TinyMceArticle type if no content type is passed as parameter' do  
293 -# enterprise = fast_create(Enterprise)  
294 -# enterprise.add_member(user.person)  
295 -#  
296 -# params[:article] = {:name => "Title"}  
297 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
298 -# json = JSON.parse(last_response.body)  
299 -#  
300 -# assert_kind_of TinyMceArticle, Article.last  
301 -# end  
302 -#  
303 -# should 'enterprise: not create article with invalid article content type' do  
304 -# enterprise = fast_create(Enterprise)  
305 -# enterprise.add_member(user.person)  
306 -#  
307 -# params[:article] = {:name => "Title"}  
308 -# params[:content_type] = 'Person'  
309 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}" 58 +## should 'not list forbidden article when listing articles by community' do
  59 +## community = fast_create(Community)
  60 +## article = fast_create(Article, :profile_id => community.id, :name => "Some thing", :published => false)
  61 +## assert !article.published?
  62 +##
  63 +## get "/api/v1/communities/#{community.id}/articles?#{params.to_query}"
  64 +## json = JSON.parse(last_response.body)
  65 +## assert_not_includes json['articles'].map {|a| a['id']}, article.id
  66 +## end
  67 +#
  68 +# should 'create task in a community' do
  69 +# community = fast_create(Community)
  70 +# give_permission(person, 'post_content', community)
  71 +# post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"
310 # json = JSON.parse(last_response.body) 72 # json = JSON.parse(last_response.body)
311 -#  
312 -# assert_equal 403, last_response.status 73 +# assert_not_nil json["task"]["id"]
313 # end 74 # end
314 # 75 #
315 -# should 'enterprise: create article defining the correct profile' do  
316 -# enterprise = fast_create(Enterprise)  
317 -# enterprise.add_member(user.person)  
318 -#  
319 -# params[:article] = {:name => "Title"}  
320 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
321 -# json = JSON.parse(last_response.body)  
322 -#  
323 -# assert_equal enterprise, Article.last.profile 76 +# should 'do not create article if user has no permission to post content' do
  77 +#assert false
  78 +## community = fast_create(Community)
  79 +## give_permission(user.person, 'invite_members', community)
  80 +## params[:article] = {:name => "Title"}
  81 +## post "/api/v1/communities/#{community.id}/articles?#{params.to_query}"
  82 +## assert_equal 403, last_response.status
324 # end 83 # end
325 # 84 #
326 -# should 'enterprise: create article defining the created_by' do  
327 -# enterprise = fast_create(Enterprise)  
328 -# enterprise.add_member(user.person) 85 +## should 'create article with parent' do
  86 +## community = fast_create(Community)
  87 +## community.add_member(user.person)
  88 +## article = fast_create(Article)
  89 +##
  90 +## params[:article] = {:name => "Title", :parent_id => article.id}
  91 +## post "/api/v1/communities/#{community.id}/articles?#{params.to_query}"
  92 +## json = JSON.parse(last_response.body)
  93 +## assert_equal article.id, json["article"]["parent"]["id"]
  94 +## end
  95 +#
  96 +# should 'create task defining the requestor as current profile logged in' do
  97 +# community = fast_create(Community)
  98 +# community.add_member(person)
329 # 99 #
330 -# params[:article] = {:name => "Title"}  
331 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}" 100 +# post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"
332 # json = JSON.parse(last_response.body) 101 # json = JSON.parse(last_response.body)
333 # 102 #
334 -# assert_equal user.person, Article.last.created_by 103 +# assert_equal person, Task.last.requestor
335 # end 104 # end
336 # 105 #
337 -# should 'enterprise: create article defining the last_changed_by' do  
338 -# enterprise = fast_create(Enterprise)  
339 -# enterprise.add_member(user.person) 106 +# should 'create task defining the target as the community' do
  107 +# community = fast_create(Community)
  108 +# community.add_member(person)
340 # 109 #
341 -# params[:article] = {:name => "Title"}  
342 -# post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}" 110 +# post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"
343 # json = JSON.parse(last_response.body) 111 # json = JSON.parse(last_response.body)
344 # 112 #
345 -# assert_equal user.person, Article.last.last_changed_by  
346 -# end  
347 -#  
348 -# should 'list article children with partial fields' do  
349 -# article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")  
350 -# child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")  
351 -# params[:fields] = [:title]  
352 -# get "/api/v1/articles/#{article.id}/children?#{params.to_query}"  
353 -# json = JSON.parse(last_response.body)  
354 -# assert_equal ['title'], json['articles'].first.keys  
355 -# end  
356 -#  
357 -# should 'suggest article children' do  
358 -# article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")  
359 -# params[:target_id] = user.person.id  
360 -# params[:article] = {:name => "Article name", :body => "Article body"}  
361 -# assert_difference "SuggestArticle.count" do  
362 -# post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}"  
363 -# end  
364 -# json = JSON.parse(last_response.body)  
365 -# assert_equal 'SuggestArticle', json['type']  
366 -# end  
367 -#  
368 -# should 'suggest event children' do  
369 -# article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")  
370 -# params[:target_id] = user.person.id  
371 -# params[:article] = {:name => "Article name", :body => "Article body", :type => "Event"}  
372 -# assert_difference "SuggestArticle.count" do  
373 -# post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}"  
374 -# end  
375 -# json = JSON.parse(last_response.body)  
376 -# assert_equal 'SuggestArticle', json['type']  
377 -# end  
378 -#  
379 -# should 'update hit attribute of article children' do  
380 -# a1 = fast_create(Article, :profile_id => user.person.id)  
381 -# a2 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)  
382 -# a3 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)  
383 -# get "/api/v1/articles/#{a1.id}/children?#{params.to_query}"  
384 -# json = JSON.parse(last_response.body)  
385 -# assert_equal [1, 1], json['articles'].map { |a| a['hits']}  
386 -# assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits] 113 +# assert_equal community, Task.last.target
387 # end 114 # end
388 # 115 #
  116 +## #############################
  117 +## # Person Articles #
  118 +## #############################
  119 +##
  120 +## should 'return article by person' do
  121 +## person = fast_create(Person)
  122 +## article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
  123 +## get "/api/v1/people/#{person.id}/articles/#{article.id}?#{params.to_query}"
  124 +## json = JSON.parse(last_response.body)
  125 +## assert_equal article.id, json["article"]["id"]
  126 +## end
  127 +##
  128 +## should 'not return article by person if user has no permission to view it' do
  129 +## person = fast_create(Person)
  130 +## article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
  131 +## assert !article.published?
  132 +##
  133 +## get "/api/v1/people/#{person.id}/articles/#{article.id}?#{params.to_query}"
  134 +## assert_equal 403, last_response.status
  135 +## end
  136 +##
  137 +## should 'not list forbidden article when listing articles by person' do
  138 +## person = fast_create(Person)
  139 +## article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
  140 +## assert !article.published?
  141 +## get "/api/v1/people/#{person.id}/articles?#{params.to_query}"
  142 +## json = JSON.parse(last_response.body)
  143 +## assert_not_includes json['articles'].map {|a| a['id']}, article.id
  144 +## end
  145 +##
  146 +## should 'create article in a person' do
  147 +## params[:article] = {:name => "Title"}
  148 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  149 +## json = JSON.parse(last_response.body)
  150 +## assert_equal "Title", json["article"]["title"]
  151 +## end
  152 +##
  153 +## should 'person do not create article if user has no permission to post content' do
  154 +## person = fast_create(Person)
  155 +## params[:article] = {:name => "Title"}
  156 +## post "/api/v1/people/#{person.id}/articles?#{params.to_query}"
  157 +## assert_equal 403, last_response.status
  158 +## end
  159 +##
  160 +## should 'person create article with parent' do
  161 +## article = fast_create(Article)
  162 +##
  163 +## params[:article] = {:name => "Title", :parent_id => article.id}
  164 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  165 +## json = JSON.parse(last_response.body)
  166 +## assert_equal article.id, json["article"]["parent"]["id"]
  167 +## end
  168 +##
  169 +## should 'person create article with content type passed as parameter' do
  170 +## Article.delete_all
  171 +## params[:article] = {:name => "Title"}
  172 +## params[:content_type] = 'TextArticle'
  173 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  174 +## json = JSON.parse(last_response.body)
  175 +##
  176 +## assert_kind_of TextArticle, Article.last
  177 +## end
  178 +##
  179 +## should 'person create article of TinyMceArticle type if no content type is passed as parameter' do
  180 +## params[:article] = {:name => "Title"}
  181 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  182 +## json = JSON.parse(last_response.body)
  183 +##
  184 +## assert_kind_of TinyMceArticle, Article.last
  185 +## end
  186 +##
  187 +## should 'person not create article with invalid article content type' do
  188 +## params[:article] = {:name => "Title"}
  189 +## params[:content_type] = 'Person'
  190 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  191 +## json = JSON.parse(last_response.body)
  192 +##
  193 +## assert_equal 403, last_response.status
  194 +## end
  195 +##
  196 +## should 'person create article defining the correct profile' do
  197 +## params[:article] = {:name => "Title"}
  198 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  199 +## json = JSON.parse(last_response.body)
  200 +##
  201 +## assert_equal user.person, Article.last.profile
  202 +## end
  203 +##
  204 +## should 'person create article defining the created_by' do
  205 +## params[:article] = {:name => "Title"}
  206 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  207 +## json = JSON.parse(last_response.body)
  208 +##
  209 +## assert_equal user.person, Article.last.created_by
  210 +## end
  211 +##
  212 +## should 'person create article defining the last_changed_by' do
  213 +## params[:article] = {:name => "Title"}
  214 +## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"
  215 +## json = JSON.parse(last_response.body)
  216 +##
  217 +## assert_equal user.person, Article.last.last_changed_by
  218 +## end
  219 +##
  220 +## #############################
  221 +## # Enterprise Articles #
  222 +## #############################
  223 +##
  224 +## should 'return article by enterprise' do
  225 +## enterprise = fast_create(Enterprise)
  226 +## article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing")
  227 +## get "/api/v1/enterprises/#{enterprise.id}/articles/#{article.id}?#{params.to_query}"
  228 +## json = JSON.parse(last_response.body)
  229 +## assert_equal article.id, json["article"]["id"]
  230 +## end
  231 +##
  232 +## should 'not return article by enterprise if user has no permission to view it' do
  233 +## enterprise = fast_create(Enterprise)
  234 +## article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing", :published => false)
  235 +## assert !article.published?
  236 +##
  237 +## get "/api/v1/enterprises/#{enterprise.id}/articles/#{article.id}?#{params.to_query}"
  238 +## assert_equal 403, last_response.status
  239 +## end
  240 +##
  241 +## should 'not list forbidden article when listing articles by enterprise' do
  242 +## enterprise = fast_create(Enterprise)
  243 +## article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing", :published => false)
  244 +## assert !article.published?
  245 +##
  246 +## get "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  247 +## json = JSON.parse(last_response.body)
  248 +## assert_not_includes json['articles'].map {|a| a['id']}, article.id
  249 +## end
  250 +##
  251 +## should 'create article in a enterprise' do
  252 +## enterprise = fast_create(Enterprise)
  253 +## give_permission(user.person, 'post_content', enterprise)
  254 +## params[:article] = {:name => "Title"}
  255 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  256 +## json = JSON.parse(last_response.body)
  257 +## assert_equal "Title", json["article"]["title"]
  258 +## end
  259 +##
  260 +## should 'enterprise: do not create article if user has no permission to post content' do
  261 +## enterprise = fast_create(Enterprise)
  262 +## give_permission(user.person, 'invite_members', enterprise)
  263 +## params[:article] = {:name => "Title"}
  264 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  265 +## assert_equal 403, last_response.status
  266 +## end
  267 +##
  268 +## should 'enterprise: create article with parent' do
  269 +## enterprise = fast_create(Enterprise)
  270 +## enterprise.add_member(user.person)
  271 +## article = fast_create(Article)
  272 +##
  273 +## params[:article] = {:name => "Title", :parent_id => article.id}
  274 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  275 +## json = JSON.parse(last_response.body)
  276 +## assert_equal article.id, json["article"]["parent"]["id"]
  277 +## end
  278 +##
  279 +## should 'enterprise: create article with content type passed as parameter' do
  280 +## enterprise = fast_create(Enterprise)
  281 +## enterprise.add_member(user.person)
  282 +##
  283 +## Article.delete_all
  284 +## params[:article] = {:name => "Title"}
  285 +## params[:content_type] = 'TextArticle'
  286 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  287 +## json = JSON.parse(last_response.body)
  288 +##
  289 +## assert_kind_of TextArticle, Article.last
  290 +## end
  291 +##
  292 +## should 'enterprise: create article of TinyMceArticle type if no content type is passed as parameter' do
  293 +## enterprise = fast_create(Enterprise)
  294 +## enterprise.add_member(user.person)
  295 +##
  296 +## params[:article] = {:name => "Title"}
  297 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  298 +## json = JSON.parse(last_response.body)
  299 +##
  300 +## assert_kind_of TinyMceArticle, Article.last
  301 +## end
  302 +##
  303 +## should 'enterprise: not create article with invalid article content type' do
  304 +## enterprise = fast_create(Enterprise)
  305 +## enterprise.add_member(user.person)
  306 +##
  307 +## params[:article] = {:name => "Title"}
  308 +## params[:content_type] = 'Person'
  309 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  310 +## json = JSON.parse(last_response.body)
  311 +##
  312 +## assert_equal 403, last_response.status
  313 +## end
  314 +##
  315 +## should 'enterprise: create article defining the correct profile' do
  316 +## enterprise = fast_create(Enterprise)
  317 +## enterprise.add_member(user.person)
  318 +##
  319 +## params[:article] = {:name => "Title"}
  320 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  321 +## json = JSON.parse(last_response.body)
  322 +##
  323 +## assert_equal enterprise, Article.last.profile
  324 +## end
  325 +##
  326 +## should 'enterprise: create article defining the created_by' do
  327 +## enterprise = fast_create(Enterprise)
  328 +## enterprise.add_member(user.person)
  329 +##
  330 +## params[:article] = {:name => "Title"}
  331 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  332 +## json = JSON.parse(last_response.body)
  333 +##
  334 +## assert_equal user.person, Article.last.created_by
  335 +## end
  336 +##
  337 +## should 'enterprise: create article defining the last_changed_by' do
  338 +## enterprise = fast_create(Enterprise)
  339 +## enterprise.add_member(user.person)
  340 +##
  341 +## params[:article] = {:name => "Title"}
  342 +## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"
  343 +## json = JSON.parse(last_response.body)
  344 +##
  345 +## assert_equal user.person, Article.last.last_changed_by
  346 +## end
  347 +##
  348 +## should 'list article children with partial fields' do
  349 +## article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  350 +## child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")
  351 +## params[:fields] = [:title]
  352 +## get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
  353 +## json = JSON.parse(last_response.body)
  354 +## assert_equal ['title'], json['articles'].first.keys
  355 +## end
  356 +##
  357 +## should 'suggest article children' do
  358 +## article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  359 +## params[:target_id] = user.person.id
  360 +## params[:article] = {:name => "Article name", :body => "Article body"}
  361 +## assert_difference "SuggestArticle.count" do
  362 +## post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}"
  363 +## end
  364 +## json = JSON.parse(last_response.body)
  365 +## assert_equal 'SuggestArticle', json['type']
  366 +## end
  367 +##
  368 +## should 'suggest event children' do
  369 +## article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  370 +## params[:target_id] = user.person.id
  371 +## params[:article] = {:name => "Article name", :body => "Article body", :type => "Event"}
  372 +## assert_difference "SuggestArticle.count" do
  373 +## post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}"
  374 +## end
  375 +## json = JSON.parse(last_response.body)
  376 +## assert_equal 'SuggestArticle', json['type']
  377 +## end
  378 +##
  379 +## should 'update hit attribute of article children' do
  380 +## a1 = fast_create(Article, :profile_id => user.person.id)
  381 +## a2 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)
  382 +## a3 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)
  383 +## get "/api/v1/articles/#{a1.id}/children?#{params.to_query}"
  384 +## json = JSON.parse(last_response.body)
  385 +## assert_equal [1, 1], json['articles'].map { |a| a['hits']}
  386 +## assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits]
  387 +## end
  388 +##
389 end 389 end