rezource 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rezource.rb +40 -27
- data/rezource.gemspec +1 -1
- data/test/test_rezource.rb +88 -40
- metadata +1 -1
data/lib/rezource.rb
CHANGED
@@ -82,49 +82,62 @@ module Rezource
|
|
82
82
|
# -----------
|
83
83
|
|
84
84
|
def new_resource_path(*args)
|
85
|
-
|
85
|
+
parts = ["new"] + namespace + (parent? ? [parent_ivar] : []) + [resource_ivar] + ["path"]
|
86
|
+
send parts.join("_").to_sym, *args
|
87
|
+
|
88
|
+
# send raw_path("new").to_sym, *args
|
86
89
|
end
|
87
90
|
|
88
91
|
def edit_resource_path(*args)
|
89
|
-
|
92
|
+
action_resource_path "edit", *args
|
93
|
+
# parts = ["edit"] + namespace + [resource_ivar] + ["path"]
|
94
|
+
# send parts.join("_").to_sym, *args
|
95
|
+
# send raw_path("edit").to_sym, *args
|
90
96
|
end
|
91
97
|
|
92
98
|
def action_resource_path(action, *args)
|
93
|
-
|
99
|
+
parts = [action] + namespace + [resource_ivar] + ["path"]
|
100
|
+
send parts.join("_").to_sym, *args
|
101
|
+
# send raw_path(action).to_sym, *args
|
94
102
|
end
|
95
103
|
|
96
104
|
def resources_path(*args)
|
97
|
-
|
105
|
+
parts = namespace + (parent? ? [parent_ivar] : []) + [resource_options[:singleton] ? resource_ivar : resources_ivar] + ["path"]
|
106
|
+
send parts.join("_").to_sym, *args
|
107
|
+
# send raw_path.to_sym, *args
|
98
108
|
end
|
99
109
|
|
100
110
|
def resource_path(*args)
|
101
|
-
|
111
|
+
parts = namespace + [resource_ivar] + ["path"]
|
112
|
+
send parts.join("_").to_sym, *args
|
113
|
+
# send raw_path(nil, true).to_sym, *args
|
102
114
|
end
|
103
115
|
|
104
|
-
def raw_path(action=nil, singleton=false)
|
105
|
-
|
106
|
-
|
107
|
-
parts += namespace
|
116
|
+
# def raw_path(action=nil, singleton=false)
|
117
|
+
# parts = []
|
118
|
+
# parts += [action] if action
|
108
119
|
|
109
|
-
|
110
|
-
if !action || action != "edit"
|
111
|
-
parts += [parent_ivar]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
parts += if action
|
116
|
-
[resource_ivar]
|
117
|
-
elsif singleton
|
118
|
-
[resource_ivar]
|
119
|
-
elsif resource_options[:singleton]
|
120
|
-
[resource_ivar]
|
121
|
-
else
|
122
|
-
[resources_ivar]
|
123
|
-
end
|
120
|
+
# parts += namespace
|
124
121
|
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
# if parent?
|
123
|
+
# if !action || action != "edit"
|
124
|
+
# parts += [parent_ivar]
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
|
128
|
+
# parts += if action
|
129
|
+
# [resource_ivar]
|
130
|
+
# elsif singleton
|
131
|
+
# [resource_ivar]
|
132
|
+
# elsif resource_options[:singleton]
|
133
|
+
# [resource_ivar]
|
134
|
+
# else
|
135
|
+
# [resources_ivar]
|
136
|
+
# end
|
137
|
+
|
138
|
+
# parts += ["path"]
|
139
|
+
# parts.join("_")
|
140
|
+
# end
|
128
141
|
|
129
142
|
# -----------
|
130
143
|
|
data/rezource.gemspec
CHANGED
data/test/test_rezource.rb
CHANGED
@@ -130,76 +130,124 @@ class RezourceTest < Test::Unit::TestCase
|
|
130
130
|
# ----- url resources
|
131
131
|
|
132
132
|
|
133
|
-
def test_raw_path
|
133
|
+
# def test_raw_path
|
134
|
+
# c = SamplesController.new
|
135
|
+
# assert_equal "samples_path", c.raw_path
|
136
|
+
# end
|
137
|
+
|
138
|
+
# def test_raw_path__with_singleton
|
139
|
+
# c = SamplesController.new
|
140
|
+
# assert_equal "sample_path", c.raw_path(nil, true)
|
141
|
+
# end
|
142
|
+
|
143
|
+
# def test_raw_path__with_new_action
|
144
|
+
# c = SamplesController.new
|
145
|
+
# assert_equal "new_sample_path", c.raw_path("new")
|
146
|
+
# end
|
147
|
+
|
148
|
+
# def test_raw_path__with_edit_action
|
149
|
+
# c = SamplesController.new
|
150
|
+
# assert_equal "edit_sample_path", c.raw_path("edit")
|
151
|
+
# end
|
152
|
+
|
153
|
+
# def test_raw_path__with_namespace
|
154
|
+
# c = Namespaced::SamplesController.new
|
155
|
+
# assert_equal "namespaced_samples_path", c.raw_path
|
156
|
+
# end
|
157
|
+
|
158
|
+
# def test_raw_path__with_parent
|
159
|
+
# c = SamplesController.resource(belongs_to: SampleParent).new
|
160
|
+
# assert_equal "sample_parent_samples_path", c.raw_path
|
161
|
+
# end
|
162
|
+
|
163
|
+
# def test_raw_path__with_parent_and_namespace
|
164
|
+
# c = Namespaced::SamplesController.resource(belongs_to: SampleParent).new
|
165
|
+
# assert_equal "namespaced_sample_parent_samples_path", c.raw_path
|
166
|
+
# end
|
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
|
+
|
173
|
+
def test_resources_path
|
134
174
|
c = SamplesController.new
|
135
|
-
|
175
|
+
c.stubs(:samples_path).returns "xyz"
|
176
|
+
assert_equal "xyz", c.resources_path
|
136
177
|
end
|
137
178
|
|
138
|
-
def
|
139
|
-
c = SamplesController.new
|
140
|
-
|
179
|
+
def test_resources_path__with_singleton
|
180
|
+
c = SamplesController.resource(singleton: true).new
|
181
|
+
c.stubs(:sample_path).returns "xyz"
|
182
|
+
assert_equal "xyz", c.resources_path
|
141
183
|
end
|
142
184
|
|
143
|
-
def
|
144
|
-
c = SamplesController.new
|
145
|
-
|
185
|
+
def test_resources_path__with_namespace
|
186
|
+
c = Namespaced::SamplesController.new
|
187
|
+
c.stubs(:namespaced_samples_path).returns "xyz"
|
188
|
+
assert_equal "xyz", c.resources_path
|
146
189
|
end
|
147
190
|
|
148
|
-
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
def test_resource_path
|
149
195
|
c = SamplesController.new
|
150
|
-
|
196
|
+
c.stubs(:sample_path).returns "xyz"
|
197
|
+
assert_equal "xyz", c.resource_path
|
151
198
|
end
|
152
199
|
|
153
|
-
def
|
154
|
-
c =
|
155
|
-
|
200
|
+
def test_resource_path__with_singleton
|
201
|
+
c = SamplesController.resource(singleton: true).new
|
202
|
+
c.stubs(:sample_path).returns "xyz"
|
203
|
+
assert_equal "xyz", c.resource_path
|
156
204
|
end
|
157
205
|
|
158
|
-
def
|
159
|
-
c = SamplesController.
|
160
|
-
|
206
|
+
def test_resource_path__with_namespace
|
207
|
+
c = Namespaced::SamplesController.new
|
208
|
+
c.stubs(:namespaced_sample_path).returns "xyz"
|
209
|
+
assert_equal "xyz", c.resource_path
|
161
210
|
end
|
162
211
|
|
163
|
-
def test_raw_path__with_parent_and_namespace
|
164
|
-
c = Namespaced::SamplesController.resource(belongs_to: SampleParent).new
|
165
|
-
assert_equal "namespaced_sample_parent_samples_path", c.raw_path
|
166
|
-
end
|
167
212
|
|
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
213
|
|
173
|
-
def
|
214
|
+
def test_new_resources_path
|
174
215
|
c = SamplesController.new
|
175
|
-
c.stubs(:
|
176
|
-
assert_equal "
|
216
|
+
c.stubs(:new_sample_path).returns "xyz"
|
217
|
+
assert_equal "xyz", c.new_resource_path
|
177
218
|
end
|
178
219
|
|
179
|
-
def
|
180
|
-
c = SamplesController.new
|
181
|
-
c.stubs(:
|
182
|
-
assert_equal "
|
220
|
+
def test_new_resources_path__with_namespace
|
221
|
+
c = Namespaced::SamplesController.new
|
222
|
+
c.stubs(:new_namespaced_sample_path).returns "xyz"
|
223
|
+
assert_equal "xyz", c.new_resource_path
|
183
224
|
end
|
184
225
|
|
185
|
-
def
|
226
|
+
def test_edit_resources_path
|
186
227
|
c = SamplesController.new
|
187
|
-
c.stubs(:
|
188
|
-
assert_equal "
|
228
|
+
c.stubs(:edit_sample_path).returns "xyz"
|
229
|
+
assert_equal "xyz", c.edit_resource_path
|
189
230
|
end
|
190
231
|
|
191
|
-
def
|
192
|
-
c = SamplesController.new
|
193
|
-
c.stubs(:
|
194
|
-
assert_equal "
|
232
|
+
def test_edit_resources_path__with_namespace
|
233
|
+
c = Namespaced::SamplesController.new
|
234
|
+
c.stubs(:edit_namespaced_sample_path).returns "xyz"
|
235
|
+
assert_equal "xyz", c.edit_resource_path
|
195
236
|
end
|
196
237
|
|
197
238
|
def test_action_resources_path
|
198
239
|
c = SamplesController.new
|
199
|
-
c.stubs(:custom_sample_path).returns "
|
200
|
-
assert_equal "
|
240
|
+
c.stubs(:custom_sample_path).returns "xyz"
|
241
|
+
assert_equal "xyz", c.action_resource_path("custom")
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_action_resources_path__with_namespace
|
245
|
+
c = Namespaced::SamplesController.new
|
246
|
+
c.stubs(:custom_namespaced_sample_path).returns "xyz"
|
247
|
+
assert_equal "xyz", c.action_resource_path("custom")
|
201
248
|
end
|
202
249
|
|
250
|
+
# ------
|
203
251
|
|
204
252
|
def test_default_respond_with
|
205
253
|
c = SamplesController.new
|