josevalim-inherited_resources 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +7 -6
- data/lib/inherited_resources/base.rb +8 -7
- data/lib/inherited_resources/base_helpers.rb +15 -10
- data/test/base_helpers_test.rb +13 -5
- data/test/{fixtures → locales}/en.yml +4 -0
- data/test/test_helper.rb +1 -1
- metadata +3 -3
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Inherited Resources
|
2
2
|
License: MIT
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.5
|
4
4
|
|
5
5
|
You can also read this README in pretty html at the GitHub project Wiki page:
|
6
6
|
|
@@ -290,12 +290,13 @@ Then you will finally have:
|
|
290
290
|
|
291
291
|
'Hooray! You just tuned your Aston Martin!'
|
292
292
|
|
293
|
-
If your controller is namespaced, for example
|
294
|
-
|
293
|
+
If your controller is namespaced, for example Rars::CarsController, the
|
294
|
+
messages will be checked in the following order:
|
295
295
|
|
296
|
-
flash.
|
297
|
-
flash.
|
298
|
-
flash.
|
296
|
+
flash.rare.cars.create.notice
|
297
|
+
flash.rare.actions.create.notice
|
298
|
+
flash.cars.create.notice
|
299
|
+
flash.actions.create.notice
|
299
300
|
|
300
301
|
Belongs to
|
301
302
|
----------
|
@@ -226,17 +226,18 @@ module InheritedResources
|
|
226
226
|
|
227
227
|
if object.save
|
228
228
|
set_flash_message!(:notice, '{{resource_name}} was successfully created.')
|
229
|
+
location_url = resource_url rescue nil # Sometimes resource_url is undefined
|
229
230
|
|
230
|
-
respond_to(:with => object, :status => :created, :location =>
|
231
|
-
block.call
|
231
|
+
respond_to(:with => object, :status => :created, :location => location_url) do |format|
|
232
|
+
block.call(args_for_block(block, format, true)) if block_given?
|
232
233
|
format.html { redirect_to(resource_url) }
|
233
234
|
end
|
234
235
|
else
|
235
236
|
set_flash_message!(:error)
|
236
237
|
|
237
238
|
respond_to(:with => object.errors, :status => :unprocessable_entity) do |format|
|
238
|
-
block.call
|
239
|
-
format.html { render :action =>
|
239
|
+
block.call(args_for_block(block, format, false)) if block_given?
|
240
|
+
format.html { render :action => 'new' }
|
240
241
|
end
|
241
242
|
end
|
242
243
|
end
|
@@ -250,7 +251,7 @@ module InheritedResources
|
|
250
251
|
set_flash_message!(:notice, '{{resource_name}} was successfully updated.')
|
251
252
|
|
252
253
|
respond_to do |format|
|
253
|
-
block.call
|
254
|
+
block.call(args_for_block(block, format, true)) if block_given?
|
254
255
|
format.html { redirect_to(resource_url) }
|
255
256
|
format.all { head :ok }
|
256
257
|
end
|
@@ -258,8 +259,8 @@ module InheritedResources
|
|
258
259
|
set_flash_message!(:error)
|
259
260
|
|
260
261
|
respond_to(:with => object.errors, :status => :unprocessable_entity) do |format|
|
261
|
-
block.call
|
262
|
-
format.html { render :action =>
|
262
|
+
block.call(args_for_block(block, format, false)) if block_given?
|
263
|
+
format.html { render :action => 'edit' }
|
263
264
|
end
|
264
265
|
end
|
265
266
|
end
|
@@ -176,24 +176,29 @@ module InheritedResources #:nodoc:
|
|
176
176
|
#
|
177
177
|
# 'Hooray! You just tuned your Aston Martin!'
|
178
178
|
#
|
179
|
-
# If your controller is namespaced, for example
|
179
|
+
# If your controller is namespaced, for example Rare::CarsController,
|
180
180
|
# the messages will be checked in the following order:
|
181
181
|
#
|
182
|
-
# flash.
|
182
|
+
# flash.rare.cars.create.status
|
183
|
+
# flash.rare.actions.create.status
|
183
184
|
# flash.cars.create.status
|
184
185
|
# flash.actions.create.status
|
185
186
|
#
|
186
187
|
def set_flash_message!(status, default_message = '')
|
187
|
-
options =
|
188
|
-
:default =>
|
189
|
-
:"flash.actions.#{action_name}.#{status}",
|
190
|
-
default_message ],
|
188
|
+
options = {
|
189
|
+
:default => default_message,
|
191
190
|
:resource_name => resource_class.human_name,
|
192
|
-
})
|
193
|
-
|
194
|
-
|
195
|
-
|
191
|
+
}.merge(interpolation_options)
|
192
|
+
|
193
|
+
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
199
|
end
|
200
|
+
options[:default] = defaults.push(options[:default])
|
201
|
+
options[:default].flatten!
|
197
202
|
|
198
203
|
# TODO Deprecate this whole begin/rescue block and replace it for:
|
199
204
|
#
|
data/test/base_helpers_test.rb
CHANGED
@@ -28,14 +28,14 @@ class FlashBaseHelpersTest < TEST_CLASS
|
|
28
28
|
@request.accept = 'application/xml'
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def test_success_flash_message_on_create_with_yml
|
32
32
|
Address.stubs(:new).returns(mock_address(:save => true))
|
33
33
|
@controller.stubs(:address_url)
|
34
34
|
post :create
|
35
35
|
assert_equal 'You created a new address close to <b>Ocean Avenue</b>.', flash[:notice]
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def test_success_flash_message_on_create_with_namespaced_controller
|
39
39
|
@controller = Admin::AddressesController.new
|
40
40
|
Address.stubs(:new).returns(mock_address(:save => true))
|
41
41
|
@controller.stubs(:address_url)
|
@@ -43,20 +43,28 @@ class FlashBaseHelpersTest < TEST_CLASS
|
|
43
43
|
assert_equal 'Admin, you created a new address close to <b>Ocean Avenue</b>.', flash[:notice]
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def test_failure_flash_message_on_create_with_namespaced_controller_actions
|
47
|
+
@controller = Admin::AddressesController.new
|
48
|
+
Address.stubs(:new).returns(mock_address(:save => false))
|
49
|
+
@controller.stubs(:address_url)
|
50
|
+
post :create
|
51
|
+
assert_equal 'Admin error message.', flash[:error]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_success_flash_message_on_update
|
47
55
|
Address.stubs(:find).returns(mock_address(:update_attributes => true))
|
48
56
|
put :update
|
49
57
|
assert_response :success
|
50
58
|
assert_equal 'Nice! Address was updated with success!', flash[:notice]
|
51
59
|
end
|
52
60
|
|
53
|
-
def
|
61
|
+
def test_failure_flash_message_on_update
|
54
62
|
Address.stubs(:find).returns(mock_address(:update_attributes => false, :errors => []))
|
55
63
|
put :update
|
56
64
|
assert_equal 'Oh no! We could not update your address!', flash[:error]
|
57
65
|
end
|
58
66
|
|
59
|
-
def
|
67
|
+
def test_success_flash_message_on_destroy
|
60
68
|
Address.stubs(:find).returns(mock_address(:destroy => true))
|
61
69
|
delete :destroy
|
62
70
|
assert_equal 'Address was successfully destroyed.', flash[:notice]
|
@@ -7,6 +7,10 @@ en:
|
|
7
7
|
notice: "Nice! {{resource_name}} was updated with success!"
|
8
8
|
error: "Oh no! We could not update your address!"
|
9
9
|
admin:
|
10
|
+
actions:
|
11
|
+
create:
|
12
|
+
notice: "Admin notice message."
|
13
|
+
error: "Admin error message."
|
10
14
|
addresses:
|
11
15
|
create:
|
12
16
|
notice: "Admin, you created a new address close to <b>{{reference}}</b>."
|
data/test/test_helper.rb
CHANGED
@@ -16,7 +16,7 @@ require 'action_controller/test_process'
|
|
16
16
|
|
17
17
|
TEST_CLASS = ActionController::TestCase
|
18
18
|
|
19
|
-
I18n.load_path << File.join(File.dirname(__FILE__), '
|
19
|
+
I18n.load_path << File.join(File.dirname(__FILE__), 'locales', 'en.yml')
|
20
20
|
I18n.reload!
|
21
21
|
|
22
22
|
# Load respond_to before defining ApplicationController
|
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.4.
|
4
|
+
version: 0.4.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
|
+
date: 2009-03-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -78,7 +78,7 @@ test_files:
|
|
78
78
|
- test/singleton_test.rb
|
79
79
|
- test/test_helper.rb
|
80
80
|
- test/url_helpers_test.rb
|
81
|
-
- test/
|
81
|
+
- test/locales/en.yml
|
82
82
|
- test/views/cities/edit.html.erb
|
83
83
|
- test/views/cities/index.html.erb
|
84
84
|
- test/views/cities/new.html.erb
|