rezource 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rezource.rb +15 -6
- data/rezource.gemspec +1 -1
- data/test/test_rezource.rb +55 -1
- metadata +1 -1
data/lib/rezource.rb
CHANGED
@@ -55,6 +55,10 @@ module Rezource
|
|
55
55
|
send raw_path("edit").to_sym, *args
|
56
56
|
end
|
57
57
|
|
58
|
+
def action_resource_path(action, *args)
|
59
|
+
send raw_path(action).to_sym, *args
|
60
|
+
end
|
61
|
+
|
58
62
|
def resources_path(*args)
|
59
63
|
send raw_path.to_sym, *args
|
60
64
|
end
|
@@ -63,17 +67,13 @@ module Rezource
|
|
63
67
|
send raw_path(nil, true).to_sym, *args
|
64
68
|
end
|
65
69
|
|
66
|
-
# def resource_path(*args)
|
67
|
-
# send raw_path.to_sym, *args
|
68
|
-
# end
|
69
|
-
|
70
70
|
def raw_path(action=nil, singleton=false)
|
71
71
|
parts = []
|
72
72
|
parts += [action] if action
|
73
73
|
parts += namespace
|
74
74
|
parts += [parent_ivar] if parent?
|
75
75
|
|
76
|
-
parts += if
|
76
|
+
parts += if action
|
77
77
|
[resource_ivar]
|
78
78
|
elsif singleton
|
79
79
|
[resource_ivar]
|
@@ -204,7 +204,16 @@ module Rezource
|
|
204
204
|
resource.update_attributes attributes if resource.valid?
|
205
205
|
after_update resource
|
206
206
|
|
207
|
-
|
207
|
+
if _action = params[:_action]
|
208
|
+
if resource.valid?
|
209
|
+
respond_with *namespace, resource, location: action_resource_path(_action)
|
210
|
+
else
|
211
|
+
respond_with *namespace, resource, action: _action
|
212
|
+
end
|
213
|
+
|
214
|
+
else
|
215
|
+
respond_with *namespace, resource
|
216
|
+
end
|
208
217
|
end
|
209
218
|
|
210
219
|
def resource_destroy(resource)
|
data/rezource.gemspec
CHANGED
data/test/test_rezource.rb
CHANGED
@@ -9,8 +9,13 @@ class Sample
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class SamplesController
|
12
|
-
def self.helper_method(*args)
|
12
|
+
def self.helper_method(*args)
|
13
13
|
end
|
14
|
+
|
15
|
+
def params
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
14
19
|
include Rezource
|
15
20
|
end
|
16
21
|
|
@@ -18,6 +23,9 @@ module Namespaced
|
|
18
23
|
class SamplesController
|
19
24
|
def self.helper_method(*args)
|
20
25
|
end
|
26
|
+
def params
|
27
|
+
{}
|
28
|
+
end
|
21
29
|
include Rezource
|
22
30
|
end
|
23
31
|
end
|
@@ -41,8 +49,11 @@ class RezourceTest < Test::Unit::TestCase
|
|
41
49
|
assert c.respond_to? :resource
|
42
50
|
assert c.respond_to? :resources
|
43
51
|
assert c.respond_to? :parent
|
52
|
+
|
53
|
+
assert c.respond_to? :resource_path
|
44
54
|
assert c.respond_to? :resources_path
|
45
55
|
assert c.respond_to? :new_resource_path
|
56
|
+
assert c.respond_to? :edit_resource_path
|
46
57
|
end
|
47
58
|
|
48
59
|
def test_resource_options
|
@@ -113,6 +124,12 @@ class RezourceTest < Test::Unit::TestCase
|
|
113
124
|
assert_equal "/samples/XYZ/edit", c.edit_resource_path
|
114
125
|
end
|
115
126
|
|
127
|
+
def test_action_resources_path
|
128
|
+
c = SamplesController.new
|
129
|
+
c.stubs(:custom_sample_path).returns "/samples/XYZ/custom"
|
130
|
+
assert_equal "/samples/XYZ/custom", c.action_resource_path("custom")
|
131
|
+
end
|
132
|
+
|
116
133
|
|
117
134
|
def test_default_respond_with
|
118
135
|
c = SamplesController.new
|
@@ -436,6 +453,43 @@ class RezourceTest < Test::Unit::TestCase
|
|
436
453
|
c.resource_update m, attributes
|
437
454
|
end
|
438
455
|
|
456
|
+
def test_resource_update__invalid_with_action
|
457
|
+
c = SamplesController.new
|
458
|
+
attributes = {name: "joe"}
|
459
|
+
m = mock()
|
460
|
+
|
461
|
+
c.expects(:before_update).with(m)
|
462
|
+
m.expects(:valid?).returns false
|
463
|
+
c.expects(:after_update).with(m)
|
464
|
+
|
465
|
+
c.expects(:"params").returns({_action: "custom"})
|
466
|
+
m.expects(:valid?).returns false
|
467
|
+
|
468
|
+
c.expects(:respond_with).with(*(c.namespace + [m] + [{action: "custom"}]))
|
469
|
+
|
470
|
+
c.resource_update m, attributes
|
471
|
+
end
|
472
|
+
|
473
|
+
def test_resource_update__valid_with_action
|
474
|
+
c = SamplesController.new
|
475
|
+
attributes = {name: "joe"}
|
476
|
+
m = mock()
|
477
|
+
|
478
|
+
c.expects(:before_update).with(m)
|
479
|
+
m.expects(:valid?).returns true
|
480
|
+
m.expects(:update_attributes).with(attributes)
|
481
|
+
c.expects(:after_update).with(m)
|
482
|
+
|
483
|
+
c.expects(:"params").returns({_action: "custom"})
|
484
|
+
m.expects(:valid?).returns true
|
485
|
+
|
486
|
+
c.expects(:"custom_sample_path").returns "/sample/XYZ/custom"
|
487
|
+
|
488
|
+
c.expects(:respond_with).with(*(c.namespace + [m] + [{location: "/sample/XYZ/custom"}]))
|
489
|
+
|
490
|
+
c.resource_update m, attributes
|
491
|
+
end
|
492
|
+
|
439
493
|
def test_resource_destroy
|
440
494
|
c = SamplesController.new
|
441
495
|
m = mock()
|