hobo 1.3.0.pre19 → 1.3.0.pre20

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 (44) hide show
  1. data/CHANGES.txt +282 -234
  2. data/VERSION +1 -1
  3. data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
  4. data/lib/generators/hobo/assets/templates/dryml-support.js +2 -2
  5. data/lib/generators/hobo/i18n/templates/hobo.it.yml +1 -1
  6. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +64 -64
  7. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
  8. data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
  9. data/lib/generators/hobo/rapid/templates/reset.css +1 -1
  10. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +15 -15
  11. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  12. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
  13. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +15 -14
  14. data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
  15. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +2 -2
  16. data/lib/hobo.rb +1 -0
  17. data/lib/hobo/controller.rb +6 -6
  18. data/lib/hobo/controller/authentication_support.rb +1 -1
  19. data/lib/hobo/controller/model.rb +10 -10
  20. data/lib/hobo/controller/user.rb +6 -6
  21. data/lib/hobo/engine.rb +6 -0
  22. data/lib/hobo/extensions/action_view/translation_helper.rb +20 -0
  23. data/lib/hobo/extensions/active_model/translation.rb +1 -1
  24. data/lib/hobo/extensions/i18n.rb +16 -0
  25. data/lib/hobo/helper.rb +2 -2
  26. data/lib/hobo/helper/translations.rb +61 -80
  27. data/lib/hobo/model/lifecycles/lifecycle.rb +5 -1
  28. data/lib/hobo/model/lifecycles/transition.rb +1 -0
  29. data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
  30. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +2 -2
  31. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +7 -7
  32. data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
  33. data/lib/hobo/rapid/taglibs/rapid_core.dryml +8 -8
  34. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
  35. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +9 -9
  36. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +1 -1
  37. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +0 -17
  38. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -5
  39. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +1 -1
  40. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +6 -6
  41. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
  42. data/test/permissions/test_permissions.rb +103 -103
  43. metadata +15 -14
  44. data/lib/hobo/rapid/taglibs/rapid_translations.dryml +0 -36
@@ -1,13 +1,13 @@
1
- # Notes:
2
- #
1
+ # Notes:
2
+ #
3
3
  # create/update/delete by guest
4
4
  # create/update/delete by non-permitted user
5
5
  # create/update/delete by permitted user
6
- #
6
+ #
7
7
  # All of the above for has-many related records
8
8
  # All of the above for has-many through related records
9
9
  # All of the above for belongs-to related records
10
- #
10
+ #
11
11
  # a permitted user can't create/update/delete any of the above related records without :accessible
12
12
 
13
13
 
@@ -20,13 +20,13 @@ require 'shoulda'
20
20
  Models.init
21
21
 
22
22
  class PermissionsTest < Test::Unit::TestCase
23
-
23
+
24
24
  def assert_create_prevented(*models)
25
25
  counts = models.*.count
26
26
  assert_raises(Hobo::PermissionDeniedError) { yield }
27
27
  assert_equal(counts, models.*.count)
28
28
  end
29
-
29
+
30
30
  def assert_created(*args)
31
31
  expectations = {}
32
32
  args.in_groups_of(2) {|model, expected| expectations[model] = [model.count, expected]}
@@ -37,58 +37,58 @@ class PermissionsTest < Test::Unit::TestCase
37
37
  assert_equal(nums.last, delta, "Expected #{nums.last} #{model.name.pluralize} to be created, but #{delta} were")
38
38
  end
39
39
  end
40
-
40
+
41
41
  def assert_change_prevented(record, field)
42
42
  was = record.send(field)
43
43
  assert_raises(Hobo::PermissionDeniedError) { yield }
44
44
  record.reload
45
45
  assert_equal was, record.send(field)
46
46
  end
47
-
47
+
48
48
  def assert_deleted(record)
49
49
  assert_raises(ActiveRecord::RecordNotFound) { record.class.find(record.id) }
50
50
  end
51
-
52
- def assert_destroy_prevented(*records)
51
+
52
+ def assert_destroy_prevented(*records)
53
53
  assert_raises(Hobo::PermissionDeniedError) { yield }
54
54
  records.each { |record| assert record.class.find(record.id) }
55
55
  end
56
-
57
-
56
+
57
+
58
58
  def existing_recipe(user=nil)
59
59
  user ||= User.new :name => "existing recipe owner"
60
60
  Recipe.create :name => "existing recipe", :user => user
61
61
  end
62
-
62
+
63
63
 
64
64
  context "The permission system" do
65
-
65
+
66
66
  context "with a guest user acting" do
67
67
  setup { @guest = Hobo::Model::Guest.new }
68
-
68
+
69
69
  should "prevent creation of a recipe" do
70
70
  assert_create_prevented(Recipe) { Recipe.user_create! @guest, :name => "test recipe" }
71
71
  end
72
-
72
+
73
73
  should "prevent update of an exiting recipe" do
74
74
  r = existing_recipe
75
75
  assert_change_prevented(r, :name) { r.user_update_attributes!(@guest, :name => "pwned!") }
76
76
  end
77
-
77
+
78
78
  should "prevent deletion of an existing recipe" do
79
79
  r = existing_recipe
80
80
  assert_destroy_prevented(r) { r.user_destroy(@guest) }
81
81
  end
82
-
82
+
83
83
  end
84
-
84
+
85
85
  context "with a regular user acting" do
86
-
87
- setup { @user = User.create! :name => "regular" }
88
-
89
-
86
+
87
+ setup { @user = User.create! :name => "regular" }
88
+
89
+
90
90
  # --- Permitted basic actions --- #
91
-
91
+
92
92
  should "allow creation of a recipe" do
93
93
  assert_created Recipe, 1 do
94
94
  @recipe = Recipe.user_create! @user, :name => "test recipe"
@@ -102,7 +102,7 @@ class PermissionsTest < Test::Unit::TestCase
102
102
  r.reload
103
103
  assert_equal("new name", r.name)
104
104
  end
105
-
105
+
106
106
  should "allow deletion of a recipe (owned by the acting user)" do
107
107
  r = existing_recipe(@user)
108
108
  r.user_destroy(@user)
@@ -115,28 +115,28 @@ class PermissionsTest < Test::Unit::TestCase
115
115
  should "prevent creation of a recipe owned by another user" do
116
116
  assert_create_prevented(Recipe) { Recipe.user_create! @user, :name => "test recipe", :user => User.new }
117
117
  end
118
-
118
+
119
119
  context "on a recipe owned by another user" do
120
120
  setup { @r = existing_recipe(User.create!(:name => "a n other")) }
121
-
121
+
122
122
  should "prevent update" do
123
123
  assert_change_prevented(@r, :name) { @r.user_update_attributes!(@user, :name => "pwned!") }
124
124
  end
125
-
125
+
126
126
  should "prevent deletion" do
127
127
  assert_destroy_prevented(@r) { @r.user_destroy(@user) }
128
128
  end
129
-
129
+
130
130
  end
131
-
132
-
131
+
132
+
133
133
  # --- Prevented actions on has_many related records --- #
134
-
134
+
135
135
  # (sanity check)
136
136
  should "prevent creation of images without a recipe" do
137
137
  assert_create_prevented(Image) { Image.user_create! @user, :name => "test image" }
138
138
  end
139
-
139
+
140
140
  should "prevent creation of images along with a recipe" do # Only paid up users can
141
141
  assert_create_prevented(Recipe, Image) do
142
142
  Recipe.user_create! @user, :name => "test recipe",
@@ -144,7 +144,7 @@ class PermissionsTest < Test::Unit::TestCase
144
144
  '1' => { :name => "image 2" } }
145
145
  end
146
146
  end
147
-
147
+
148
148
  context "on an another's recipe with images" do
149
149
  setup do
150
150
  user = User.create :name => "a n other"
@@ -152,71 +152,71 @@ class PermissionsTest < Test::Unit::TestCase
152
152
  @i1 = @r.images.create(:name => "image 1")
153
153
  @i2 = @r.images.create(:name => "image 2")
154
154
  end
155
-
155
+
156
156
  should "prevent update of those images" do
157
157
  assert_change_prevented(@i1, :name) do
158
158
  @r.user_update_attributes!(@user, :images => { '0' => { :id => @i1.id, :name => "pwned!" } })
159
159
  end
160
160
  end
161
-
161
+
162
162
  should "prevent deletion of those images" do
163
163
  assert_destroy_prevented(@i1, @i2) { @r.user_update_attributes!(@user, :images => { }) }
164
164
  end
165
165
  end
166
-
166
+
167
167
  # Note: permitted actions on has-many associated records are in the paid-up user section
168
168
  # Tis the tyranny of the dominant hiearchy : )
169
-
169
+
170
170
 
171
171
  # --- Permitted actions on has_many :through relationships --- #
172
-
172
+
173
173
  context "" do
174
174
  setup do
175
175
  @c1 = User.create :name => "Collaborator 1"
176
176
  @c2 = User.create :name => "Collaborator 2"
177
177
  end
178
-
178
+
179
179
  should "allow adding collaborators when creating a recipe" do
180
- @r = Recipe.user_create! @user, :name => "my recipe",
180
+ @r = Recipe.user_create! @user, :name => "my recipe",
181
181
  :collaborators => { '0' => "@#{@c1.id}", '1' => "@#{@c2.id}" }
182
182
  assert_equal(@r.collaborators, [@c1, @c2])
183
183
  end
184
-
184
+
185
185
  should "allow adding collaborators to a recipe" do
186
186
  @r = existing_recipe(@user)
187
-
187
+
188
188
  @r.user_update_attributes! @user, :collaborators => { '0' => "@#{@c1.id}", '1' => "@#{@c2.id}" }
189
189
  assert_equal(@r.collaborators, [@c1, @c2])
190
190
  end
191
-
191
+
192
192
  should "allow removing collaborators from a recipe" do
193
193
  @r = existing_recipe(@user)
194
194
  @r.collaborators << @c1
195
- @r.collaborators << @c2
195
+ @r.collaborators << @c2
196
196
  join1, join2 = @r.collaboratorships
197
-
197
+
198
198
  # sanity check
199
199
  @r.reload
200
200
  assert_equal(@r.collaborators.length, 2)
201
201
 
202
202
  @r.user_update_attributes! @user, :collaborators => {}
203
203
  assert_equal(@r.collaborators.length, 0)
204
-
204
+
205
205
  assert_deleted(join1)
206
206
  assert_deleted(join2)
207
207
  end
208
-
209
-
208
+
209
+
210
210
  # --- Prevented actions on has_many :through relationships --- #
211
-
211
+
212
212
  context "on another's recipe" do
213
213
  setup do
214
214
  other_user = User.create :name => "a n other"
215
215
  @r = existing_recipe(other_user)
216
216
  end
217
-
217
+
218
218
  should "prevent adding collaborators" do
219
- assert_create_prevented(Collaboratorship) do
219
+ assert_create_prevented(Collaboratorship) do
220
220
  @r.user_update_attributes! @user, :collaborators => { '0' => "@#{@c1.id}", '1' => "@#{@c2.id}" }
221
221
  end
222
222
  end
@@ -233,45 +233,45 @@ class PermissionsTest < Test::Unit::TestCase
233
233
  end
234
234
  end
235
235
  end
236
-
236
+
237
237
  end
238
-
238
+
239
239
  # --- Permitted actions on a belongs_to related record --- #
240
-
240
+
241
241
  should "allow creation of a code-example along with a recipe" do
242
242
  assert_created(Recipe, 1, CodeExample, 1) do
243
- @r = Recipe.user_create! @user, :name => "recipe with code example",
243
+ @r = Recipe.user_create! @user, :name => "recipe with code example",
244
244
  :code_example => { :filename => "code.zip" }
245
245
  end
246
246
  assert_equal("code.zip", @r.code_example.filename)
247
247
  end
248
-
248
+
249
249
  should "allow creation of a code-example for an existing recipe" do
250
250
  @r = existing_recipe(@user)
251
251
  assert_created(CodeExample, 1) do
252
252
  @r.user_update_attributes! @user, :code_example => { :filename => "code.zip" }
253
253
  end
254
- assert_equal("code.zip", @r.code_example.filename)
254
+ assert_equal("code.zip", @r.code_example.filename)
255
255
  end
256
-
256
+
257
257
  should "allow the code example related to a recipe to be changed" do
258
258
  r = existing_recipe @user
259
259
  c1 = CodeExample.create! :filename => "exmaple1.zip"
260
260
  c2 = CodeExample.create! :filename => "exmaple2.zip"
261
261
  r.code_example = c1
262
262
  r.save
263
-
263
+
264
264
  r.user_update_attributes! @user, :code_example => "@#{c2.id}"
265
-
265
+
266
266
  assert_equal(c2, r.code_example)
267
267
  end
268
-
269
- context "on an existing recipe with a code example" do
268
+
269
+ context "on an existing recipe with a code example" do
270
270
  setup do
271
271
  @ce = CodeExample.create! :filename => "exmaple.zip"
272
272
  @r = Recipe.create :name => "existing recipe", :user => @user, :code_example => @ce
273
273
  end
274
-
274
+
275
275
  should "allow update of the code-example" do
276
276
  # To update the exsting target of a belongs_to association, the id must be included in the hash
277
277
  # It is an error to provide any id other than that of the existing target
@@ -286,12 +286,12 @@ class PermissionsTest < Test::Unit::TestCase
286
286
  assert_nil @r.code_example
287
287
  # Note - the code-example is not deleted from the database
288
288
  end
289
-
289
+
290
290
  end
291
-
292
-
291
+
292
+
293
293
  # --- Prevented actions on a belongs_to related record --- #
294
-
294
+
295
295
  context "on another's recipe" do
296
296
  setup { @r = existing_recipe }
297
297
 
@@ -300,13 +300,13 @@ class PermissionsTest < Test::Unit::TestCase
300
300
  @r.user_update_attributes! @user, :code_example => { :filename => "code.zip" }
301
301
  end
302
302
  end
303
-
303
+
304
304
  context "with a code example" do
305
305
  setup do
306
306
  @ce = @r.code_example = CodeExample.create!(:filename => "exmaple.zip")
307
307
  @r.save
308
308
  end
309
-
309
+
310
310
  should "prevent update of the code-example" do
311
311
  assert_change_prevented(@ce, :filename) do
312
312
  @r.user_update_attributes! @user, :code_example => { :filename => "changed.zip" }
@@ -317,23 +317,23 @@ class PermissionsTest < Test::Unit::TestCase
317
317
  assert_change_prevented(@r, :code_example_id) do
318
318
  @r.user_update_attributes! @user, :code_example => {}
319
319
  end
320
-
320
+
321
321
  end
322
322
  end
323
- end
324
-
323
+ end
324
+
325
325
  # --- Actions on non-accesible has_many associations --- #
326
-
327
- # When associations are not declared :accesssible => true, attemting to update them
326
+
327
+ # When associations are not declared :accesssible => true, attemting to update them
328
328
  # causes a type-mismatch
329
-
329
+
330
330
  should "prevent creation of comments via a recipe" do
331
331
  r = existing_recipe
332
332
  assert_raises(ActiveRecord::AssociationTypeMismatch) do
333
333
  r.user_update_attributes! @user, :comments => { '0' => { :body => "dodgy comment"} }
334
334
  end
335
335
  end
336
-
336
+
337
337
  should "prevent update of comments via their recipe" do
338
338
  r = existing_recipe
339
339
  c = r.comments.create :body => "My nice comment"
@@ -341,26 +341,26 @@ class PermissionsTest < Test::Unit::TestCase
341
341
  r.user_update_attributes! @user, :comments => { '0' => { :id => c.id, :body => "dodgy comment"} }
342
342
  end
343
343
  end
344
-
344
+
345
345
  should "prevent deletion of comments via their recipe" do
346
346
  r = existing_recipe
347
347
  c = r.comments.create :body => "My nice comment"
348
348
  assert_destroy_prevented(c) do
349
349
  r.user_update_attributes! @user, :comments => { }
350
- end
350
+ end
351
351
  end
352
-
353
-
352
+
353
+
354
354
  # --- Actions on non-accessible belongs_to associations --- #
355
-
355
+
356
356
  should "prevent creation of a recipe when creating a comment" do
357
357
  count = Recipe.count
358
- assert_raises(ActiveRecord::AssociationTypeMismatch) do
358
+ assert_raises(ActiveRecord::AssociationTypeMismatch) do
359
359
  Comment.user_create! @user, :body => "my comment", :recipe => { :name => "I created a recipe!" }
360
360
  end
361
361
  assert_equal(count, Recipe.count)
362
362
  end
363
-
363
+
364
364
  should "prevent update of a recipe via one of its comments" do
365
365
  r = existing_recipe
366
366
  c = r.comments.create :body => "My comment"
@@ -369,7 +369,7 @@ class PermissionsTest < Test::Unit::TestCase
369
369
  end
370
370
  assert_equal("existing recipe", r.name)
371
371
  end
372
-
372
+
373
373
  should "prevent deletion of a recipe via one of its comments" do
374
374
  r = existing_recipe
375
375
  c = r.comments.create :body => "My comment"
@@ -378,20 +378,20 @@ class PermissionsTest < Test::Unit::TestCase
378
378
  end
379
379
  assert Recipe.find(r.id)
380
380
  end
381
-
381
+
382
382
  end
383
-
383
+
384
384
  context "with a paid up user acting" do
385
385
  setup { @user = User.create! :name => "paid up user", :paid_up => true }
386
-
386
+
387
387
  should "prevent direct creation of images" do # images must belong to a recipe
388
388
  assert_create_prevented(Image) { Image.user_create! @user, :name => "test image" }
389
389
  end
390
-
390
+
391
391
  # --- Permitted actions on has_many related records --- #
392
-
392
+
393
393
  should "allow creation of images along with a recipe" do
394
-
394
+
395
395
  assert_created Recipe, 1, Image, 2 do
396
396
  @recipe = Recipe.user_create! @user, :images => { '0' => { :name => "image 1" },
397
397
  '1' => { :name => "image 2" } }
@@ -406,14 +406,14 @@ class PermissionsTest < Test::Unit::TestCase
406
406
  end
407
407
 
408
408
  end
409
-
409
+
410
410
  context "on an existing recipe with images" do
411
411
  setup do
412
412
  @recipe = Recipe.create! :name => "recipe with images", :user => @user
413
413
  @i1 = @recipe.images.create! :name => "image 1"
414
414
  @i2 = @recipe.images.create! :name => "image 2"
415
- end
416
-
415
+ end
416
+
417
417
  should "allow creation of images when updating a recipe" do
418
418
  @recipe.user_update_attributes! @user, :images => { '0' => { :id => @i1.id },
419
419
  '1' => { :id => @i2.id },
@@ -424,7 +424,7 @@ class PermissionsTest < Test::Unit::TestCase
424
424
  assert_equal("image 2", Image.find(@i2.id).name)
425
425
  assert_equal("new image", @recipe.images[2].name)
426
426
  end
427
-
427
+
428
428
  should "allow updates to images when updating a recipe" do
429
429
  @recipe.user_update_attributes! @user, :images => { '0' => { :id => @i1.id, :name => "new name" },
430
430
  '1' => { :id => @i2.id } }
@@ -433,19 +433,19 @@ class PermissionsTest < Test::Unit::TestCase
433
433
  assert_equal("new name", Image.find(@i1.id).name)
434
434
  assert_equal("new name", @recipe.images[0].name)
435
435
  end
436
-
436
+
437
437
  should "allow deletion of images when updating a recipe" do
438
438
  @recipe.user_update_attributes! @user, :images => { '0' => { :id => @i1.id } }
439
439
  @recipe.reload
440
440
  assert_equal(1, @recipe.images.length)
441
441
  assert_deleted(@i2)
442
442
  end
443
-
443
+
444
444
  end
445
-
446
-
445
+
446
+
447
447
  end
448
-
449
- end
450
-
451
- end
448
+
449
+ end
450
+
451
+ end