radiant-templates-extension 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. data/HELP_designer.textile +3 -3
  2. data/README.textile +3 -3
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/app/views/admin/pages/_edit_template.html.haml +1 -2
  6. data/app/views/admin/pages/_switch_templates.html.haml +4 -4
  7. data/app/views/admin/pages/_template_chooser.html.haml +43 -0
  8. data/app/views/admin/templates/index.html.haml +0 -1
  9. data/pkg/radiant-templates-extension-1.0.0.gem +0 -0
  10. data/radiant-templates-extension.gemspec +176 -0
  11. data/templates_extension.rb +1 -1
  12. data/vendor/plugins/make_resourceful/.gitignore +1 -0
  13. data/vendor/plugins/make_resourceful/DEFAULTS +1 -1
  14. data/vendor/plugins/make_resourceful/README +7 -6
  15. data/vendor/plugins/make_resourceful/Rakefile +2 -13
  16. data/vendor/plugins/make_resourceful/VERSION +1 -1
  17. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +1 -8
  18. data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +11 -0
  19. data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +33 -2
  20. data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +63 -7
  21. data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +15 -6
  22. data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +7 -7
  23. data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +6 -6
  24. data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +1 -0
  25. data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +3 -2
  26. data/vendor/plugins/make_resourceful/spec/actions_spec.rb +33 -6
  27. data/vendor/plugins/make_resourceful/spec/integration_spec.rb +22 -22
  28. data/vendor/plugins/make_resourceful/spec/{rspec_on_rails → rspec-rails}/LICENSE +8 -6
  29. data/vendor/plugins/make_resourceful/spec/rspec-rails/redirect_to.rb +113 -0
  30. data/vendor/plugins/make_resourceful/spec/rspec-rails/render_template.rb +90 -0
  31. data/vendor/plugins/make_resourceful/spec/spec_helper.rb +62 -22
  32. data/vendor/plugins/make_resourceful/spec/urls_spec.rb +2 -0
  33. metadata +15 -11
  34. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/redirect_to.rb +0 -81
  35. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/render_template.rb +0 -28
@@ -85,10 +85,10 @@ module Resourceful
85
85
  # For example, if Person has_one Hat,
86
86
  # then in HatsController current_object essentially runs <tt>Person.find(params[:person_id]).hat</tt>.
87
87
  def current_object
88
- @current_object ||= if plural?
89
- current_model.find(params[:id])
88
+ @current_object ||= if !parent? || plural?
89
+ current_model.find(params[:id]) if params[:id]
90
90
  else
91
- parent_object.send(instance_variable_name)
91
+ parent_object.send(instance_variable_name.singularize)
92
92
  end
93
93
  end
94
94
 
@@ -126,7 +126,10 @@ module Resourceful
126
126
  current_model.build(object_parameters)
127
127
  else
128
128
  returning(current_model.new(object_parameters)) do |obj|
129
- obj.send("#{parent_name}_id=", parent_object.id) if singular? && parent?
129
+ if singular? && parent?
130
+ obj.send("#{parent_name}_id=", parent_object.id)
131
+ obj.send("#{parent_name}_type=", parent_object.class.to_s) if polymorphic_parent?
132
+ end
130
133
  end
131
134
  end
132
135
  end
@@ -205,6 +208,11 @@ module Resourceful
205
208
  !!parent_name
206
209
  end
207
210
 
211
+ # Returns whether the parent (if it exists) is polymorphic
212
+ def polymorphic_parent?
213
+ !!polymorphic_parent_name
214
+ end
215
+
208
216
  # Returns the name of the current parent object if a parent id is given, or nil otherwise.
209
217
  # For example, in HatsController where Rack has_many :hats and Person has_many :hats,
210
218
  # if <tt>params[:rack_id]</tt> is given,
@@ -235,20 +243,61 @@ module Resourceful
235
243
  # rather than <tt>@parent_name ||=</tt>. See the source code.
236
244
  #
237
245
  # Finally, note that parents must be declared via Builder#belongs_to.
246
+ #
247
+ # FIXME - Perhaps this logic should be moved to parent?() or another init method
238
248
  def parent_name
239
249
  return @parent_name if defined?(@parent_name)
240
250
  @parent_name = parent_names.find { |name| params["#{name}_id"] }
251
+ if @parent_name.nil?
252
+ # get any polymorphic parents through :as association inspection
253
+ names = params.reject { |key, value| key.to_s[/_id$/].nil? }.keys.map { |key| key.chomp("_id") }
254
+ names.each do |name|
255
+ begin
256
+ klass = name.camelize.constantize
257
+ id = params["#{name}_id"]
258
+ object = klass.find(id)
259
+ if association = object.class.reflect_on_all_associations.detect { |association| association.options[:as] && parent_names.include?(association.options[:as].to_s) }
260
+ @parent_name = name
261
+ @polymorphic_parent_name = association.options[:as].to_s
262
+ @parent_class_name = name.camelize
263
+ @parent_object = object
264
+ break
265
+ end
266
+ rescue
267
+ end
268
+ end
269
+ else
270
+ @parent_class_name = params["#{parent_name}_type"]
271
+ @polymorphic_parent = !@parent_class_name.nil?
272
+ end
273
+ @parent_name
274
+ end
275
+
276
+ def polymorphic_parent_name
277
+ @polymorphic_parent_name
278
+ end
279
+
280
+ # Returns the class name of the current parent.
281
+ # For example, in HatsController where Person has_many :hats,
282
+ # if <tt>params[:person_id]</tt> is given,
283
+ #
284
+ # parent_class_name #=> 'Person'
285
+ #
286
+ # Note that parents must be declared via Builder#belongs_to.
287
+ def parent_class_name
288
+ parent_name # to init @parent_class_name
289
+ @parent_class_name ||= parent_name.nil? ? nil : parent_name.camelize
241
290
  end
242
291
 
243
292
  # Returns the model class of the current parent.
244
293
  # For example, in HatsController where Person has_many :hats,
245
294
  # if <tt>params[:person_id]</tt> is given,
246
295
  #
247
- # parent_models #=> Rack
296
+ # parent_models #=> Person
248
297
  #
249
298
  # Note that parents must be declared via Builder#belongs_to.
250
299
  def parent_model
251
- parent_name.camelize.constantize
300
+ parent_class_name.nil? ? nil : parent_class_name.constantize
252
301
  end
253
302
 
254
303
  # Returns the current parent object for the current object.
@@ -262,7 +311,7 @@ module Resourceful
262
311
  # Note also that the results of this method are cached
263
312
  # so that multiple calls don't result in multiple SQL queries.
264
313
  def parent_object
265
- @parent_object ||= parent_model.find(params["#{parent_name}_id"])
314
+ @parent_object ||= parent_model.nil? ? nil : parent_model.find(params["#{parent_name}_id"])
266
315
  end
267
316
 
268
317
  # Assigns the current parent object, as given by parent_objects,
@@ -272,6 +321,7 @@ module Resourceful
272
321
  # You shouldn't need to use it directly unless you're creating a new action.
273
322
  def load_parent_object
274
323
  instance_variable_set("@#{parent_name}", parent_object) if parent?
324
+ instance_variable_set("@#{polymorphic_parent_name}", parent_object) if polymorphic_parent?
275
325
  end
276
326
 
277
327
  # Renders a 422 error if no parent id is given.
@@ -328,6 +378,9 @@ module Resourceful
328
378
  #
329
379
  # Note that the way this is determined is based on the singularity of the controller name,
330
380
  # so it may yield false positives for oddly-named controllers and need to be overridden.
381
+ #
382
+ # TODO: maybe we can define plural? and singular? as class_methods,
383
+ # so they are not visible to the world
331
384
  def singular?
332
385
  instance_variable_name.singularize == instance_variable_name
333
386
  end
@@ -338,6 +391,9 @@ module Resourceful
338
391
  # Note that the way this is determined is based on the singularity of the controller name,
339
392
  # so it may yield false negatives for oddly-named controllers.
340
393
  # If this is the case, the singular? method should be overridden.
394
+ #
395
+ # TODO: maybe we can define plural? and singular? as class_methods,
396
+ # so they are not visible to the world
341
397
  def plural?
342
398
  !singular?
343
399
  end
@@ -15,14 +15,15 @@ module Resourceful
15
15
  module Actions
16
16
  # GET /foos
17
17
  def index
18
- load_objects
18
+ #load_objects
19
19
  before :index
20
20
  response_for :index
21
21
  end
22
22
 
23
23
  # GET /foos/12
24
24
  def show
25
- load_object
25
+ # NOTE - Moved this call to a more generic place
26
+ #load_object
26
27
  before :show
27
28
  response_for :show
28
29
  rescue
@@ -47,9 +48,17 @@ module Resourceful
47
48
 
48
49
  # PUT /foos/12
49
50
  def update
50
- load_object
51
+ #load_object
51
52
  before :update
52
- if current_object.update_attributes object_parameters
53
+
54
+ begin
55
+ result = current_object.update_attributes object_parameters
56
+ rescue ActiveRecord::StaleObjectError
57
+ current_object.reload
58
+ result = false
59
+ end
60
+
61
+ if result
53
62
  save_succeeded!
54
63
  after :update
55
64
  response_for :update
@@ -70,14 +79,14 @@ module Resourceful
70
79
 
71
80
  # GET /foos/12/edit
72
81
  def edit
73
- load_object
82
+ #load_object
74
83
  before :edit
75
84
  response_for :edit
76
85
  end
77
86
 
78
87
  # DELETE /foos/12
79
88
  def destroy
80
- load_object
89
+ #load_object
81
90
  before :destroy
82
91
  if current_object.destroy
83
92
  after :destroy
@@ -58,7 +58,7 @@ module Resourceful
58
58
  end
59
59
 
60
60
  response_for(:show_fails) do |format|
61
- not_found = Proc.new { render :text => "No item found", :status => 404 }
61
+ not_found = Proc.new { render :text => I18n.t('make_resourceful.show.fails', :default => "No item found"), :status => 404 }
62
62
  format.html &not_found
63
63
  format.js &not_found
64
64
  format.xml &not_found
@@ -66,7 +66,7 @@ module Resourceful
66
66
 
67
67
  response_for(:create) do |format|
68
68
  format.html do
69
- set_default_flash(:notice, "Create successful!")
69
+ set_default_flash :notice, I18n.t('make_resourceful.create.success', :default => "Create successful!")
70
70
  set_default_redirect object_path
71
71
  end
72
72
  format.js
@@ -74,7 +74,7 @@ module Resourceful
74
74
 
75
75
  response_for(:create_fails) do |format|
76
76
  format.html do
77
- set_default_flash :error, "There was a problem!"
77
+ set_default_flash :error, I18n.t('make_resourceful.create.fails', :default => "There was a problem!")
78
78
  render :action => :new, :status => 422
79
79
  end
80
80
  format.js
@@ -82,7 +82,7 @@ module Resourceful
82
82
 
83
83
  response_for(:update) do |format|
84
84
  format.html do
85
- set_default_flash :notice, "Save successful!"
85
+ set_default_flash :notice, I18n.t('make_resourceful.update.success', :default => "Save successful!")
86
86
  set_default_redirect object_path
87
87
  end
88
88
  format.js
@@ -90,7 +90,7 @@ module Resourceful
90
90
 
91
91
  response_for(:update_fails) do |format|
92
92
  format.html do
93
- set_default_flash :error, "There was a problem saving!"
93
+ set_default_flash :error, I18n.t('make_resourceful.update.fails', :default => "There was a problem saving!")
94
94
  render :action => :edit, :status => 422
95
95
  end
96
96
  format.js
@@ -98,7 +98,7 @@ module Resourceful
98
98
 
99
99
  response_for(:destroy) do |format|
100
100
  format.html do
101
- set_default_flash :notice, "Record deleted!"
101
+ set_default_flash :notice, I18n.t('make_resourceful.destroy.success', :default => "Record deleted!")
102
102
  set_default_redirect objects_path
103
103
  end
104
104
  format.js
@@ -106,7 +106,7 @@ module Resourceful
106
106
 
107
107
  response_for(:destroy_fails) do |format|
108
108
  format.html do
109
- set_default_flash :error, "There was a problem deleting!"
109
+ set_default_flash :error, I18n.t('make_resourceful.destroy.fails', :default => "There was a problem deleting!")
110
110
  set_default_redirect :back, :status => :failure
111
111
  end
112
112
  format.js
@@ -65,11 +65,11 @@ module Resourceful
65
65
  # This returns the path for the parent object.
66
66
  #
67
67
  def parent_path(object = parent_object)
68
- instance_route(parent_name, object, 'path')
68
+ instance_route(parent_class_name.underscore, object, 'path')
69
69
  end
70
70
  # Same as parent_path, but with the protocol and hostname.
71
71
  def parent_url(object = parent_object)
72
- instance_route(parent_name, object, 'url')
72
+ instance_route(parent_class_name.underscore, object, 'url')
73
73
  end
74
74
 
75
75
  # This prefix is added to the Rails URL helper names
@@ -98,7 +98,7 @@ module Resourceful
98
98
  #
99
99
  # See also url_helper_prefix.
100
100
  def collection_url_prefix
101
- parent? ? "#{parent_name}_" : ''
101
+ parent? ? "#{parent_class_name.underscore}_" : ''
102
102
  end
103
103
 
104
104
  private
@@ -109,7 +109,7 @@ module Resourceful
109
109
 
110
110
  def nested_object_route(object, type)
111
111
  return object_route(object, type) unless parent?
112
- send("#{url_helper_prefix}#{parent_name}_#{current_model_name.underscore}_#{type}", parent_object, object)
112
+ send("#{url_helper_prefix}#{parent_class_name.underscore}_#{current_model_name.underscore}_#{type}", parent_object, object)
113
113
  end
114
114
 
115
115
  def edit_object_route(object, type)
@@ -125,11 +125,11 @@ module Resourceful
125
125
  end
126
126
 
127
127
  def instance_route(name, object, type, action = nil)
128
- send("#{action ? action + '_' : ''}#{url_helper_prefix}#{name}_#{type}", object)
128
+ send("#{action ? action + '_' : ''}#{url_helper_prefix}#{collection_url_prefix}#{name}_#{type}", *(parent? ? [parent_object, object] : [object]))
129
129
  end
130
130
 
131
131
  def collection_route(name, type, action = nil)
132
- send("#{action ? action + '_' : ''}#{url_helper_prefix || collection_url_prefix}#{name}_#{type}",
132
+ send("#{action ? action + '_' : ''}#{url_helper_prefix}#{collection_url_prefix}#{name}_#{type}",
133
133
  *(parent? ? [parent_object] : []))
134
134
  end
135
135
  end
@@ -75,6 +75,7 @@ module Resourceful
75
75
  helper_method(:object_path, :objects_path, :new_object_path, :edit_object_path,
76
76
  :object_url, :objects_url, :new_object_url, :edit_object_url,
77
77
  :parent_path, :parent_url,
78
+ :nested_object_path, :nested_object_url,
78
79
  :current_objects, :current_object, :current_model, :current_model_name,
79
80
  :namespaces, :instance_variable_name, :parent_names, :parent_name,
80
81
  :parent?, :parent_model, :parent_object, :save_succeeded?)
@@ -77,7 +77,7 @@ describe Resourceful::Default::Accessors, "#current_object on a singular control
77
77
  before :each do
78
78
  mock_controller Resourceful::Default::Accessors
79
79
  @controller.stubs(:plural?).returns(false)
80
- @controller.stubs(:instance_variable_name).returns("post")
80
+ @controller.stubs(:controller_name).returns("posts")
81
81
 
82
82
  @parent = stub('parent')
83
83
  @controller.stubs(:parent_object).returns(@parent)
@@ -86,7 +86,7 @@ describe Resourceful::Default::Accessors, "#current_object on a singular control
86
86
  @object = stub
87
87
  end
88
88
 
89
- it "should look up the instance object of the parent object" do
89
+ it "should return the instance object from parent object" do
90
90
  @parent.expects(:post).returns(@object)
91
91
  @controller.current_object.should == @object
92
92
  end
@@ -342,6 +342,7 @@ describe Resourceful::Default::Accessors, " with no parents" do
342
342
  mock_controller Resourceful::Default::Accessors
343
343
  @controller.stubs(:parents).returns([])
344
344
  @controller.stubs(:current_model_name).returns('Line')
345
+ @controller.stubs(:params).returns({})
345
346
  stub_const 'Line'
346
347
  end
347
348
 
@@ -10,7 +10,7 @@ describe Resourceful::Default::Actions, " index action" do
10
10
  after(:each) { @controller.index }
11
11
 
12
12
  it "should load the object collection" do
13
- @controller.expects(:load_objects)
13
+ #@controller.expects(:load_objects)
14
14
  end
15
15
 
16
16
  it "should call the before :index callback" do
@@ -32,7 +32,7 @@ describe Resourceful::Default::Actions, " show action" do
32
32
  after(:each) { @controller.show }
33
33
 
34
34
  it "should load the instance object" do
35
- @controller.expects(:load_object)
35
+ #@controller.expects(:load_object)
36
36
  end
37
37
 
38
38
  it "should call the before :show callback" do
@@ -44,7 +44,7 @@ describe Resourceful::Default::Actions, " show action" do
44
44
  end
45
45
 
46
46
  it "should run the response for show failing if an exception is raised" do
47
- @controller.stubs(:load_object).raises("Oh no!")
47
+ @controller.stubs(:response_for).with(:show).raises("Oh no!")
48
48
  @controller.expects(:response_for).with(:show_fails)
49
49
  end
50
50
  end
@@ -128,7 +128,7 @@ describe Resourceful::Default::Actions, " successful update action" do
128
128
  after(:each) { @controller.update }
129
129
 
130
130
  it "should load the instance object" do
131
- @controller.expects(:load_object)
131
+ #@controller.expects(:load_object)
132
132
  end
133
133
 
134
134
  it "should call the before :update callback" do
@@ -178,6 +178,33 @@ describe Resourceful::Default::Actions, " unsuccessful update action" do
178
178
  end
179
179
  end
180
180
 
181
+ describe Resourceful::Default::Actions, " unsuccessful update action because of StaleObjectError" do
182
+ include ControllerMocks
183
+ before :each do
184
+ mock_controller Resourceful::Default::Actions
185
+ [:load_object, :before, :after, :object_parameters,
186
+ :save_failed!, :response_for].each(&@controller.method(:stubs))
187
+ @object = stub_model("Thing")
188
+ @object.stubs(:update_attributes).raises(ActiveRecord::StaleObjectError)
189
+ @object.expects(:reload)
190
+ @controller.stubs(:current_object).returns(@object)
191
+ end
192
+
193
+ after(:each) { @controller.update }
194
+
195
+ it "should record the unsuccessful save" do
196
+ @controller.expects(:save_failed!)
197
+ end
198
+
199
+ it "should call the after :update_fails callback" do
200
+ @controller.expects(:after).with(:update_fails)
201
+ end
202
+
203
+ it "should run the response for update failing" do
204
+ @controller.expects(:response_for).with(:update_fails)
205
+ end
206
+ end
207
+
181
208
  describe Resourceful::Default::Actions, " new action" do
182
209
  include ControllerMocks
183
210
  before :each do
@@ -215,7 +242,7 @@ describe Resourceful::Default::Actions, " edit action" do
215
242
  after(:each) { @controller.edit }
216
243
 
217
244
  it "should load the instance object" do
218
- @controller.expects(:load_object)
245
+ #@controller.expects(:load_object)
219
246
  end
220
247
 
221
248
  it "should call the before :edit callback" do
@@ -240,7 +267,7 @@ describe Resourceful::Default::Actions, " successful destroy action" do
240
267
  after(:each) { @controller.destroy }
241
268
 
242
269
  it "should load the instance object" do
243
- @controller.expects(:load_object)
270
+ #@controller.expects(:load_object)
244
271
  end
245
272
 
246
273
  it "should call the before :destroy callback" do
@@ -1,8 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe "ThingsController", "with all the resourceful actions", :type => :integration do
4
- include RailsMocks
5
- #inherit Test::Unit::TestCase
3
+ describe "ThingsController", "with all the resourceful actions" do
4
+
6
5
  before :each do
7
6
  mock_resourceful do
8
7
  actions :all
@@ -21,6 +20,8 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
21
20
  (Resourceful::ACTIONS - Resourceful::MODIFYING_ACTIONS).each(&method(:should_render_html))
22
21
  Resourceful::ACTIONS.each(&method(:should_render_js))
23
22
  Resourceful::ACTIONS.each(&method(:shouldnt_render_xml))
23
+
24
+
24
25
 
25
26
  ## Specs for #index
26
27
 
@@ -32,7 +33,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
32
33
  it "should return a list of objects for #current_objects after GET /things" do
33
34
  Thing.stubs(:find).returns(@objects)
34
35
  get :index
35
- controller.current_objects.should == @objects
36
+ current_objects.should == @objects
36
37
  end
37
38
 
38
39
  it "should assign @things to a list of objects for GET /things" do
@@ -51,7 +52,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
51
52
  it "should return an object for #current_object after GET /things/12" do
52
53
  Thing.stubs(:find).returns(@object)
53
54
  get :show, :id => 12
54
- controller.current_object.should == @object
55
+ current_object.should == @object
55
56
  end
56
57
 
57
58
  it "should assign @thing to an object for GET /things/12" do
@@ -70,7 +71,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
70
71
  it "should return an object for #current_object after GET /things/12/edit" do
71
72
  Thing.stubs(:find).returns(@object)
72
73
  get :edit, :id => 12
73
- controller.current_object.should == @object
74
+ current_object.should == @object
74
75
  end
75
76
 
76
77
  it "should assign @thing to an object for GET /things/12/edit" do
@@ -94,7 +95,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
94
95
  it "should return the new object for #current_object after GET /things/new" do
95
96
  Thing.stubs(:new).returns(@object)
96
97
  get :new
97
- controller.current_object.should == @object
98
+ current_object.should == @object
98
99
  end
99
100
 
100
101
  it "should assign @thing to the new object for GET /things/new" do
@@ -118,7 +119,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
118
119
  it "should return the new object for #current_object after POST /things" do
119
120
  Thing.stubs(:new).returns(@object)
120
121
  post :create
121
- controller.current_object.should == @object
122
+ current_object.should == @object
122
123
  end
123
124
 
124
125
  it "should assign @thing to the new object for POST /things" do
@@ -177,7 +178,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
177
178
  it "should return an object for #current_object after PUT /things/12" do
178
179
  Thing.stubs(:find).returns(@object)
179
180
  put :update, :id => 12
180
- controller.current_object.should == @object
181
+ current_object.should == @object
181
182
  end
182
183
 
183
184
  it "should assign @thing to an object for PUT /things/12" do
@@ -236,7 +237,7 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
236
237
  it "should return an object for #current_object after DELETE /things/12" do
237
238
  Thing.stubs(:find).returns(@object)
238
239
  delete :destroy, :id => 12
239
- controller.current_object.should == @object
240
+ current_object.should == @object
240
241
  end
241
242
 
242
243
  it "should assign @thing to an object for DELETE /things/12" do
@@ -286,7 +287,6 @@ describe "ThingsController", "with all the resourceful actions", :type => :integ
286
287
  end
287
288
 
288
289
  describe "ThingsController", "with several parent objects", :type => :integration do
289
- include RailsMocks
290
290
  before :each do
291
291
  mock_resourceful do
292
292
  actions :all
@@ -309,19 +309,19 @@ describe "ThingsController", "with several parent objects", :type => :integratio
309
309
  it "should find all things on GET /things" do
310
310
  Thing.expects(:find).with(:all).returns(@objects)
311
311
  get :index
312
- controller.current_objects.should == @objects
312
+ current_objects.should == @objects
313
313
  end
314
314
 
315
315
  it "should find the thing with id 12 regardless of scoping on GET /things/12" do
316
316
  Thing.expects(:find).with('12').returns(@object)
317
317
  get :show, :id => 12
318
- controller.current_object.should == @object
318
+ current_object.should == @object
319
319
  end
320
320
 
321
321
  it "should create a new thing without a person on POST /things" do
322
322
  Thing.expects(:new).with('name' => "Lamp").returns(@object)
323
323
  post :create, :thing => {:name => "Lamp"}
324
- controller.current_object.should == @object
324
+ current_object.should == @object
325
325
  end
326
326
 
327
327
  ## Person ids
@@ -331,7 +331,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
331
331
  @person.stubs(:things).returns(@fake_model)
332
332
  @fake_model.stubs(:find).with(:all).returns(@objects)
333
333
  get :index, :person_id => 4
334
- controller.parent_object.should == @person
334
+ controller.instance_eval("parent_object").should == @person
335
335
  assigns(:person).should == @person
336
336
  end
337
337
 
@@ -340,7 +340,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
340
340
  @person.expects(:things).at_least_once.returns(@fake_model)
341
341
  @fake_model.expects(:find).with(:all).returns(@objects)
342
342
  get :index, :person_id => 4
343
- controller.current_objects.should == @objects
343
+ current_objects.should == @objects
344
344
  end
345
345
 
346
346
  it "should find the thing with id 12 if it belongs to the person with id 4 on GET /person/4/things/12" do
@@ -348,7 +348,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
348
348
  @person.expects(:things).at_least_once.returns(@fake_model)
349
349
  @fake_model.expects(:find).with('12').returns(@object)
350
350
  get :show, :person_id => 4, :id => 12
351
- controller.current_object.should == @object
351
+ current_object.should == @object
352
352
  end
353
353
 
354
354
  it "should create a new thing belonging to the person with id 4 on POST /person/4/things" do
@@ -356,7 +356,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
356
356
  @person.expects(:things).at_least_once.returns(@fake_model)
357
357
  @fake_model.expects(:build).with('name' => 'Lamp').returns(@object)
358
358
  post :create, :person_id => 4, :thing => {:name => "Lamp"}
359
- controller.current_object.should == @object
359
+ current_object.should == @object
360
360
  end
361
361
 
362
362
  ## Category ids
@@ -366,7 +366,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
366
366
  @category.stubs(:things).returns(@fake_model)
367
367
  @fake_model.stubs(:find).with(:all).returns(@objects)
368
368
  get :index, :category_id => 4
369
- controller.parent_object.should == @category
369
+ controller.instance_eval("parent_object").should == @category
370
370
  assigns(:category).should == @category
371
371
  end
372
372
 
@@ -375,7 +375,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
375
375
  @category.expects(:things).at_least_once.returns(@fake_model)
376
376
  @fake_model.expects(:find).with(:all).returns(@objects)
377
377
  get :index, :category_id => 4
378
- controller.current_objects.should == @objects
378
+ current_objects.should == @objects
379
379
  end
380
380
 
381
381
  it "should find the thing with id 12 if it belongs to the category with id 4 on GET /category/4/things/12" do
@@ -383,7 +383,7 @@ describe "ThingsController", "with several parent objects", :type => :integratio
383
383
  @category.expects(:things).at_least_once.returns(@fake_model)
384
384
  @fake_model.expects(:find).with('12').returns(@object)
385
385
  get :show, :category_id => 4, :id => 12
386
- controller.current_object.should == @object
386
+ current_object.should == @object
387
387
  end
388
388
 
389
389
  it "should create a new thing belonging to the category with id 4 on POST /category/4/things" do
@@ -391,6 +391,6 @@ describe "ThingsController", "with several parent objects", :type => :integratio
391
391
  @category.expects(:things).at_least_once.returns(@fake_model)
392
392
  @fake_model.expects(:build).with('name' => 'Lamp').returns(@object)
393
393
  post :create, :category_id => 4, :thing => {:name => "Lamp"}
394
- controller.current_object.should == @object
394
+ current_object.should == @object
395
395
  end
396
396
  end