hobo 1.3.0.RC4 → 1.3.0.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/CHANGES.txt +234 -282
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/app/controllers/dev_controller.rb +2 -2
  5. data/bin/hobo +3 -3
  6. data/config/routes.rb +1 -1
  7. data/doctests/hobo/lifecycles.rdoctest +1 -0
  8. data/doctests/hobo/model.rdoctest +5 -0
  9. data/doctests/hobo/multi_model_forms.rdoctest +5 -4
  10. data/doctests/hobo/scopes.rdoctest +8 -11
  11. data/doctests/prepare_testapp.rb +1 -2
  12. data/hobo.gemspec +2 -2
  13. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
  14. data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
  15. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
  16. data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
  17. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
  18. data/lib/generators/hobo/basic/basic_generator.rb +17 -0
  19. data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
  20. data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
  21. data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
  22. data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
  23. data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
  24. data/lib/generators/hobo/controller.rb +1 -6
  25. data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
  26. data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
  27. data/lib/generators/hobo/hints/hints_generator.rb +12 -0
  28. data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
  29. data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
  30. data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
  31. data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
  32. data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
  33. data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
  34. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
  35. data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
  36. data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
  37. data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
  38. data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
  39. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
  40. data/lib/generators/hobo/model.rb +13 -0
  41. data/lib/generators/hobo/model/USAGE +3 -2
  42. data/lib/generators/hobo/model/model_generator.rb +1 -2
  43. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
  44. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
  45. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
  46. data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
  47. data/lib/generators/hobo/rapid/templates/reset.css +1 -1
  48. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
  49. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  50. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
  51. data/lib/generators/hobo/resource/resource_generator.rb +1 -1
  52. data/lib/generators/hobo/routes/router.rb +4 -4
  53. data/lib/generators/hobo/routes/routes_generator.rb +1 -12
  54. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
  55. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
  56. data/lib/generators/hobo/subsite.rb +5 -18
  57. data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
  58. data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
  59. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
  60. data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
  61. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
  62. data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
  63. data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
  64. data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
  65. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
  66. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
  67. data/lib/generators/hobo/user_model/USAGE +9 -2
  68. data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
  69. data/lib/hobo.rb +7 -13
  70. data/lib/hobo/controller.rb +14 -21
  71. data/lib/hobo/controller/authentication_support.rb +23 -1
  72. data/lib/hobo/controller/model.rb +53 -48
  73. data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
  74. data/lib/hobo/engine.rb +11 -25
  75. data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
  76. data/lib/hobo/extensions/active_model/translation.rb +1 -1
  77. data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
  78. data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
  79. data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
  80. data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
  81. data/lib/hobo/extensions/active_record/scopes.rb +31 -0
  82. data/lib/hobo/extensions/array.rb +1 -13
  83. data/lib/hobo/helper.rb +6 -27
  84. data/lib/hobo/helper/translations.rb +90 -39
  85. data/lib/hobo/model.rb +20 -72
  86. data/lib/hobo/model/lifecycles.rb +11 -12
  87. data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
  88. data/lib/hobo/model/lifecycles/transition.rb +0 -1
  89. data/lib/hobo/model/permissions.rb +3 -2
  90. data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
  91. data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
  92. data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
  93. data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
  94. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
  95. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
  96. data/lib/hobo/rapid/helper.rb +5 -10
  97. data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
  98. data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
  99. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
  100. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
  101. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
  102. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
  103. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
  104. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
  105. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
  106. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
  107. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
  108. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
  109. data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
  110. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
  111. data/lib/hobo/routes.rb +23 -22
  112. data/lib/hobo/view_hints.rb +101 -0
  113. data/test/irt/generators/admin_subsite.irt +1 -1
  114. data/test/irt/generators/{assets.irt → basic.irt} +2 -2
  115. data/test/irt/generators/front_controller.irt +4 -2
  116. data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
  117. data/test/irt/generators/subsite.irt +1 -1
  118. data/test/permissions/test_permissions.rb +103 -103
  119. metadata +108 -69
  120. data/lib/generators/hobo/admin_subsite/USAGE +0 -25
  121. data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
  122. data/lib/generators/hobo/assets/USAGE +0 -5
  123. data/lib/generators/hobo/assets/assets_generator.rb +0 -18
  124. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
  125. data/lib/generators/hobo/controller/USAGE +0 -3
  126. data/lib/generators/hobo/i18n/USAGE +0 -3
  127. data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
  128. data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
  129. data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
  130. data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
  131. data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
  132. data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
  133. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
  134. data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
  135. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
  136. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  137. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  138. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  139. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
  140. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
  141. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
  142. data/lib/generators/hobo/resource/USAGE +0 -39
  143. data/lib/generators/hobo/subsite/USAGE +0 -24
  144. data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
  145. data/lib/generators/hobo/test_framework/USAGE +0 -2
  146. data/lib/generators/hobo/user_controller/USAGE +0 -3
  147. data/lib/generators/hobo/user_mailer/USAGE +0 -2
  148. data/lib/generators/hobo/user_resource/USAGE +0 -10
  149. data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
  150. data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
  151. data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
  152. data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
  153. data/lib/hobo/extensions/i18n.rb +0 -17
  154. data/lib/hobo/helper/translations/normalizer.rb +0 -39
  155. data/lib/hobo/model/view_hints.rb +0 -123
@@ -21,7 +21,7 @@ eval_file '../partials/_subsite_taglib_noopt.rb'
21
21
 
22
22
  git_reset_app
23
23
 
24
- invoke 'hobo:assets', %w[ -q ]
24
+ invoke 'hobo:basic', %w[ -q ]
25
25
  invoke 'hobo:subsite', %w[ subs -q --make-front-site]
26
26
  desc "Subsite with make-front-site files exist"
27
27
  files_exist? %w[ app/views/taglibs/front_site.dryml
@@ -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