search for: recordinvalid

Displaying 20 results from an estimated 59 matches for "recordinvalid".

2007 May 20
9
How to test for exceptions
...rd is invalid" do stub_authorized_login Venue.should_receive(:find).and_return(@venue) @venue.should_receive(:update_attributes!).with("name" => "random text").and_return(false) lambda {post :create, {:venue => @venue}}.should raise_error(ActiveRecord::RecordInvalid) end end describe VenuesController, "on create" do before(:each) do @venue = mock("venue") @venue.stub!(:new_record?).and_return(true) @venue.stub!(:to_param).and_return(''1'') Venue.stub!(:new).and_return(@venue) controller.class.send(:...
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 an image so it should validate fine. Any help would be most welcome -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You...
2006 Nov 22
3
Controller Isolation
...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 controller methods and not @ object.new_record? or @object.valid? to check whether to redirect or render. -- controller -- def create @star = Star.create!(params[:star]) redirect_to star_path(@star) rescue ActiveRec...
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 this, which makes sense but it still fails... it "should re-render new on an invalid record exception" do post :create, :us...
2013 Aug 22
1
How do I deal with ActiveRecord::RecordInvalid: Validation failed:
...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. ActiveRecord::RecordInvalid: Validation failed: Reservation limit reached for this time slot test/models/reservation_test.rb:29:in `block (2 levels) in <class:ReservationTest>'' I was wondering if anyone can give me an ideas of how to deal with this. My test environment is using shoulda, faker, and fact...
2009 Jul 04
12
save! not allowed after validates_uniqueness
...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 understand. The validation should not skip the instance from which the method is called. Please help. Thanks. -- Posted via http://www.ruby-forum.com/.
2012 May 15
1
How to handle ActiveRecord::RecordInvalid
...ontrollers 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 error page: <http://i.stack.imgur.com/YDiNN.png> And here is the category service: def self.create(params) ActiveRecord::Base.transaction do begin category = Category.new(params) decrease_counters(category.id) increase_counters...
2011 Sep 01
2
Custom ActiveRecord Error Message
I''m generating 3 models on 1 controller and i''m rescuing ActiveRecord::RecordInvalid for validation errors, however 2 of the models have the same attribute called "name", and if there''s an error on that field, I wouldn''t know whether that belongs to model A or model B. What then is the best way of modifying the error message of a validation error withou...
2007 Sep 13
2
Failing to raise an exception in a stub
...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, @client.stub!(:save!).and_raise(ActiveRecord::RecordInvalid) The save! call in the controller doesn''t seem to work. I get the following error: ArgumentError in ''ClientsController POST /clients with invalid parameters should show new form again'' wrong number of arguments (0 for 1) /Users/jarkko/Sites/koulutusweb/app/controlle...
2007 Nov 17
7
Down with Lambda!!
...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 => nil}}.should raise_error(ActiveRecord::RecordInvalid) Now it reads like a sentence..much cleaner and less abstract to those of us who are not Ruby wizards (yet) Chatting with other folks and they are hyped on the idea. What do you guys think? Any cha...
2006 Mar 19
2
Functional Testing
...? def destroy begin Question.transaction() do Answer.transaction() do @question = Question.find(params[:id]) for answer in question.answers if !answer.destroy #printf ("Answer %s on Question did not destroy!\n", answer.id.to_s) raise ActiveRecord::RecordInvalid.new(answer), "Error: Answer ID#:".concat(answer.id.to_s).concat(" on Test ID# ").concat(@exam.id.to_s).concat(" failed to destory! <br /> Contact Administrator for help! ") end end if !question.destroy #printf ("Question %s on Section...
2006 Oct 08
9
Organizing tests and mocha expectations
...lude ClientsControllerSpecHelper specify "should render edit form" do setup_controller @client = mock Client.expects(:find).with("1").returns(@client) @client.expects(:attributes=).with("attributes") @client.expects(:save!).raises(ActiveRecord::RecordInvalid.new(stub(:errors => stub(:full_messages => [])))) @controller.expects(:render).with() @controller.expects(:render).with(:action => "edit")\ put :update, :id => 1, :client => "attributes" end end Now, to fit well with RSpec''s methodology,...
2007 May 22
3
Comments wanted about spec''ing out a couple controller methods
...uzzle]) @puzzle.user = @user @media = Media.new(:uploaded_data => params[:media]) Puzzle.transaction do @puzzle.media = @media @puzzle.save! && @media.save! flash[:notice] = "Success!" redirect_to puzzle_path(@puzzle) end rescue ActiveRecord::RecordInvalid => e @media.valid? # force checking of errors even if @puzzle.save! failed flash[:error] = "Problem submitting the One Word Wonder..." render :partial => ''new'', :layout => true end def update @puzzle = Puzzle.find params[:id] Puzzle.transaction...
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 Mar 29
2
save related models from one form
...ty, @person) do @customer.save @identity.save @person.save if(undigestedPassword != params[:passwordconfirm]) @pwdmismatch = true end raise ActiveRecord::RecordInvalid unless @customer.valid? && @identity.valid? && @person.valid? && (@pwdmismatch == false) login(@customer.username, undigestedPassword, "identity") #Login and redirect the user to the selected identity end #end transaction...
2011 Jan 17
4
Factory Girl and attr_accessor with validation
...ry.define :valid_user, :class => User do |u| u.email ''barry.white-J0of1frlU80@public.gmane.org'' u.phone_number ''(925) 555-1212'' u.active true u.tc_check true end It falls over on validation - Validation failed: Tc check must be accepted (ActiveRecord::RecordInvalid) I''ve also tried setting it when called create like Factory.create(:valid_user, :tc_check => true) which has the same result. Any way of setting this before validation so that I can get it to pass the tests? Thanks Adam -- You received this message because you are subscribed to the...
2006 Jul 26
4
create! should return an Active Record object no matter what
...d 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 = Product.create! params[:product] redirect_to :action => "show", :id => @product.id rescue ActiveRecord::RecordInvalid render :action => ''new'' end If it fails @products is nil. You can''t show any errors. Here is my work around. def create @product = Product.create params[:product] @product.save! redirect_to :action => "show", :id => @product.id rescue ActiveR...
2007 Aug 23
6
controller spec with model that validates_uniqueness
...nce.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number => 13554} #model validates_presence_of :name validates_uniqueness_of :name, :allow_nil => true # rspec output ActiveRecord::RecordInvalid in ''ImagesController should update a database record when it receives a PUT'' Validation failed: Name has already been taken, Image number has already been taken It seems AR is not detecting that this is an edit/update that will not cause a uniqueness conflict. I believe th...
2009 Mar 30
2
[Cucumber] Bug with background
...auses an error Scenario: Admin should be able to run a feed # features/admin/manage_feeds.feature:23 Given an admin user Philip exists # features/step_definitions/accounts/creation.steps.rb:66 Validation failed: Login has already been taken, Email has already been taken (ActiveRecord::RecordInvalid) /Users/andy/Sites/mvor/vendor/plugins/object_daddy/lib/object_daddy.rb:210:in `generate!'' /Users/andy/Sites/mvor/vendor/plugins/object_daddy/lib/object_daddy.rb:32:in `spawn'' /Users/andy/Sites/mvor/vendor/plugins/object_daddy/lib/object_daddy.rb:209:in `/^I create a user with...
2010 Dec 30
6
validates_inclusion_of doesn't match constant
...end In another class I do: model = Model.new model.special_feature = :none model.save! Then I got this error: Validation failed: Special feature special_feature {:model=>"Model", :attribute=>"Special feature", :value=>"none"} is not defined (ActiveRecord::RecordInvalid)! But I think it''s defined... I''ve followed some tips to work with enums, so it seems this is the way to work with them, but I''m doing something wrong, any ideas? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk&q...