similar to: Machinist - having problems stubbing an after_create filter

Displaying 20 results from an estimated 2000 matches similar to: "Machinist - having problems stubbing an after_create filter"

2010 Feb 01
3
validating both sides of a has_one relationship breaks pickle/machinist tests
A lot has been posted about validation issues with associations, however, I don''t see this issue addressed specifically. ex: class Foo has_one :schedule, :dependent => :destroy validates_presence_of :schedule class Schedule belongs_to :foo validates_presence_of :foo_id this creates a circular dependency that breaks test frameworks like pickle and machinist. At first I was
2009 May 25
4
after_create and has_one association bug?
Hello, I''ve come across an issue that I''m sure is a bug when using after_create with a has_one association, but I''m not 100% certain if I''m missing something. This is pretty much exactly the code I''m using. Two simple classes (Account and Contact) and I create the contact after I create an account (via after_create). I''m not passing in a
2009 Mar 29
2
after_create and after_save
Hi, AFAIK after_create is called after_save if the entry does not exist in the DB. Is there a way to tell if a specific model is new or not in after_save? I have to do something like: def after_save add_to_history ''save'' end def after_create add_to_history ''create'' end However after_save is called when creating too. -- cheers, M.
2006 Aug 17
4
Automatically creating associated records with after_create
Hi all. I am actually using ActiveRecord outside of Rails but I don''t see that it matters for this question. I want to automatically create a registration entry when I add a new user to my application. This works fine, but it''s not automatic: class User < ActiveRecord :: Base has_many :registrations end class Test user = User.new user.registrations.create end
2008 Sep 23
3
calling save in after_create hook
Scenario: I''m creating an image file upload service for my web site. As well as saving the actual file I also need to create a database record for the file. I would like to name the file after the record id, but I also need to save some attributes of the image (width/height/mime_type etc) which I can''t discover until after the file is created. The Problem: 1) The id is not
2006 Aug 14
2
after_create is not being called
Hi all I have the following model: class PhotoGallery < ActiveRecord::Base attr_accessible :title, :description, :file_path, :title_photo_id has_many :photos, :dependent => :destroy belongs_to :title_photo, :class_name => ''Photo'', :foreign_key => ''title_photo_id'' validates_presence_of :title, :description, :file_path
2007 Sep 05
2
after_create callback called twice in test env when using fixtures
All, I''ve been trying to figure out a strange bug in one of my applications that I think I''ve narrowed down to a problem with rails fixtures. It seems as though the after_create callback is being run twice when I save a record. This is only happening a) in the test environment, and b) when there is a fixture file for that table. The test below only prints "Doing
2008 Jun 03
1
after_create callback in subclass
I have a User model with a protected method defined: def set_role(rolename) role = Role.find_by_rolename(rolename) permission = Permission.new permission.role = role permission.user = self permission.save(false) end and a subclass with: after_create set_role(''client'') This always fails for me with the error: undefined method `set_role''
2010 Jun 03
2
creating fixtures for has_many :through
I''m stymied at how to create a fixture that establishes a has_many :through relationship. I''ve watched the railscast at: http://media.railscasts.com/videos/081_fixtures_in_rails_2.mov ... but that''s for HABTM relationships. I''ve read: http://www.ruby-forum.com/topic/145676 but that ultimately doesn''t answer any question. So with no further ado:
2007 Dec 13
16
"Tricks" for testing after_create callback???
I''ve got a model Message, which needs to send an email using action mailer after it''s first saved in the database. I want to pass the model to the mailer which then uses methods on the message model to render the email. So the natural way to do this is in an after_create callback on the Message model. But I can''t see an easy way to test this. Here''s my spec
2007 Feb 05
1
long jumping out of code in specs
I wrote this abomination just now, and wonder if anyone else has had experience with the pattern behind it. In short, I''m specing an after_create hook on an ActiveRecord model, that calls a bunch of private methods. Instead of stubbing all those private methods (which is verboten anyway, as well as impossible because creating the object which owns those methods is what I''m
2007 Mar 17
4
Created_on and updated_on in a non-ActiveRecord model
Hi you all, I have a model simulating an ActiveRecord model, according to the tips stated in [1]. It is simulated because even though I am gonna save the attributes in a file, not in a DB, I still want the validations made by ActiveRecord::Base (see code below). Well, the thing is that I also want the behaviour of the created_on and updated_on columns, that get modified automatically before
2009 Jul 20
9
rake error
When I run rake test:units I get this error: 292 tests, 350 assertions, 2 failures, 13 errors rake aborted! Command failed with status (1): [/usr/local/bin/ruby -I"lib:test" "/ usr/loc...] This error just showed up yesterday --- I have no idea how I caused it. Here is my gem list in case that helps: actionmailer (2.3.2, 2.2.2) actionpack (2.3.2, 2.2.2) activerecord (2.3.2, 2.2.2)
2007 Oct 19
3
Stubbing a Kernel method?
Is it possible to stub a Kernel method? I''m specifically interested in the ''open'' method to test some code using open-uri. I''ve tried: Kernel.should_receive(:open).with(''filename'').and_return(''data'') However, this doesn''t seem to work. Any suggestions would be appreciated. --Paul
2006 Aug 17
0
Re Automatically creating associated records with after_create
I don''t get what class Test is for, or where the registration model is, but remember that registrationS is the collection object. I think you want something like after_create { self.registrations << Registration.new } Cheers, B Gates I want to automatically create a registration entry when I add a new user to my application. This works fine, but it''s not
2011 Aug 17
0
after_create bug in Rails 3
Hi, I realized the order of the after_create callback is dependent on where in the class it is defined. I wrote a blog post about it, but am not sure where in the code one might begin to resolve this issue. I''m hoping someone else might be able to help out or guide me in the right direction: http://ablogaboutcode.com/2011/08/17/after_create-bug-in-rails-3/ Thanks, Pan -- You
2007 Feb 24
0
after_create not creating the right object
I have 2 tables... club and forum, which use the "type" as I''m subclassing the Club and Forum objects. Tables are: clubs: id title type forums: id club_id title type I''ve put an "after_create" callback in the Club as Club has_one Forum: class Club < ActiveRecord::Base after_create :create_forum has_one :forum def self.create_forum # create it
2010 Jan 29
4
requiring records in the DB before testing
Is there any way I can require a small set of data be in the test database before any tests are run? (unit, functional, integration, cucumber, etc) Any way besides using fixtures, that is. Overload a rake task? Modify test_helper? Any ideas? (Simple Case: I have to have a minimal set of user roles defined before any users can be created) -- You received this message because you are subscribed to
2006 Jul 19
0
save without after_save, after_create, after_update?
How to update attribute(s) and save a record instance without triggering the hooks: after_save, after_create, after_update? I know it''s possible with Record.update() but this is dynamic. Only receive the instance, without knowing its class (thus cannot call the class method update()). Or is there a way of knowing the class and calling the class method? Thank you. -- Posted via
2010 Dec 12
5
Fixtures and unit tests - no such file to load
Hello all, I''m having some issues with my test fixtures and unit tests and am hoping somebody has an idea about how to fix it. Background: I have a table in my legacy database called tp_approval_step. For this table I have a fixture called tp_approval_step.yml I have a model called ApprovalProcessStep that uses set_table_name ''tp_approval_step'' In my test file,