Override parent accessor in should_be_restful ?

1 view
Skip to first unread message

Kevin Fullerton

unread,
Feb 21, 2008, 2:06:04 PM2/21/08
to sho...@googlegroups.com
Hi,

Following on from my earlier mail, it may be worth being able to override the parent accessor name (but not the parent object name) in the
should_be_restful tests.

An example is as such, I have the following ActiveRecord polymorphic association setup

class Customer < ActiveRecord::Base
has_many :addresses, :as => :addressable
end
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end

I'm using resource_controller in my controllers, but if I run the following functional test on the AddressesController

class AddressesControllerTest < ActionController::TestCase
context "An address instance" do
setup do
@address = Address.find(:first)
end

should_be_restful do |resource|
resource.parent = :customer
end
end
end

It errors on 37 tests - all the errors are regarding undefined method 'customer' which is correct - the object at the Address level is called
addressable - to support this I'd want the test to be defined as

should_be_restful do |resource|
resource.parent = :customer
resource.parent_class = :addressable
end

This way it would still use customer_address_url for the tests, but would pass @address.addressable,@address as the parameters which would work.

I'll take a look at the code to see if I can see an easy way of adding this functionality.

Many thanks

Kevin

Reply all
Reply to author
Forward
0 new messages