Re: [rspec-users] Question on SQL exceptions

2009-03-10 Thread James Byrne
James Byrne wrote: > > I do not know what I am doing wrong either. I tried much the same thing > as you suggest last night in the console: Well, whatever I was doing wrong I seem to have fixed it. Things now seem to be working as I intended. -- Posted via http://www.ruby-forum.com/. ___

Re: [rspec-users] Question on SQL exceptions

2009-03-10 Thread James Byrne
Pat Maddox wrote: > > Not sure what your problem is. Here's a gist that demonstrates what > you're trying to do, and works fine. http://gist.github.com/76667 > > Pat I do not know what I am doing wrong either. I tried much the same thing as you suggest last night in the console: >> def my_

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread Pat Maddox
On Mar 9, 2009, at 1:53 PM, James Byrne wrote: Pat Maddox wrote: ActiveRecord doesn't know anything about db constraint errors. If one is violated, the error propagates up in the form of an exception. I realize that, but the exception is of the ActiveRecord:StatementInvalid class, which I

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread Tim Glen
Just a stab in the dark, but I haven't seen any mention of calling save vs. save!. save just puts any errors in the model, save! will raise the exception if there are any errors. That may not be the case for ActiveRecord:StatementInvalid exception, but I thought i'd mention it anyway. I wond

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread James Byrne
Tim Glen wrote: > Just a stab in the dark, but I haven't seen any mention of calling > save vs. save!. save just puts any errors in the model, save! will > raise the exception if there are any errors. That may not be the case > for ActiveRecord:StatementInvalid exception, but I thought i'd mention

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread Tim Glen
ActiveRecord doesn't know anything about db constraint errors. If one is violated, the error propagates up in the form of an exception. I realize that, but the exception is of the ActiveRecord:StatementInvalid class, which I should be able to catch in the controller with a rescue clause.

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread Scott Taylor
On Mar 9, 2009, at 4:53 PM, James Byrne wrote: Pat Maddox wrote: ActiveRecord doesn't know anything about db constraint errors. If one is violated, the error propagates up in the form of an exception. I realize that, but the exception is of the ActiveRecord:StatementInvalid class, which

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread James Byrne
Pat Maddox wrote: > ActiveRecord doesn't know anything about db constraint errors. If one > is violated, the error propagates up in the form of an exception. > I realize that, but the exception is of the ActiveRecord:StatementInvalid class, which I should be able to catch in the controller wit

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread Pat Maddox
ActiveRecord doesn't know anything about db constraint errors. If one is violated, the error propagates up in the form of an exception. Put a validates_uniqueness_of :login_name on your User class, and you'll get the behavior you want. You can keep the db constraint in as a safety net aga

Re: [rspec-users] Question on SQL exceptions

2009-03-09 Thread James Byrne
James Byrne wrote: Q. > To prevent duplicate values in the DBMS I use a unique index on those > columns. I am testing that duplicate values cannot, in fact, be added. > I thought, probably incorrectly, that when #save is called then any > errors are returned to the controller to handle. This is

[rspec-users] Question on SQL exceptions

2009-03-09 Thread James Byrne
To prevent duplicate values in the DBMS I use a unique index on those columns. I am testing that duplicate values cannot, in fact, be added. This is the cucumber scenario: Scenario: The legal name must be unique Given I do have a user named "admin" And the user named "admin" is authe