Hi,
I’m trying to write a helper for Scriptaculous’ InPlaceCollectionEditor
component. I’ve already submitted a patch
(http://dev.rubyonrails.org/ticket/4302). This was a drunk patch; it
needs a bit of work (Don’t drink & code!). So far I’ve gotten it to work
correctly with normal collections, but I want to use it for belongs_to
relations as well.
I want to build a test case for the in_place_collection_editor field for
which I need to know how to do the following (in rails core trunk):
How do I simulate a controller?
How do I simulate an instance variable on that controller?
How do I simulate an Array of ActiveRecord instances? Can this array be
loaded from fixtures?
I basically want to do the following:
The model:
class Post < ActiveRecord::Base
belongs_to :section
end
class Section < ActiveRecord::Base
has_many :posts
end
There would be a “post” instance variable set on the controller.
I’ve tried setting this up as I’ve seen in other tests (using structs)
as such:
def setup
@sections = [
Section.new(:id => 1, :name => ‘News’),
Section.new(:id => 2, :name => ‘Gossip’),
Section.new(:id => 3, :name => ‘Slander’)
]
@post = Post.new(:id => ‘1’, :title => ‘Foo’, :section =>
@sections[0])
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
url = “http://www.example.com/”
url << options[:action].to_s if options and options[:action]
url
end
end
@controller = @controller.new
end
But I’m not able to use this setup as ActionView::Helpers::InstanceTag
uses a method of CGI to get to the instance variable set on the
controller:
def object
@object || @template_object.instance_variable_get(“@#{@object_name}”)
end
Also the structs don’t seem to behave as I expected them to (they don’t
seem to respond to .send, nor am I able to access properties), weird
thing is that ActiveRecord objects do behave.
I’d like to be able to develop this using tests. When I’m developing
this as a plugin it’s a PITA to have to restart the server for the
changes to reload.
Anybody interested in the code (in plugin form) can check it out from: