josevalim-inherited_resources 0.5.0 → 0.5.1

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ # Version 0.5.0
2
+
3
+ * Only call I18n if it's defined.
4
+
1
5
  # Version 0.4.6
2
6
 
3
7
  * Dealing with namespaced controllers out of the box;
data/MIT-LICENSE CHANGED
@@ -1,5 +1,4 @@
1
- Copyright (c) 2006 Coda Hale
2
- Copyright (c) 2008 José Valim (jose.valim at gmail dot com)
1
+ Copyright (c) 2009 José Valim
3
2
 
4
3
  Permission is hereby granted, free of charge, to any person obtaining
5
4
  a copy of this software and associated documentation files (the
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  Inherited Resources
2
2
  License: MIT
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
 
5
5
  You can also read this README in pretty html at the GitHub project Wiki page:
6
6
 
@@ -16,7 +16,7 @@ your controllers more powerful and cleaner at the same time.
16
16
  Plus, making your controllers follow a pattern, it helps you to write better
17
17
  code by following fat models and skinny controllers convention.
18
18
 
19
- Inherited Resources is tested and compatible with Rails 2.2.2 and Rails 2.3.0.
19
+ Inherited Resources is tested and compatible with Rails 2.2.x and Rails 2.3.x.
20
20
 
21
21
  keywords: resources, controller, singleton, belongs_to, polymorphic and I18n
22
22
 
@@ -185,22 +185,26 @@ module InheritedResources #:nodoc:
185
185
  # flash.actions.create.status
186
186
  #
187
187
  def set_flash_message!(status, default_message = '')
188
+ return flash[status] = default_message unless defined?(::I18n)
189
+
188
190
  options = {
189
- :default => default_message,
191
+ :default => default_message || '',
190
192
  :resource_name => resource_class.human_name,
191
193
  }.merge(interpolation_options)
192
194
 
193
195
  defaults = []
194
- slices = [:flash]
195
- controller_path.split('/').each do |path|
196
- slices << path
197
- defaults << :"#{slices[0..-1].join('.')}.#{action_name}.#{status}"
198
- defaults << :"#{slices[0..-2].join('.')}.actions.#{action_name}.#{status}"
196
+ slices = controller_path.split('/')
197
+
198
+ while slices.size > 0
199
+ defaults << :"flash.#{slices.fill(controller_name, -1).join('.')}.#{action_name}.#{status}"
200
+ defaults << :"flash.#{slices.fill(:actions, -1).join('.')}.#{action_name}.#{status}"
201
+ slices.shift
199
202
  end
203
+
200
204
  options[:default] = defaults.push(options[:default])
201
205
  options[:default].flatten!
202
206
 
203
- message = I18n.t options[:default].shift, options
207
+ message = ::I18n.t options[:default].shift, options
204
208
  flash[status] = message unless message.blank?
205
209
  end
206
210
 
@@ -51,6 +51,14 @@ class FlashBaseHelpersTest < TEST_CLASS
51
51
  assert_equal 'Admin error message.', flash[:error]
52
52
  end
53
53
 
54
+ def test_inherited_success_flash_message_on_update_on_namespaced_controllers
55
+ @controller = Admin::AddressesController.new
56
+ Address.stubs(:find).returns(mock_address(:update_attributes => true))
57
+ put :update
58
+ assert_response :success
59
+ assert_equal 'Nice! Address was updated with success!', flash[:notice]
60
+ end
61
+
54
62
  def test_success_flash_message_on_update
55
63
  Address.stubs(:find).returns(mock_address(:update_attributes => true))
56
64
  put :update
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josevalim-inherited_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
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-03-11 00:00:00 -07:00
12
+ date: 2009-03-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15