John Small wrote:> I''m using ActiveResouce objects which don''t have a
corresponding
> ActiveRecord object in the DB because they''re acting as a front
end to a
> legacy Windows application which can read and write REST type XML.
>
> That works fine, but when I try to do some unit testing
> thenActiveSupport::TestCase when it''s setting up will try to
delete
> everything in the tables corresponding to ActiveRecords that it knows
> about. Which it should do in preparation to loading fixtures. But in the
> case of ActiveResources there''s no corresponding table, so it
tries to
> delete all records in a table, with the name that corresponds to the
> ActiveResource, and then fails because it''s not there.
>
> E.g. I have an ActiveResouce defined as
>
> class ChoiceCustomers < ActiveResource::Base
> etc
> end
>
> Now when I try to run the unit test ChoiceCustomerTest <
> ActiveSupport::TestCase
>
> even though there''s nothing in it apart from the default test,
then I
> get an error from the database when it tries to "delete from
> choice_customers" because there''s no corresponding table.
>
> How can I make sure that ActiveSupport::TestCase doesn''t regard
> ActiveResources as ActiveRecords?
Problem solved!
When you create a new resource via script/generate resource. It doesn''t
actually create a resource, it creates an ActiveRecord with associated
controller. So I went in an changed <ActiveRecord::Base to
<ActiveResource::Base in the model file. But...
The generator has also created a dummy fixture.yml in fixtures. So when
you run tests it tries to delete all records from the corresponding
table name it infers from the name of the fixture file. In the case of a
client only ActiveResource application, there isn''t one so it fails.
All I had to do was removed the dummy fixture file and it''s now fine.
John Small
--
Posted via http://www.ruby-forum.com/.