make_resourceful 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Rakefile +31 -0
  2. data/Readme.rdoc +229 -0
  3. data/VERSION +1 -0
  4. data/lib/make_resourceful.rb +11 -0
  5. data/lib/resourceful/base.rb +63 -0
  6. data/lib/resourceful/builder.rb +405 -0
  7. data/lib/resourceful/default/accessors.rb +418 -0
  8. data/lib/resourceful/default/actions.rb +101 -0
  9. data/lib/resourceful/default/callbacks.rb +51 -0
  10. data/lib/resourceful/default/responses.rb +118 -0
  11. data/lib/resourceful/default/urls.rb +136 -0
  12. data/lib/resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
  13. data/lib/resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
  14. data/lib/resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
  15. data/lib/resourceful/generators/resourceful_scaffold/templates/functional_test.rb +50 -0
  16. data/lib/resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
  17. data/lib/resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
  18. data/lib/resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
  19. data/lib/resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
  20. data/lib/resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
  21. data/lib/resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
  22. data/lib/resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
  23. data/lib/resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
  24. data/lib/resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
  25. data/lib/resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
  26. data/lib/resourceful/maker.rb +92 -0
  27. data/lib/resourceful/response.rb +33 -0
  28. data/lib/resourceful/serialize.rb +185 -0
  29. data/spec/accessors_spec.rb +474 -0
  30. data/spec/actions_spec.rb +310 -0
  31. data/spec/base_spec.rb +12 -0
  32. data/spec/builder_spec.rb +332 -0
  33. data/spec/callbacks_spec.rb +71 -0
  34. data/spec/integration_spec.rb +394 -0
  35. data/spec/maker_spec.rb +91 -0
  36. data/spec/response_spec.rb +37 -0
  37. data/spec/responses_spec.rb +314 -0
  38. data/spec/serialize_spec.rb +133 -0
  39. data/spec/urls_spec.rb +282 -0
  40. metadata +97 -0
data/spec/urls_spec.rb ADDED
@@ -0,0 +1,282 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Resourceful::Default::URLs, " for a controller with no parents or namespaces" do
4
+ include ControllerMocks
5
+ before :each do
6
+ mock_controller Resourceful::Default::URLs
7
+ @object = stub_model('Thing')
8
+ @controller.stubs(:current_object).returns(@object)
9
+
10
+ @controller.stubs(:current_model_name).returns('Thing')
11
+ @controller.stubs(:parent?).returns(false)
12
+ @controller.stubs(:namespaces).returns([])
13
+ end
14
+
15
+ it "should return nil for #url_helper_prefix" do
16
+ @controller.url_helper_prefix.should be_nil
17
+ end
18
+
19
+ it "should return the empty string for #collection_url_prefix" do
20
+ @controller.collection_url_prefix.should == ""
21
+ end
22
+
23
+ it "should get the path of current_object with #object_path" do
24
+ @controller.expects(:send).with('thing_path', @object)
25
+ @controller.object_path
26
+ end
27
+
28
+ it "should get the url of current_object with #object_url" do
29
+ @controller.expects(:send).with('thing_url', @object)
30
+ @controller.object_url
31
+ end
32
+
33
+ it "should get the path of the passed object with #object_path" do
34
+ model = stub_model('Thing')
35
+ @controller.expects(:send).with('thing_path', model)
36
+ @controller.object_path(model)
37
+ end
38
+
39
+ it "should get the url of the passed object with #object_url" do
40
+ model = stub_model('Thing')
41
+ @controller.expects(:send).with('thing_url', model)
42
+ @controller.object_url(model)
43
+ end
44
+
45
+ it "should get the path of current_object with #nested_object_path" do
46
+ @controller.expects(:send).with('thing_path', @object)
47
+ @controller.nested_object_path
48
+ end
49
+
50
+ it "should get the url of current_object with #nested_object_url" do
51
+ @controller.expects(:send).with('thing_url', @object)
52
+ @controller.nested_object_url
53
+ end
54
+
55
+ it "should get the path of the passed object with #nested_object_path" do
56
+ model = stub_model('Thing')
57
+ @controller.expects(:send).with('thing_path', model)
58
+ @controller.nested_object_path(model)
59
+ end
60
+
61
+ it "should get the url of the passed object with #nested_object_url" do
62
+ model = stub_model('Thing')
63
+ @controller.expects(:send).with('thing_url', model)
64
+ @controller.nested_object_url(model)
65
+ end
66
+
67
+ it "should get the edit path of current_object with #edit_object_path" do
68
+ @controller.expects(:send).with('edit_thing_path', @object)
69
+ @controller.edit_object_path
70
+ end
71
+
72
+ it "should get the edit url of current_object with #edit_object_url" do
73
+ @controller.expects(:send).with('edit_thing_url', @object)
74
+ @controller.edit_object_url
75
+ end
76
+
77
+ it "should get the edit path of the passed object with #edit_object_path" do
78
+ model = stub_model('Thing')
79
+ @controller.expects(:send).with('edit_thing_path', model)
80
+ @controller.edit_object_path(model)
81
+ end
82
+
83
+ it "should get the edit url of the passed object with #edit_object_url" do
84
+ model = stub_model('Thing')
85
+ @controller.expects(:send).with('edit_thing_url', model)
86
+ @controller.edit_object_url(model)
87
+ end
88
+
89
+ it "should get the plural path of the current model with #objects_path" do
90
+ @controller.expects(:send).with('things_path')
91
+ @controller.objects_path
92
+ end
93
+
94
+ it "should get the plural url of the current model with #objects_url" do
95
+ @controller.expects(:send).with('things_url')
96
+ @controller.objects_url
97
+ end
98
+
99
+ it "should get the new path of the current model with #new_object_path" do
100
+ @controller.expects(:send).with('new_thing_path')
101
+ @controller.new_object_path
102
+ end
103
+
104
+ it "should get the new url of the current model with #new_object_url" do
105
+ @controller.expects(:send).with('new_thing_url')
106
+ @controller.new_object_url
107
+ end
108
+ end
109
+
110
+ describe Resourceful::Default::URLs, " for a controller with a parent object" do
111
+ include ControllerMocks
112
+ before :each do
113
+ mock_controller Resourceful::Default::URLs
114
+ @object = stub_model('Thing')
115
+ @controller.stubs(:current_object).returns(@object)
116
+
117
+ @controller.stubs(:current_model_name).returns('Thing')
118
+
119
+ @person = stub_model('Person')
120
+ @controller.stubs(:parent_object).returns(@person)
121
+ @controller.stubs(:parent_name).returns('person')
122
+ @controller.stubs(:parent?).returns(true)
123
+ @controller.stubs(:parent_class_name).returns('Person')
124
+ @controller.stubs(:namespaces).returns([])
125
+ end
126
+
127
+ it "should return nil for #url_helper_prefix" do
128
+ @controller.url_helper_prefix.should be_nil
129
+ end
130
+
131
+ it "should return the underscored parent name for #collection_url_prefix" do
132
+ @controller.collection_url_prefix.should == "person_"
133
+ end
134
+
135
+ it "should get the path of current_object with #object_path" do
136
+ @controller.expects(:send).with('person_thing_path', @person, @object)
137
+ @controller.object_path
138
+ end
139
+
140
+ it "should get the nested path of current_object with #nested_object_path" do
141
+ @controller.expects(:send).with('person_thing_path', @person, @object)
142
+ @controller.nested_object_path
143
+ end
144
+
145
+ it "should get the nested url of current_object with #nested_object_url" do
146
+ @controller.expects(:send).with('person_thing_url', @person, @object)
147
+ @controller.nested_object_url
148
+ end
149
+
150
+ it "should get the nested path of the passed object with #nested_object_path" do
151
+ object = stub_model('Thing')
152
+ @controller.expects(:send).with('person_thing_path', @person, object)
153
+ @controller.nested_object_path object
154
+ end
155
+
156
+ it "should get the nested url of the passed object with #nested_object_url" do
157
+ object = stub_model('Thing')
158
+ @controller.expects(:send).with('person_thing_url', @person, object)
159
+ @controller.nested_object_url object
160
+ end
161
+
162
+ it "should get the plural path of the current model and its parent with #objects_path" do
163
+ @controller.expects(:send).with('person_things_path', @person)
164
+ @controller.objects_path
165
+ end
166
+
167
+ it "should get the edit path of the current model with #edit_object_path" do
168
+ @controller.expects(:send).with('edit_person_thing_path', @person, @object)
169
+ @controller.edit_object_path
170
+ end
171
+
172
+ it "should get the new path of the current model and its parent with #new_object_path" do
173
+ @controller.expects(:send).with('new_person_thing_path', @person)
174
+ @controller.new_object_path
175
+ end
176
+
177
+ it "should get the path of the parent_object with #parent_path" do
178
+ pending
179
+ @controller.expects(:send).with('person_path', @person)
180
+ @controller.parent_path
181
+ end
182
+
183
+ it "should get the url of the parent_object with #parent_url" do
184
+ pending
185
+ @controller.expects(:send).with('person_url', @person)
186
+ @controller.parent_url
187
+ end
188
+
189
+ it "should get the path of the passed object with #parent_path" do
190
+ pending
191
+ model = stub_model('Person')
192
+ @controller.expects(:send).with('person_path', model)
193
+ @controller.parent_path model
194
+ end
195
+
196
+ it "should get the url of the passed object with #parent_url" do
197
+ pending
198
+ model = stub_model('Person')
199
+ @controller.expects(:send).with('person_url', model)
200
+ @controller.parent_url model
201
+ end
202
+ end
203
+
204
+ describe Resourceful::Default::URLs, " for a controller within a namespace" do
205
+ include ControllerMocks
206
+ before :each do
207
+ mock_controller Resourceful::Default::URLs
208
+ @object = stub_model('Thing')
209
+ @controller.stubs(:current_object).returns(@object)
210
+
211
+ @controller.stubs(:current_model_name).returns('Thing')
212
+
213
+ @controller.stubs(:parent?).returns(false)
214
+ @controller.stubs(:namespaces).returns([:admin, :main])
215
+ end
216
+
217
+ it "should return the underscored list of namespaces for #url_helper_prefix" do
218
+ @controller.url_helper_prefix.should == "admin_main_"
219
+ end
220
+
221
+ it "should get the namespaced path of current_object with #object_path" do
222
+ @controller.expects(:send).with('admin_main_thing_path', @object)
223
+ @controller.object_path
224
+ end
225
+
226
+ it "should get the namespaced plural path of the current model with #objects_path" do
227
+ @controller.expects(:send).with('admin_main_things_path')
228
+ @controller.objects_path
229
+ end
230
+
231
+ it "should get the edit path of the current model with #edit_object_path" do
232
+ @controller.expects(:send).with('edit_admin_main_thing_path', @object)
233
+ @controller.edit_object_path
234
+ end
235
+
236
+ it "should get the new path of the current model with #new_object_path" do
237
+ @controller.expects(:send).with('new_admin_main_thing_path')
238
+ @controller.new_object_path
239
+ end
240
+ end
241
+
242
+ describe Resourceful::Default::URLs, " for a controller with a parent object and within a namespace" do
243
+ include ControllerMocks
244
+ before :each do
245
+ mock_controller Resourceful::Default::URLs
246
+ @object = stub_model('Thing')
247
+ @controller.stubs(:current_object).returns(@object)
248
+
249
+ @controller.stubs(:current_model_name).returns('Thing')
250
+
251
+ @person = stub_model('Person')
252
+ @controller.stubs(:parent_object).returns(@person)
253
+ @controller.stubs(:parent_name).returns('person')
254
+ @controller.stubs(:parent?).returns(true)
255
+ @controller.stubs(:parent_class_name).returns('Person')
256
+ @controller.stubs(:namespaces).returns([:admin, :main])
257
+ end
258
+
259
+ it "should return the underscored list of namespaces for #url_helper_prefix" do
260
+ @controller.url_helper_prefix.should == "admin_main_"
261
+ end
262
+
263
+ it "should get the namespaced path of current_object with #object_path" do
264
+ @controller.expects(:send).with('admin_main_person_thing_path', @person, @object)
265
+ @controller.object_path
266
+ end
267
+
268
+ it "should get the namespaced plural path of the current model and its parent with #objects_path" do
269
+ @controller.expects(:send).with('admin_main_person_things_path', @person)
270
+ @controller.objects_path
271
+ end
272
+
273
+ it "should get the edit path of the current model with #edit_object_path" do
274
+ @controller.expects(:send).with('edit_admin_main_person_thing_path', @person, @object)
275
+ @controller.edit_object_path
276
+ end
277
+
278
+ it "should get the new path of the current model and its parent with #new_object_path" do
279
+ @controller.expects(:send).with('new_admin_main_person_thing_path', @person)
280
+ @controller.new_object_path
281
+ end
282
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: make_resourceful
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hampton Catlin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-17 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: ! ' Take back control of your Controllers. Make them awesome. Make
15
+ them sleek. Make them resourceful.
16
+
17
+ '
18
+ email: hcatlin@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/make_resourceful.rb
24
+ - lib/resourceful/base.rb
25
+ - lib/resourceful/builder.rb
26
+ - lib/resourceful/default/accessors.rb
27
+ - lib/resourceful/default/actions.rb
28
+ - lib/resourceful/default/callbacks.rb
29
+ - lib/resourceful/default/responses.rb
30
+ - lib/resourceful/default/urls.rb
31
+ - lib/resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb
32
+ - lib/resourceful/generators/resourceful_scaffold/templates/controller.rb
33
+ - lib/resourceful/generators/resourceful_scaffold/templates/fixtures.yml
34
+ - lib/resourceful/generators/resourceful_scaffold/templates/functional_test.rb
35
+ - lib/resourceful/generators/resourceful_scaffold/templates/helper.rb
36
+ - lib/resourceful/generators/resourceful_scaffold/templates/migration.rb
37
+ - lib/resourceful/generators/resourceful_scaffold/templates/model.rb
38
+ - lib/resourceful/generators/resourceful_scaffold/templates/unit_test.rb
39
+ - lib/resourceful/generators/resourceful_scaffold/templates/view__form.haml
40
+ - lib/resourceful/generators/resourceful_scaffold/templates/view_edit.haml
41
+ - lib/resourceful/generators/resourceful_scaffold/templates/view_index.haml
42
+ - lib/resourceful/generators/resourceful_scaffold/templates/view_new.haml
43
+ - lib/resourceful/generators/resourceful_scaffold/templates/view_partial.haml
44
+ - lib/resourceful/generators/resourceful_scaffold/templates/view_show.haml
45
+ - lib/resourceful/maker.rb
46
+ - lib/resourceful/response.rb
47
+ - lib/resourceful/serialize.rb
48
+ - Rakefile
49
+ - Readme.rdoc
50
+ - VERSION
51
+ - spec/accessors_spec.rb
52
+ - spec/actions_spec.rb
53
+ - spec/base_spec.rb
54
+ - spec/builder_spec.rb
55
+ - spec/callbacks_spec.rb
56
+ - spec/integration_spec.rb
57
+ - spec/maker_spec.rb
58
+ - spec/response_spec.rb
59
+ - spec/responses_spec.rb
60
+ - spec/serialize_spec.rb
61
+ - spec/urls_spec.rb
62
+ homepage: http://github.com/hcatlin/make_resourceful
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.6
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: An elegant, structured way to build ActionPack Controllers
86
+ test_files:
87
+ - spec/accessors_spec.rb
88
+ - spec/actions_spec.rb
89
+ - spec/base_spec.rb
90
+ - spec/builder_spec.rb
91
+ - spec/callbacks_spec.rb
92
+ - spec/integration_spec.rb
93
+ - spec/maker_spec.rb
94
+ - spec/response_spec.rb
95
+ - spec/responses_spec.rb
96
+ - spec/serialize_spec.rb
97
+ - spec/urls_spec.rb