Displaying 20 results from an estimated 5000 matches similar to: "Custom ActiveRecord Error Message"
2007 Aug 08
5
Can''t seem to spec a ActiveRecord::RecordInvalid exception properly...
1 def create
2 @user = User.new(params[:user])
3 @user.save!
4 self.current_user = @user
5 redirect_to user_path(@user)
6 flash[:notice] = "Thanks for signing up!"
7 rescue ActiveRecord::RecordInvalid
8 render :action => ''new''
9 end
I can''t seem to properly spec this out. I am trying numerous things, the
latest one is
2007 May 20
9
How to test for exceptions
Hi folks,
I''m in the process of converting a Test::Unit functional test to RSpec, but I''ve run into a slight problem. I tried looking through the documentation but I still don''t know what I missed.
Thanks in advance,
Blake
describe VenuesController, "on update" do
before(:each) do
@venue = mock("venue")
2009 Jan 30
2
rescue ActiveRecord::RecordInvalid
Hi all,
I am using is_attachment plugin, but I will always end up with this
error:
RuntimeError in PostsController#create
BLAH
which was caused by:
version.filename = file_name_for_version(version_name)
begin
version.save!
rescue ActiveRecord::RecordInvalid
raise "BLAH"
end
end
RecordInvalid was raised by save! because is invalid.
Does anyone know why? I am uploading
2006 Oct 08
9
Organizing tests and mocha expectations
I''m simultaneously getting into using Mocha and RSpec-style tests
(courtesy of the simply_bdd plugin) and I''m struggling with some
issues while trying to organize my specs/test. Here''s a code example
illustrating the problem:
context "update cliient invalid data" do
include ClientsControllerSpecHelper
specify "should render edit form" do
2013 Aug 22
1
How do I deal with ActiveRecord::RecordInvalid: Validation failed:
Hello all,
I am currently writing model tests in rails 4. I am attempting to add an
error to a reservation object if the total number of reservations for a
given date and time has reached a pre-determined limit.
When my test runs, it is hitting the appropriate code but it is raising the
following error as opposed to just giving me an error in the object that I
can use.
2005 Dec 21
10
Investigating Unicode. Take 2, with nastities and allegations.
Well, I see that my last email hasn''t generated any reaction from the
Rails core team. It looks like all of them are the happy users of
"plain text" (which, as we know by now, doesn''t exist, but still).
I apologize in advance for the sore bitterness of this message but I
see that the Rails-core STILL, despite all of the efforts, sees these
issues as something
2012 May 15
1
How to handle ActiveRecord::RecordInvalid
I''m new to Rails. I''m using Service layer to keep my controllers thin. All
my service layer files are located in app/services/domain,
app/services/application and app/services/infrastructure. I''m using
services in active admin controller section. When validation fail it can''t
redirect correctly, it keeps throwing me ActiveRecord::RecordInvalid. Here
is the
2008 Feb 27
8
ActiveRecord validation messages not I18N-friendly and enforces grammar
ActiveRecord validation messages are currently not I18N-friendly.
Specifically, I''m referring to the fact that it enforces a certain
grammar, namely the beginning of the message must consist of the field
name. For example:
validates_presence_of :name, :message => "can''t be blank."
...generates the message "Name can''t be blank". This grammar
2006 Nov 22
3
Controller Isolation
Hi,
I have a project that I had running under rspec 0.6.x and recently upgraded
to 0.7.2.
I am trying to isolate my controllers from the database as I go through and
change all the specs to run under 0.7.2.
I am having a problem where I need to make the create! method return the
mocked object as well as raise RecordInvalid exception. Is this at all
possible?
I use the rescue statement in my
2009 Oct 09
0
ActiveRecord::Errors#full_messages changes in 2.3.4
After upgrading our application from Rails 2.3.2 to 2.3.4 all our
error messages appeared as "{{attribute}} {{message}}" (literally).
Since we noticed this problem short before a release and hadn''t enough
time to look deeper into it we fixed it by using the "old"
full_messages method that was present in 2.3.2
So today I started reading up on what exactly has changed,
2006 Mar 19
2
Functional Testing
Hey all,
I have a many-to-many relationship (Questions
has_and_belongs_to_many Answers), and when I destroy
the Question (the one) I also destroy all the Answers
(the many).
Since the following doesn''t seem to work for
has_and_belongs_to_many:
class Question < AR::Base...
has_and_belongs_to_many :answers, :dependent =>
:destroy
end
I have this embedded in a transaction block
2007 Nov 17
7
Down with Lambda!!
Rspec is all about using natural language to define behavior. In this
context, I feel that lambda is sorely out of place. I was chatting on
#irc and a pal of mine (wycats) proposed an interesting alternative:
alias_method :doing, :lambda
so instead of something like
lambda {post :create, {:title => nil}}.should
raise_error(ActiveRecord::RecordInvalid)
we get
doing {post :create, {:title
2007 Sep 13
2
Failing to raise an exception in a stub
I''ve come across rather strange behaviour when trying to raise an
exception in a stubbed method.
I''m speccing the behaviour of a Rails create action, where I''m using
save! to catch failed saves. In the case of working save, I''m using
the following stub:
@client.stub!(:save!).and_return(true)
which works fine.
However, in the negative case,
2006 Mar 29
2
save related models from one form
I have three tables customers, indentities and people. I hav ecreated
models for them. The are connected with foreign keys and
has_many/belongs_to in this fashion:
customers has_many: identities
identities belongs_to: customer
identities has_many: people
people belongs_to: identities
Now, I have a form in which I would like to create db entries for the
three tables. customers have a password
2007 May 22
3
Comments wanted about spec''ing out a couple controller methods
(oops, accidentally sent this to the rspec-devel list, sorry about that)
Could someone help me spec out these Rails controller methods? I
don''t know where to get started, especially with the transaction
stuff. Or, if anyone else could suggest ways I could improve the
code, that would be great as well.
Puzzle has_one Media. Both are AR model objects.
class PuzzlesController <
2009 Jul 04
12
save! not allowed after validates_uniqueness
I have this in a model
validates_uniqueness_of :aspect, :scope => :user_id
In an instance method of the same model I have "save!" but I don''t touch
the :aspect attribute in that instance method at all.
Whenever that save! command is run however I get this error:
ActiveRecord::RecordInvalid: Validation failed: Aspect has
already been taken
I don''t
2007 Aug 07
4
Problems with raising errors on a mocked object
I''m trying to mock a object to raise a certain error. By doing so I
get a ArgumentError on ActiveRecord''s save! method:
http://pastie.caboo.se/85628
I''ve tried to debug it but just can''t seem to find what I''m doing
wrong. Any help is greatly appreciated.
Cheers,
Eivind Uggedal
2006 Jul 26
4
create! should return an Active Record object no matter what
I just using the bang versions of save and create after seeing Rick
(technoweenie) use it in his code. I like it much better.
I have a problem with the create! method. It doesn''t return an Active
Record object if it fails. That means you can''t display the errors on
the object. Whats the point than?
Here is a broken example that should work.
def create
@product =
2011 Jan 17
4
Factory Girl and attr_accessor with validation
I have a problem with a recent change to one of my models when created
via Factory.create.
class User < ActiveRecord::Base
attr_accessor :tc_check
validates :tc_check, :presence => true, :acceptance => true
...
end
The following definition fails, when calling
Factory.create(:valid_user)
Factory.define :valid_user, :class => User do |u|
u.email
2010 Sep 23
7
errors.add, setting the whole message
Hi all. I have an attribute, job_role_id_short, that is being set in a
form. This field has a custom validation on it, which does this if it
fails:
self.errors.add(:job_role_id_short, "cannot be blank")
I want to add the error onto the attribute, so that the form builder
will wrap the field in a fieldWithErrors div. However, the error it
generates says "Job Role Short cannot