Initially it was failing when running the code from within a Cucumber
step definition. In this step definition, I am implementing a Given
step (in part) by calling a method of a model. This method is throwing
the error. In summary, the step definition is as follows:

Given ... do
user = User.create!(...)
member=Member.add_member_for_user(user) <----! error thrown by this
method
...
end

Having experienced the error within Cucumber, I then entered the same
code into 'script/console test' i.e.

>> user=User.create!(...)
>> member=Member.add_member_for_user etc...

The code raised an error again.

If however I run the code in development or by using the development
console or as a standalone Ruby program which makes use of
ActiveRecord and my models, it runs fine.


On 8 May, 14:53, Colin Law <clan...@googlemail.com> wrote:
> Is it failing while running one of your tests (possibly an error in the
> test) or while preparing for the test (possibly a problem with your
> fixtures)?
>
> Colin
>
> 2009/5/8 Lee <lee.longm...@googlemail.com>
>
>
>
> > I have some model code that runs fine in development environment but
> > fails in the test environment.
>
> > In test, the code always fails at the same point with:
>
> > Mysql::Error: Duplicate entry '5-17' for key 'PRIMARY': INSERT INTO
> > `accessibilities_namespaces` (`accessibility_id`, `namespace_id`)
> > VALUES (17, 5) [0m
>
> > accessibilities_namespaces is a join table for HABTM relationships.
>
> > My logging suggests that ActiveRecord tries to insert the same record
> > twice when run in test (but only in test!) which would explain the
> > above error. I am sure that the code does not try to create the same
> > record twice and in any case it runs fine in development mode.
>
> > I have tried running the code using 'script/console test' and it fails
> > here also. Though it does not fail when run in 'script/console
> > [development]'.
>
> > I suspect the problem does not lie with MySQL or ActiveRecord, but
> > something to do with the differences between running in development vs
> > test.
>
> > Any thoughts appreciated. I'm baffled by this.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to