I’m trying to write a helper for Scriptaculous’ InPlaceCollectionEditor
component. I’ve already submitted a patch
( 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

class Section < ActiveRecord::Base
has_many :posts

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 = [ => 1, :name => ‘News’), => 2, :name => ‘Gossip’), => 3, :name => ‘Slander’)
@post = => ‘1’, :title => ‘Foo’, :section =>

@controller = do
def url_for(options, *parameters_for_method_reference)
url = “
url << options[:action].to_s if options and options[:action]
@controller =

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

def object
@object || @template_object.instance_variable_get("@#{@object_name}")

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:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs