inherited_resources 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,9 +1,6 @@
1
1
  # Version 0.9.4
2
2
 
3
- * Since InheritedResouces 0.9.4, :notice and :error in I18n messages are deprecated in
4
- favor of :success and :failure. If you try to access them, a deprecation message is shown.
5
- If you want to skip the message, because you are sure you *won't* access such keys,
6
- just set DO_NOT_SET_NOTICE_MESSAGE to true somewhere in your app.
3
+ * DEPRECATION: Use :success and :failure as flash messages instead :notice and :error
7
4
 
8
5
  # Version 0.9
9
6
 
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  Inherited Resources
2
2
  License: MIT
3
- Version: 0.9.4
3
+ Version: 0.9.2
4
4
 
5
5
  == Description
6
6
 
@@ -36,13 +36,6 @@ When used with integrate_views equals to false, rspec overwrites default_render,
36
36
  render and some other controller methods which makes Inherited Resources not work
37
37
  properly. In such cases, you have to set integrate_views to true.
38
38
 
39
- == Deprecation
40
-
41
- Since InheritedResouces 0.9.4, :notice and :error in I18n messages are deprecated in
42
- favor of :success and :failure. If you try to access them, a deprecation message is shown.
43
- If you want to skip the message, because you are sure you *won't* access such keys,
44
- just set DO_NOT_SET_NOTICE_MESSAGE to true somewhere in your app.
45
-
46
39
  == Basic Usage
47
40
 
48
41
  To use Inherited Resources you just have to inherit (duh) it:
@@ -267,8 +260,8 @@ on projects controller, it will search for:
267
260
  flash.projects.create.status
268
261
  flash.actions.create.status
269
262
 
270
- The status can be :success (when the object can be created, updated
271
- or destroyed with success) or :failure (when the objecy cannot be created
263
+ The status can be :notice (when the object can be created, updated
264
+ or destroyed with success) or :error (when the objecy cannot be created
272
265
  or updated).
273
266
 
274
267
  Those messages are interpolated by using the resource class human name, which
@@ -277,7 +270,7 @@ is also localized and it means you can set:
277
270
  flash:
278
271
  actions:
279
272
  create:
280
- success: "Hooray! {{resource_name}} was successfully created!"
273
+ notice: "Hooray! {{resource_name}} was successfully created!"
281
274
 
282
275
  It will replace {{resource_name}} by the human name of the resource class,
283
276
  which is "Project" in this case.
@@ -288,7 +281,7 @@ the title of the project while updating a project. Well, that's easy also:
288
281
  flash:
289
282
  projects:
290
283
  update:
291
- success: "Hooray! The project "{{project_title}}" was updated!"
284
+ notice: "Hooray! The project "{{project_title}}" was updated!"
292
285
 
293
286
  Since :project_title is not available for interpolation by default, you have
294
287
  to overwrite interpolation_options.
@@ -31,11 +31,11 @@ module InheritedResources
31
31
  object = build_resource
32
32
 
33
33
  if create_resource(object)
34
- set_flash_message!(:success, '{{resource_name}} was successfully created.')
34
+ set_flash_message!(:notice, '{{resource_name}} was successfully created.')
35
35
  options[:location] ||= resource_url rescue nil
36
36
  respond_with_dual_blocks(object, options, true, block)
37
37
  else
38
- set_flash_message!(:failure)
38
+ set_flash_message!(:error)
39
39
  respond_with_dual_blocks(object, options, false, block)
40
40
  end
41
41
  end
@@ -46,11 +46,11 @@ module InheritedResources
46
46
  object = resource
47
47
 
48
48
  if update_resource(object, params[resource_instance_name])
49
- set_flash_message!(:success, '{{resource_name}} was successfully updated.')
49
+ set_flash_message!(:notice, '{{resource_name}} was successfully updated.')
50
50
  options[:location] ||= resource_url rescue nil
51
51
  respond_with_dual_blocks(object, options, true, block)
52
52
  else
53
- set_flash_message!(:failure)
53
+ set_flash_message!(:error)
54
54
  respond_with_dual_blocks(object, options, false, block)
55
55
  end
56
56
  end
@@ -62,10 +62,10 @@ module InheritedResources
62
62
  options[:location] ||= collection_url rescue nil
63
63
 
64
64
  if destroy_resource(object)
65
- set_flash_message!(:success, '{{resource_name}} was successfully destroyed.')
65
+ set_flash_message!(:notice, '{{resource_name}} was successfully destroyed.')
66
66
  respond_with_dual_blocks(object, options, true, block)
67
67
  else
68
- set_flash_message!(:failure, '{{resource_name}} could not be destroyed.')
68
+ set_flash_message!(:error, '{{resource_name}} could not be destroyed.')
69
69
  respond_with_dual_blocks(object, options, false, block)
70
70
  end
71
71
  end
@@ -226,8 +226,8 @@ module InheritedResources
226
226
  # flash.cars.create.status
227
227
  # flash.actions.create.status
228
228
  #
229
- # The statuses can be :success (when the object can be created, updated
230
- # or destroyed with success) or :failure (when the objecy cannot be created
229
+ # The statuses can be :notice (when the object can be created, updated
230
+ # or destroyed with success) or :error (when the objecy cannot be created
231
231
  # or updated).
232
232
  #
233
233
  # Those messages are interpolated by using the resource class human name.
@@ -236,7 +236,7 @@ module InheritedResources
236
236
  # flash:
237
237
  # actions:
238
238
  # create:
239
- # success: "Hooray! {{resource_name}} was successfully created!"
239
+ # notice: "Hooray! {{resource_name}} was successfully created!"
240
240
  #
241
241
  # But sometimes, flash messages are not that simple. Going back
242
242
  # to cars example, you might want to say the brand of the car when it's
@@ -245,7 +245,7 @@ module InheritedResources
245
245
  # flash:
246
246
  # cars:
247
247
  # update:
248
- # success: "Hooray! You just tuned your {{car_brand}}!"
248
+ # notice: "Hooray! You just tuned your {{car_brand}}!"
249
249
  #
250
250
  # Since :car_name is not available for interpolation by default, you have
251
251
  # to overwrite interpolation_options.
@@ -266,7 +266,7 @@ module InheritedResources
266
266
  # flash.cars.create.status
267
267
  # flash.actions.create.status
268
268
  #
269
- def orig_set_flash_message!(status, default_message=nil)
269
+ def set_flash_message!(status, default_message=nil)
270
270
  return flash[status] = default_message unless defined?(::I18n)
271
271
 
272
272
  resource_name = if resource_class
@@ -306,29 +306,6 @@ module InheritedResources
306
306
  flash[status] = message unless message.blank?
307
307
  end
308
308
 
309
- def set_flash_message!(status, default_message=nil)
310
- return orig_set_flash_message!(status, default_message) if defined?(DO_NOT_SET_DEPRECATED_FLASH)
311
-
312
- fallback = status == :success ? :notice : :error
313
- result = orig_set_flash_message!(status)
314
-
315
- if result.blank?
316
- result = orig_set_flash_message!(fallback)
317
-
318
- if result.blank?
319
- result = orig_set_flash_message!(status, default_message) if default_message
320
- else
321
- ActiveSupport::Deprecation.warn "Using :#{fallback} in I18n with InheritedResources is deprecated, please use :#{status} instead"
322
- end
323
- end
324
-
325
- unless result.blank?
326
- flash[status] = result
327
- flash[fallback] = ActiveSupport::Deprecation::DeprecatedObjectProxy.new result, "Accessing :#{fallback} in flash with InheritedResources is deprecated, please use :#{status} instead"
328
- result
329
- end
330
- end
331
-
332
309
  # Used to allow to specify success and failure within just one block:
333
310
  #
334
311
  # def create
@@ -63,11 +63,9 @@ module InheritedResources
63
63
  raise ArgumentError, 'Wrong number of arguments. You have to provide which actions you want to keep.' if actions_to_keep.empty?
64
64
 
65
65
  options = actions_to_keep.extract_options!
66
- actions_to_remove = Array(options[:except])
67
- actions_to_remove += ACTIONS - actions_to_keep.map { |a| a.to_sym } unless actions_to_keep.include?(:all)
68
- actions_to_remove.map! { |a| a.to_sym }
69
- actions_to_remove.uniq!
70
-
66
+ actions_to_remove = Array(options[:except])
67
+ actions_to_remove += ACTIONS - actions_to_keep.map { |a| a.to_sym } unless actions_to_keep.first == :all
68
+ actions_to_remove.map! { |a| a.to_sym }.uniq!
71
69
  (instance_methods.map { |m| m.to_sym } & actions_to_remove).each do |action|
72
70
  undef_method action, "#{action}!"
73
71
  end
@@ -1,3 +1,3 @@
1
1
  module InheritedResources
2
- VERSION = '0.9.4'.freeze
3
- end
2
+ VERSION = '0.9.5'.freeze
3
+ end
data/test/flash_test.rb CHANGED
@@ -34,7 +34,7 @@ class FlashBaseHelpersTest < ActionController::TestCase
34
34
  def test_success_flash_message_on_create_with_yml
35
35
  Address.stubs(:new).returns(mock_address(:save => true))
36
36
  post :create
37
- assert_equal 'You created a new address close to <b>Ocean Avenue</b>.', flash[:success]
37
+ assert_equal 'You created a new address close to <b>Ocean Avenue</b>.', flash[:notice]
38
38
  end
39
39
 
40
40
  def test_success_flash_message_on_create_with_namespaced_controller
@@ -42,7 +42,7 @@ class FlashBaseHelpersTest < ActionController::TestCase
42
42
  @controller.stubs(:resource_url).returns("http://test.host/")
43
43
  Address.stubs(:new).returns(mock_address(:save => true))
44
44
  post :create
45
- assert_equal 'Admin, you created a new address close to <b>Ocean Avenue</b>.', flash[:success]
45
+ assert_equal 'Admin, you created a new address close to <b>Ocean Avenue</b>.', flash[:notice]
46
46
  end
47
47
 
48
48
  def test_failure_flash_message_on_create_with_namespaced_controller_actions
@@ -50,7 +50,7 @@ class FlashBaseHelpersTest < ActionController::TestCase
50
50
  @controller.stubs(:resource_url).returns("http://test.host/")
51
51
  Address.stubs(:new).returns(mock_address(:save => false))
52
52
  post :create
53
- assert_equal 'Admin error message.', flash[:failure]
53
+ assert_equal 'Admin error message.', flash[:error]
54
54
  end
55
55
 
56
56
  def test_inherited_success_flash_message_on_update_on_namespaced_controllers
@@ -59,26 +59,26 @@ class FlashBaseHelpersTest < ActionController::TestCase
59
59
  Address.stubs(:find).returns(mock_address(:update_attributes => true))
60
60
  put :update
61
61
  assert_response :success
62
- assert_equal 'Nice! Address was updated with success!', flash[:success]
62
+ assert_equal 'Nice! Address was updated with success!', flash[:notice]
63
63
  end
64
64
 
65
65
  def test_success_flash_message_on_update
66
66
  Address.stubs(:find).returns(mock_address(:update_attributes => true))
67
67
  put :update
68
68
  assert_response :success
69
- assert_equal 'Nice! Address was updated with success!', flash[:success]
69
+ assert_equal 'Nice! Address was updated with success!', flash[:notice]
70
70
  end
71
71
 
72
72
  def test_failure_flash_message_on_update
73
73
  Address.stubs(:find).returns(mock_address(:update_attributes => false, :errors => {:some => :error}))
74
74
  put :update
75
- assert_equal 'Oh no! We could not update your address!', flash[:failure]
75
+ assert_equal 'Oh no! We could not update your address!', flash[:error]
76
76
  end
77
77
 
78
78
  def test_success_flash_message_on_destroy
79
79
  Address.stubs(:find).returns(mock_address(:destroy => true))
80
80
  delete :destroy
81
- assert_equal 'Address was successfully destroyed.', flash[:success]
81
+ assert_equal 'Address was successfully destroyed.', flash[:notice]
82
82
  end
83
83
 
84
84
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inherited_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-12 00:00:00 -02:00
12
+ date: 2009-12-22 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15