rezource 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rezource.rb +48 -7
- data/rezource.gemspec +1 -1
- data/test/test_rezource.rb +70 -0
- metadata +2 -2
data/lib/rezource.rb
CHANGED
@@ -18,15 +18,18 @@ module Rezource
|
|
18
18
|
# ----------
|
19
19
|
|
20
20
|
def index
|
21
|
-
respond_with *namespace, find_resources
|
21
|
+
# respond_with *namespace, find_resources
|
22
|
+
index_respond_with find_resources
|
22
23
|
end
|
23
24
|
|
24
25
|
def show
|
25
|
-
respond_with *namespace, find_resource
|
26
|
+
# respond_with *namespace, find_resource
|
27
|
+
show_respond_with find_resource
|
26
28
|
end
|
27
29
|
|
28
30
|
def new
|
29
|
-
respond_with *namespace, build_resource
|
31
|
+
# respond_with *namespace, build_resource
|
32
|
+
new_respond_with build_resource
|
30
33
|
end
|
31
34
|
|
32
35
|
def create
|
@@ -34,7 +37,8 @@ module Rezource
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def edit
|
37
|
-
respond_with *namespace, find_resource
|
40
|
+
# respond_with *namespace, find_resource
|
41
|
+
edit_respond_with find_resource
|
38
42
|
end
|
39
43
|
|
40
44
|
def update
|
@@ -47,6 +51,36 @@ module Rezource
|
|
47
51
|
|
48
52
|
# -----------
|
49
53
|
|
54
|
+
def index_respond_with(resources)
|
55
|
+
respond_with *namespace, resources
|
56
|
+
end
|
57
|
+
|
58
|
+
def show_respond_with(resource)
|
59
|
+
respond_with *namespace, resource
|
60
|
+
end
|
61
|
+
|
62
|
+
def new_respond_with(resource)
|
63
|
+
respond_with *namespace, resource
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_respond_with(resource)
|
67
|
+
respond_with *namespace, resource
|
68
|
+
end
|
69
|
+
|
70
|
+
def edit_respond_with(resource)
|
71
|
+
respond_with *namespace, resource
|
72
|
+
end
|
73
|
+
|
74
|
+
# def update_respond_with(resource)
|
75
|
+
# respond_with *namespace, resource
|
76
|
+
# end
|
77
|
+
|
78
|
+
def destroy_respond_with(resource)
|
79
|
+
respond_with *namespace, resource
|
80
|
+
end
|
81
|
+
|
82
|
+
# -----------
|
83
|
+
|
50
84
|
def new_resource_path(*args)
|
51
85
|
send raw_path("new").to_sym, *args
|
52
86
|
end
|
@@ -71,7 +105,12 @@ module Rezource
|
|
71
105
|
parts = []
|
72
106
|
parts += [action] if action
|
73
107
|
parts += namespace
|
74
|
-
|
108
|
+
|
109
|
+
if parent?
|
110
|
+
if !action || action != "edit"
|
111
|
+
parts += [parent_ivar]
|
112
|
+
end
|
113
|
+
end
|
75
114
|
|
76
115
|
parts += if action
|
77
116
|
[resource_ivar]
|
@@ -196,7 +235,8 @@ module Rezource
|
|
196
235
|
resource.save if resource.valid?
|
197
236
|
after_create resource
|
198
237
|
|
199
|
-
respond_with *namespace, resource
|
238
|
+
# respond_with *namespace, resource
|
239
|
+
create_respond_with resource
|
200
240
|
end
|
201
241
|
|
202
242
|
def resource_update(resource, attributes={})
|
@@ -221,7 +261,8 @@ module Rezource
|
|
221
261
|
resource.destroy
|
222
262
|
after_destroy resource
|
223
263
|
|
224
|
-
respond_with *namespace, resource
|
264
|
+
# respond_with *namespace, resource
|
265
|
+
destroy_respond_with resource
|
225
266
|
end
|
226
267
|
|
227
268
|
|
data/rezource.gemspec
CHANGED
data/test/test_rezource.rb
CHANGED
@@ -62,6 +62,71 @@ class RezourceTest < Test::Unit::TestCase
|
|
62
62
|
assert_equal options, SamplesController.new.resource_options
|
63
63
|
end
|
64
64
|
|
65
|
+
# ----- <action>_respond_with
|
66
|
+
|
67
|
+
def test_index_respond_with
|
68
|
+
c = SamplesController.new
|
69
|
+
|
70
|
+
c.expects(:find_resources).returns([1,2,3])
|
71
|
+
c.expects(:index_respond_with).with([1,2,3])
|
72
|
+
|
73
|
+
c.index
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_show_respond_with
|
77
|
+
c = SamplesController.new
|
78
|
+
|
79
|
+
c.expects(:find_resource).returns({name: "joe"})
|
80
|
+
c.expects(:show_respond_with).with({name: "joe"})
|
81
|
+
|
82
|
+
c.show
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_new_respond_with
|
86
|
+
c = SamplesController.new
|
87
|
+
|
88
|
+
c.expects(:build_resource).returns({name: "joe"})
|
89
|
+
c.expects(:new_respond_with).with({name: "joe"})
|
90
|
+
|
91
|
+
c.new
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_create_respond_with
|
95
|
+
c = SamplesController.new
|
96
|
+
|
97
|
+
resource = mock()
|
98
|
+
resource.expects(:valid?).returns true
|
99
|
+
resource.expects(:save)
|
100
|
+
|
101
|
+
c.expects(:permitted_params_create).returns([])
|
102
|
+
c.expects(:build_resource).returns(resource)
|
103
|
+
c.expects(:create_respond_with).with(resource)
|
104
|
+
|
105
|
+
c.create
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_edit_respond_with
|
109
|
+
c = SamplesController.new
|
110
|
+
|
111
|
+
c.expects(:find_resource).returns({name: "joe"})
|
112
|
+
c.expects(:edit_respond_with).with({name: "joe"})
|
113
|
+
|
114
|
+
c.edit
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_create_respond_with
|
118
|
+
c = SamplesController.new
|
119
|
+
|
120
|
+
resource = mock()
|
121
|
+
resource.expects(:destroy)
|
122
|
+
|
123
|
+
c.expects(:find_resource).returns(resource)
|
124
|
+
c.expects(:destroy_respond_with).with(resource)
|
125
|
+
|
126
|
+
c.destroy
|
127
|
+
end
|
128
|
+
|
129
|
+
|
65
130
|
# ----- url resources
|
66
131
|
|
67
132
|
|
@@ -100,6 +165,11 @@ class RezourceTest < Test::Unit::TestCase
|
|
100
165
|
assert_equal "namespaced_sample_parent_samples_path", c.raw_path
|
101
166
|
end
|
102
167
|
|
168
|
+
def test_raw_path__with_parent_and_namespace_and_action
|
169
|
+
c = Namespaced::SamplesController.resource(belongs_to: SampleParent).new
|
170
|
+
assert_equal "edit_namespaced_sample_path", c.raw_path("edit")
|
171
|
+
end
|
172
|
+
|
103
173
|
def test_resources_path
|
104
174
|
c = SamplesController.new
|
105
175
|
c.stubs(:samples_path).returns "/samples"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rezource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Make Rails restful controller even more simple
|
15
15
|
email: jan.zimmek@web.de
|