typus 3.0.11 → 3.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/README.md +4 -1
  2. data/app/helpers/admin/relationships_helper.rb +2 -2
  3. data/app/views/admin/dashboard/_applications.html.erb +1 -1
  4. data/app/views/admin/helpers/resources/_errors.html.erb +1 -1
  5. data/app/views/admin/helpers/sidebar/_sidebar.html.erb +1 -1
  6. data/app/views/admin/resources/index.html.erb +2 -2
  7. data/app/views/admin/templates/_has_n.html.erb +1 -1
  8. data/app/views/admin/templates/_has_one.html.erb +1 -1
  9. data/config/locales/typus.ca.yml +1 -1
  10. data/config/locales/typus.de.models.yml +6 -5
  11. data/config/locales/typus.de.yml +39 -36
  12. data/config/locales/typus.el.yml +1 -1
  13. data/config/locales/typus.es.yml +1 -1
  14. data/config/locales/typus.fr.yml +1 -1
  15. data/config/locales/typus.hu.yml +1 -1
  16. data/config/locales/typus.locale.yml.template +1 -1
  17. data/config/locales/typus.pt-BR.yml +1 -1
  18. data/config/locales/typus.pt-PT.yml +1 -1
  19. data/config/locales/typus.ru.yml +1 -1
  20. data/config/locales/typus.zh-CN.yml +1 -1
  21. data/lib/typus/version.rb +1 -1
  22. data/typus.gemspec +7 -4
  23. metadata +16 -164
  24. data/test/app/controllers/admin/account_controller_test.rb +0 -106
  25. data/test/app/controllers/admin/assets_controller_test.rb +0 -156
  26. data/test/app/controllers/admin/base_controller_test.rb +0 -41
  27. data/test/app/controllers/admin/birds_controller_test.rb +0 -42
  28. data/test/app/controllers/admin/cases_controller_test.rb +0 -21
  29. data/test/app/controllers/admin/categories_controller_test.rb +0 -134
  30. data/test/app/controllers/admin/comments_controller_test.rb +0 -79
  31. data/test/app/controllers/admin/dashboard_controller_test.rb +0 -162
  32. data/test/app/controllers/admin/image_holders_controller_test.rb +0 -75
  33. data/test/app/controllers/admin/invoices_controller_test.rb +0 -78
  34. data/test/app/controllers/admin/orders_controller_test.rb +0 -18
  35. data/test/app/controllers/admin/pages_controller_test.rb +0 -37
  36. data/test/app/controllers/admin/posts_controller_test.rb +0 -770
  37. data/test/app/controllers/admin/projects_controller_test.rb +0 -52
  38. data/test/app/controllers/admin/session_controller_test.rb +0 -92
  39. data/test/app/controllers/admin/status_controller_test.rb +0 -54
  40. data/test/app/controllers/admin/typus_users_controller_test.rb +0 -156
  41. data/test/app/controllers/admin/users_controller_test.rb +0 -106
  42. data/test/app/controllers/admin/views_controller_test.rb +0 -36
  43. data/test/app/helpers/admin/base_helper_test.rb +0 -83
  44. data/test/app/helpers/admin/dashboard_helper_test.rb +0 -32
  45. data/test/app/helpers/admin/file_preview_helper_test.rb +0 -90
  46. data/test/app/helpers/admin/filters_helper_test.rb +0 -166
  47. data/test/app/helpers/admin/form_helper_test.rb +0 -126
  48. data/test/app/helpers/admin/list_helper_test.rb +0 -76
  49. data/test/app/helpers/admin/relationships_helper_test.rb +0 -19
  50. data/test/app/helpers/admin/resources_helper_test.rb +0 -46
  51. data/test/app/helpers/admin/search_helper_test.rb +0 -60
  52. data/test/app/helpers/admin/sidebar_helper_test.rb +0 -34
  53. data/test/app/helpers/admin/table_helper_test.rb +0 -241
  54. data/test/app/mailers/admin/mailer_test.rb +0 -32
  55. data/test/app/models/admin_user_test.rb +0 -5
  56. data/test/app/models/typus_user_roles_test.rb +0 -125
  57. data/test/app/models/typus_user_test.rb +0 -228
  58. data/test/config/routes_test.rb +0 -29
  59. data/test/factories.rb +0 -122
  60. data/test/fixtures/config/broken/application.yml +0 -68
  61. data/test/fixtures/config/broken/application_roles.yml +0 -20
  62. data/test/fixtures/config/broken/empty.yml +0 -0
  63. data/test/fixtures/config/broken/empty_roles.yml +0 -0
  64. data/test/fixtures/config/broken/undefined.yml +0 -3
  65. data/test/fixtures/config/broken/undefined_roles.yml +0 -6
  66. data/test/fixtures/config/default/typus.yml +0 -13
  67. data/test/fixtures/config/default/typus_roles.yml +0 -2
  68. data/test/fixtures/config/empty/empty_01.yml +0 -0
  69. data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
  70. data/test/fixtures/config/empty/empty_02.yml +0 -0
  71. data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
  72. data/test/fixtures/config/locales/es.yml +0 -10
  73. data/test/fixtures/config/namespaced/application.yml +0 -5
  74. data/test/fixtures/config/namespaced/application_roles.yml +0 -2
  75. data/test/fixtures/config/ordered/001_roles.yml +0 -2
  76. data/test/fixtures/config/ordered/002_roles.yml +0 -2
  77. data/test/fixtures/config/unordered/app_one_roles.yml +0 -2
  78. data/test/fixtures/config/unordered/app_two_roles.yml +0 -2
  79. data/test/lib/support/active_record_test.rb +0 -174
  80. data/test/lib/support/fake_user_test.rb +0 -63
  81. data/test/lib/support/hash_test.rb +0 -29
  82. data/test/lib/support/object_test.rb +0 -17
  83. data/test/lib/support/string_test.rb +0 -98
  84. data/test/lib/typus/configuration_test.rb +0 -46
  85. data/test/lib/typus/controller/actions_test.rb +0 -141
  86. data/test/lib/typus/controller/associations_test.rb +0 -7
  87. data/test/lib/typus/controller/autocomplete_test.rb +0 -7
  88. data/test/lib/typus/controller/filters_test.rb +0 -73
  89. data/test/lib/typus/controller/format_test.rb +0 -7
  90. data/test/lib/typus/i18n_test.rb +0 -9
  91. data/test/lib/typus/orm/active_record/class_methods_test.rb +0 -390
  92. data/test/lib/typus/orm/active_record/search_test.rb +0 -330
  93. data/test/lib/typus/regex_test.rb +0 -53
  94. data/test/lib/typus/resources_test.rb +0 -41
  95. data/test/lib/typus_test.rb +0 -142
  96. data/test/test_helper.rb +0 -15
@@ -1,770 +0,0 @@
1
- require "test_helper"
2
-
3
- =begin
4
-
5
- What's being tested here?
6
-
7
- - CRUD: Create, read, update, destroy
8
- - CRUD Extras: toggle
9
- - Filters
10
- - Forms
11
- - Overrides
12
- - Permissions
13
- - Roles
14
- - Views
15
-
16
- =end
17
-
18
- class Admin::PostsControllerTest < ActionController::TestCase
19
-
20
- setup do
21
- @typus_user = Factory(:typus_user)
22
- @request.session[:typus_user_id] = @typus_user.id
23
- @post = Factory(:post)
24
- end
25
-
26
- teardown do
27
- Post.delete_all
28
- TypusUser.delete_all
29
- end
30
-
31
- ##############################################################################
32
- #
33
- ##############################################################################
34
-
35
- context "CRUD" do
36
-
37
- should "render index" do
38
- get :index
39
- assert_response :success
40
- assert_template 'index'
41
- end
42
-
43
- context "new" do
44
-
45
- should "render" do
46
- get :new
47
- assert_response :success
48
- assert_template 'new'
49
- end
50
-
51
- should "reject params which are not included in @resource.columns.map(&:name)" do
52
- %w(chunky_bacon).each do |param|
53
- get :new, {param => param}
54
- assert_response :success
55
- assert_template 'new'
56
- end
57
- end
58
-
59
- end
60
-
61
- should "create" do
62
- assert_difference('Post.count') do
63
- post :create, :post => @post.attributes
64
- assert_response :redirect
65
- assert_redirected_to "/admin/posts/edit/#{Post.last.id}"
66
- end
67
- end
68
-
69
- should "render show" do
70
- get :show, :id => @post.id
71
- assert_response :success
72
- assert_template 'show'
73
- end
74
-
75
- should "render edit" do
76
- get :edit, :id => @post.id
77
- assert_response :success
78
- assert_template 'edit'
79
- end
80
-
81
- should "update" do
82
- post :update, :id => @post.id, :post => { :title => 'Updated' }
83
- assert_response :redirect
84
- assert_redirected_to "/admin/posts/edit/#{@post.id}"
85
- end
86
-
87
- end
88
-
89
- context "CRUD extras" do
90
-
91
- setup do
92
- @request.env['HTTP_REFERER'] = "/admin/posts"
93
- end
94
-
95
- context "toggle" do
96
-
97
- should "work" do
98
- assert !@post.published
99
- get :toggle, :id => @post.id, :field => "published"
100
-
101
- assert_response :redirect
102
- assert_redirected_to @request.env["HTTP_REFERER"]
103
- assert_equal "Post successfully updated.", flash[:notice]
104
- assert @post.reload.published
105
- end
106
-
107
- should "render edit post when validation fails" do
108
- @post.body = nil
109
- @post.save(:validate => false)
110
- get :toggle, :id => @post.id, :field => "published"
111
- assert_response :success
112
- assert_template "admin/resources/edit"
113
- end
114
-
115
- end
116
-
117
- end
118
-
119
- context "Filters" do
120
-
121
- should "render index with accepted params" do
122
- @post.update_attributes(:published => true)
123
- get :index, :published => 'true'
124
- assert_response :success
125
- assert_template 'index'
126
- assert assigns(:items).size.eql?(1)
127
-
128
- get :index, :published => 'false'
129
- assert assigns(:items).size.eql?(0)
130
- end
131
-
132
- should "render index with accepted params - search" do
133
- @post.update_attributes(:title => "neinonon")
134
- get :index, :search => 'neinonon'
135
- assert_response :success
136
- assert_template 'index'
137
- assert assigns(:items).size.eql?(1)
138
-
139
- get :index, :search => 'unexisting'
140
- assert assigns(:items).size.eql?(0)
141
- end
142
-
143
- should "render index with non-accepted params" do
144
- get :index, :non_accepted_param => 'non_accepted_param'
145
- assert_response :success
146
- assert_template 'index'
147
- end
148
-
149
- end
150
-
151
- context "Filters" do
152
-
153
- should "be included in index" do
154
- get :index
155
- assert assigns(:predefined_filters).nil?
156
- end
157
-
158
- end
159
-
160
- context "Actions" do
161
-
162
- should "be edit and trash on index" do
163
- get :index
164
-
165
- expected = [["Edit", {"action"=>"edit"}, {}],
166
- ["Trash", {"action"=>"destroy"}, {"method"=>"delete", "confirm"=>"Trash?"}]]
167
-
168
- assert_equal expected, assigns(:resource_actions)
169
- end
170
-
171
- context "with overriden default action on item" do
172
-
173
- setup do
174
- Typus::Resources.expects(:default_action_on_item).at_least_once.returns('show')
175
- end
176
-
177
- should "be show and trash on index" do
178
- get :index
179
-
180
- expected = [["Show", {"action"=>"show"}, {}],
181
- ["Trash", {"action"=>"destroy"}, {"method"=>"delete", "confirm"=>"Trash?"}]]
182
-
183
- assert_equal expected, assigns(:resource_actions)
184
- end
185
-
186
- end
187
-
188
- end
189
-
190
- context "Forms" do
191
-
192
- setup do
193
- get :new
194
- end
195
-
196
- should "verify forms" do
197
- assert_select "form"
198
- end
199
-
200
- # We have 3 inputs: 1 hidden which is the UTF8 stuff, one which is the
201
- # Post#title and finally the submit button.
202
- should "have 3 inputs" do
203
- assert_select "form input", 3
204
-
205
- # Post#title: Input
206
- assert_select 'label[for="post_title"]'
207
- assert_select 'input#post_title[type="text"]'
208
- end
209
-
210
- should "have 1 textarea" do
211
- assert_select "form textarea", 1
212
-
213
- # Post#body: Text Area
214
- assert_select 'label[for="post_body"]'
215
- assert_select 'textarea#post_body'
216
- end
217
-
218
- should "have 6 selectors" do
219
- assert_select "form select", 6
220
-
221
- # Post#created_at: Datetime
222
- assert_select 'label[for="post_created_at"]'
223
- assert_select 'select#post_created_at_1i'
224
- assert_select 'select#post_created_at_2i'
225
- assert_select 'select#post_created_at_3i'
226
- assert_select 'select#post_created_at_4i'
227
- assert_select 'select#post_created_at_5i'
228
-
229
- # Post#status: Selector
230
- assert_select 'label[for="post_status"]'
231
- assert_select 'select#post_status'
232
- end
233
-
234
- should "have 1 template" do
235
- assert_match "templates#datepicker_template_published_at", @response.body
236
- end
237
-
238
- end
239
-
240
- context "Overwrite action_after_save" do
241
-
242
- setup do
243
- Typus::Resources.expects(:action_after_save).returns("index")
244
- @post = Factory(:post)
245
- end
246
-
247
- should "create an item and redirect to index" do
248
- assert_difference('Post.count') do
249
- post :create, :post => @post.attributes
250
- assert_response :redirect
251
- assert_redirected_to :action => 'index'
252
- end
253
- end
254
-
255
- should "update an item and redirect to index" do
256
- post :update, :id => @post.id, :post => { :title => 'Updated' }
257
- assert_response :redirect
258
- assert_redirected_to :action => 'index'
259
- end
260
-
261
- end
262
-
263
- context "Formats" do
264
-
265
- should "render index and return xml" do
266
- get :index, :format => "xml"
267
-
268
- assert_response :success
269
-
270
- assert_match %Q[<?xml version="1.0" encoding="UTF-8"?>], @response.body
271
- assert_match %Q[<posts type="array">], @response.body
272
- assert_match "<status>#{@post.status}</status>", @response.body
273
- assert_match "<title>#{@post.title}</title>", @response.body
274
- end
275
-
276
- should "render index and return csv" do
277
- expected = <<-RAW
278
- title;status
279
- #{@post.title};#{@post.status}
280
- RAW
281
-
282
- get :index, :format => "csv"
283
-
284
- assert_response :success
285
- assert_equal expected, @response.body
286
- end
287
-
288
- should "not instantiate resource_actions" do
289
- get :index, :format => "xml"
290
- assert assigns(:resource_actions).nil?
291
- end
292
-
293
- should "not instantiate predefined_filters" do
294
- get :index, :format => "xml"
295
- assert assigns(:predefined_filters).nil?
296
- end
297
-
298
- end
299
-
300
- context "Permissions" do
301
-
302
- context "Root" do
303
-
304
- setup do
305
- @editor = Factory(:typus_user, :email => "editor@example.com", :role => "editor")
306
- @post = Factory(:post, :typus_user => @editor)
307
- end
308
-
309
- should "should list all posts no matter who is the owner" do
310
- Post.delete_all
311
- admin = TypusUser.where(:role => 'admin').first
312
- 2.times { Factory(:post, :typus_user => @editor) }
313
- 2.times { Factory(:post, :typus_user => @typus_user) }
314
- Typus::Resources.expects(:only_user_items).returns(true)
315
-
316
- get :index
317
-
318
- assert_equal 4, Post.count
319
- assert_equal 4, assigns(:items).size
320
- assert_equal [@editor.id, @editor.id, @typus_user.id, @typus_user.id], assigns(:items).map(&:typus_user_id)
321
- end
322
-
323
- should "be able to edit any record" do
324
- Post.all.each do |post|
325
- get :edit, :id => post.id
326
- assert_response :success
327
- assert_template 'edit'
328
- end
329
- end
330
-
331
- should "verify_admin_updating_an_item_does_not_change_typus_user_id_if_not_defined" do
332
- _post = @post
333
- post :update, :id => @post.id, :post => { :title => 'Updated by admin' }
334
- assert_equal _post.typus_user_id, @post.reload.typus_user_id
335
- end
336
-
337
- should "verify_admin_updating_an_item_does_change_typus_user_id_to_whatever_admin_wants" do
338
- post :update, :id => @post.id, :post => { :title => 'Updated', :typus_user_id => 108 }
339
- assert_equal 108, @post.reload.typus_user_id
340
- end
341
-
342
- end
343
-
344
- context "No root" do
345
-
346
- setup do
347
- @typus_user = Factory(:typus_user, :email => "editor@example.com", :role => "editor")
348
- @request.session[:typus_user_id] = @typus_user.id
349
- @request.env['HTTP_REFERER'] = '/admin/posts'
350
- end
351
-
352
- should "not be root" do
353
- assert @typus_user.is_not_root?
354
- end
355
-
356
- should "verify_editor_can_show_any_record" do
357
- Post.all.each do |post|
358
- get :show, :id => post.id
359
- assert_response :success
360
- assert_template 'show'
361
- end
362
- end
363
-
364
- should "verify_editor_tried_to_edit_a_post_owned_by_himself" do
365
- get :edit, :id => Factory(:post, :typus_user => @typus_user).id
366
- assert_response :success
367
- end
368
-
369
- should "verify_editor_tries_to_edit_a_post_owned_by_the_admin" do
370
- get :edit, :id => Factory(:post).id
371
- assert_response :unprocessable_entity
372
- end
373
-
374
- should "verify_editor_tries_to_show_a_post_owned_by_the_admin" do
375
- get :show, :id => Factory(:post).id
376
- assert_response :success
377
- end
378
-
379
- should "only list editor posts" do
380
- Post.delete_all
381
- admin = TypusUser.where(:role => 'admin').first
382
- 2.times { Factory(:post, :typus_user => admin) }
383
- 2.times { Factory(:post, :typus_user => @typus_user) }
384
- Typus::Resources.expects(:only_user_items).returns(true)
385
-
386
- get :index
387
-
388
- assert_equal 4, Post.count
389
- assert_equal 2, assigns(:items).size
390
- assert_equal [@typus_user.id, @typus_user.id], assigns(:items).map(&:typus_user_id)
391
- end
392
-
393
- should "verify_editor_tries_to_show_a_post_owned_by_the_admin when only user items" do
394
- Typus::Resources.expects(:only_user_items).returns(true)
395
- post = Factory(:post)
396
- get :show, :id => post.id
397
- assert_response :unprocessable_entity
398
- end
399
-
400
- should "verify_typus_user_id_of_item_when_creating_record" do
401
- assert_difference('Post.count') do
402
- post :create, :post => { :title => "Chunky Bacon", :body => "Lorem ipsum ..." }
403
- end
404
-
405
- assert_equal @request.session[:typus_user_id], assigns(:item).typus_user_id
406
- end
407
-
408
- should "verify_editor_updating_an_item_does_not_change_typus_user_id" do
409
- [ 108, nil ].each do |typus_user_id|
410
- post_ = Factory(:post, :typus_user => @typus_user)
411
- post :update, :id => post_.id, :post => { :title => 'Updated', :typus_user_id => @typus_user.id }
412
- post_updated = Post.find(post_.id)
413
- assert_equal @request.session[:typus_user_id], post_updated.typus_user_id
414
- end
415
- end
416
-
417
- end
418
-
419
- end
420
-
421
- context "Roles" do
422
-
423
- setup do
424
- @request.env['HTTP_REFERER'] = '/admin/posts'
425
- end
426
-
427
- context "Admin" do
428
-
429
- should "be able to add posts" do
430
- assert @typus_user.can?("create", "Post")
431
- end
432
-
433
- should "be able to destroy posts" do
434
- get :destroy, :id => Factory(:post).id, :method => :delete
435
-
436
- assert_response :redirect
437
- assert_equal "Post successfully removed.", flash[:notice]
438
- assert_redirected_to :action => :index
439
- end
440
-
441
- end
442
-
443
- context "Designer" do
444
-
445
- setup do
446
- Typus.user_class.delete_all
447
- @designer = Factory(:typus_user, :role => "designer")
448
- @request.session[:typus_user_id] = @designer.id
449
- @post = Factory(:post)
450
- end
451
-
452
- should "not be able to add posts" do
453
- get :new
454
-
455
- assert_response :unprocessable_entity
456
- end
457
-
458
- should "not be able to destroy posts" do
459
- assert_no_difference('Post.count') do
460
- get :destroy, :id => @post.id, :method => :delete
461
- end
462
- assert_response :unprocessable_entity
463
- end
464
-
465
- end
466
-
467
- end
468
-
469
- context "Relationships (relate)" do
470
-
471
- setup do
472
- @post = Factory(:post)
473
- end
474
-
475
- should "relate comment to post (has_many)" do
476
- comment = Factory(:comment, :post => nil)
477
- @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
478
-
479
- assert_difference('@post.comments.count') do
480
- post :relate, { :id => @post.id, :related => { :model => 'Comment', :id => comment.id, :association_name => 'comments' } }
481
- end
482
-
483
- assert_response :redirect
484
- assert_redirected_to @request.env['HTTP_REFERER']
485
- assert_equal "Post successfully updated.", flash[:notice]
486
- end
487
-
488
- should "return a message instead a 404 error if related_id is empty" do
489
- comment = Factory(:comment, :post => nil)
490
- @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
491
-
492
- assert_no_difference('@post.comments.count') do
493
- post :relate, { :id => @post.id, :related => { :model => 'Comment', :id => "", :association_name => 'comments' } }
494
- end
495
-
496
- assert_response :redirect
497
- assert_redirected_to @request.env['HTTP_REFERER']
498
- assert_equal "Please, select an option.", flash[:notice]
499
- end
500
-
501
- should "return a message instead a 404 error if related_id is nil" do
502
- comment = Factory(:comment, :post => nil)
503
- @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
504
-
505
- assert_no_difference('@post.comments.count') do
506
- post :relate, { :id => @post.id, :related => { :model => 'Comment', :id => nil, :association_name => 'comments' } }
507
- end
508
-
509
- assert_response :redirect
510
- assert_redirected_to @request.env['HTTP_REFERER']
511
- assert_equal "Please, select an option.", flash[:notice]
512
- end
513
-
514
- should "relate category to post (has_and_belongs_to_many)" do
515
- category = Factory(:category)
516
- @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#categories"
517
-
518
- assert_difference('category.posts.count') do
519
- post :relate, { :id => @post.id, :related => { :model => 'Category', :id => category.id, :association_name => 'categories' } }
520
- end
521
-
522
- assert_response :redirect
523
- assert_redirected_to @request.env['HTTP_REFERER']
524
- assert_equal "Post successfully updated.", flash[:notice]
525
- end
526
-
527
- end
528
-
529
- context "Views" do
530
-
531
- context "Index" do
532
-
533
- setup do
534
- get :index
535
- end
536
-
537
- should "render index and validates_presence_of_custom_partials" do
538
- assert_match "posts#_index.html.erb", @response.body
539
- end
540
-
541
- should "render_index_and_verify_page_title" do
542
- assert_select "title", "Typus &mdash; Posts"
543
- end
544
-
545
- should "render index_and_show_add_entry_link" do
546
- assert_select "#sidebar ul" do
547
- assert_select "li", "Add new"
548
- end
549
- end
550
-
551
- end
552
-
553
- context "New" do
554
-
555
- setup do
556
- get :new
557
- end
558
-
559
- should "render new and partials_on_new" do
560
- assert_match "posts#_new.html.erb", @response.body
561
- end
562
-
563
- should "render new and verify page title" do
564
- assert_select "title", "Typus &mdash; New Post"
565
- end
566
-
567
- end
568
-
569
- context "Edit" do
570
-
571
- setup do
572
- get :edit, :id => Factory(:post).id
573
- end
574
-
575
- should "render_edit_and_verify_presence_of_custom_partials" do
576
- assert_match "posts#_edit.html.erb", @response.body
577
- end
578
-
579
- should "render_edit_and_verify_page_title" do
580
- assert_select "title", "Typus &mdash; Edit Post"
581
- end
582
-
583
- end
584
-
585
- context "Show" do
586
-
587
- setup do
588
- get :show, :id => Factory(:post).id
589
- end
590
-
591
- should "render_show_and_verify_presence_of_custom_partials" do
592
- assert_match "posts#_show.html.erb", @response.body
593
- end
594
-
595
- should "render show and verify page title" do
596
- assert_select "title", "Typus &mdash; Show Post"
597
- end
598
-
599
- end
600
-
601
- should "get_index_and_render_edit_or_show_links" do
602
- %w(edit show).each do |action|
603
- Typus::Resources.expects(:default_action_on_item).at_least_once.returns(action)
604
- get :index
605
- Post.all.each do |post|
606
- assert_match "/posts/#{action}/#{post.id}", @response.body
607
- end
608
- end
609
- end
610
-
611
- context "Designer" do
612
-
613
- setup do
614
- @typus_user = Factory(:typus_user, :email => "designer@example.com", :role => "designer")
615
- @request.session[:typus_user_id] = @typus_user.id
616
- end
617
-
618
- should "render_index_and_not_show_add_entry_link" do
619
- get :index
620
- assert_response :success
621
- assert_no_match /Add Post/, @response.body
622
- end
623
-
624
- end
625
-
626
- context "Editor" do
627
-
628
- setup do
629
- @typus_user = Factory(:typus_user, :email => "editor@example.com", :role => "editor")
630
- @request.session[:typus_user_id] = @typus_user.id
631
- end
632
-
633
- =begin
634
-
635
- ##
636
- # This feature is no longer available. I've to decide if I want to take
637
- # it back.
638
- #
639
- should "get_index_and_render_edit_or_show_links_on_owned_records" do
640
- get :index
641
- Post.all.each do |post|
642
- action = post.owned_by?(@typus_user) ? "edit" : "show"
643
- assert_match "/posts/#{action}/#{post.id}", @response.body
644
- end
645
- end
646
-
647
- =end
648
-
649
- should "get_index_and_render_edit_or_show_on_only_user_items" do
650
- %w(edit show).each do |action|
651
- Typus::Resources.stubs(:only_user_items).returns(true)
652
- Typus::Resources.stubs(:default_action_on_item).returns(action)
653
- get :index
654
- Post.all.each do |post|
655
- if @typus_user.owns?(post)
656
- assert_match "/posts/#{action}/#{post.id}", @response.body
657
- else
658
- assert_no_match /\/posts\/#{action}\/#{post.id}/, @response.body
659
- end
660
- end
661
- end
662
- end
663
-
664
- end
665
-
666
- end
667
-
668
- ##
669
- # We are in a View and we want to create a new Post from there to be able
670
- # to assign it. There are two cases:
671
- #
672
- # - We are creating the view.
673
- # - We are editing the view.
674
- #
675
- context "create_with_back_to" do
676
-
677
- setup do
678
- @post = { :title => 'This is another title', :body => 'Body' }
679
- end
680
-
681
- context "when creating an item" do
682
-
683
- ##
684
- # We click on the "Add new" link and we are redirected to:
685
- #
686
- # /admin/posts/new
687
- #
688
- # With a collection of params which will be used to create the
689
- # association if everything works as expected.
690
- #
691
- # Once the association is created we are redirected back to where we
692
- # started with a param which selects the Post on the View form.
693
- #
694
- # /admin/views/new?post_id=1
695
- #
696
- # So we end up having a new Post and if we save the form will be
697
- # assigned to the view.
698
- #
699
-
700
- should "create new post and redirect to view" do
701
- assert_difference('Post.count') do
702
- post :create, { :post => @post,
703
- :resource => "View" }
704
- end
705
- assert_response :redirect
706
- assert_redirected_to "/admin/views/new?post_id=#{Post.last.id}"
707
- end
708
-
709
- end
710
-
711
- context "when editing an item" do
712
-
713
- ##
714
- # We click on the "Add new" link and we are redirected to:
715
- #
716
- # /admin/posts/new
717
- #
718
- # The important thing here is that we are passing the `resource_id`
719
- # because we will assign the newly created Post to the View.
720
- #
721
- # So we will end up having a new Post assigned to the View.
722
- #
723
-
724
- setup do
725
- @view = Factory(:view, :post => nil)
726
- end
727
-
728
- should "create new post and redirect to view" do
729
- assert_difference('Post.count') do
730
- post :create, { :post => @post, :resource => "View", :resource_id => @view.id }
731
- end
732
- assert_response :redirect
733
- assert_redirected_to "/admin/views/edit/#{@view.id}"
734
-
735
- # Make sure the association is created!
736
- assert @view.reload.post
737
- end
738
-
739
- end
740
-
741
- end
742
-
743
- context "autocomplete" do
744
-
745
- setup do
746
- 25.times { Factory(:post) }
747
- end
748
-
749
- should "work and return a json hash with ten items" do
750
- get :autocomplete, { :term => "Post" }
751
- assert_response :success
752
- assert_equal 20, assigns(:items).size
753
- end
754
-
755
- should "work and return json hash with one item" do
756
- post = Post.first
757
- post.update_attributes(:title => "fesplugas")
758
-
759
- get :autocomplete, { :term => "jmeiss" }
760
- assert_response :success
761
- assert_equal 0, assigns(:items).size
762
-
763
- get :autocomplete, { :term => "fesplugas" }
764
- assert_response :success
765
- assert_equal 1, assigns(:items).size
766
- end
767
-
768
- end
769
-
770
- end