I am having a strange problem with FactoryGirl, Spork and Cucumber.
It seems to be happening when on a 'before_validation' hook another
model object is created and saved.

Below is a cut down version of the model in question. When it is
created via FactoryGirl, I get this error:

Country(#28734490) expected, got Country(#28417320)
(ActiveRecord::AssociationTypeMismatch)

class TuteonParent < ActiveRecord::Base

  has_one :address, :as => :addressable
  has_one :fs_parent_profile

  accepts_nested_attributes_for :fs_parent_profile, :address

  validates_presence_of :address
  validates_associated :address

  validates_presence_of :core_profile
  validates_associated :core_profile

  validates_presence_of :fs_parent_profile
  validates_associated :fs_parent_profile

  before_validation :create_fs_parent_profile

  def create_fs_parent_profile

    fs_parent_profile = FsParentProfile.new(
      :state => address.country.name,
      :curriculum_state => address.country.name,
      :country => address.country,
      :fs_curriculum_country =>
FsCurriculumCountry.find_by_country_id(address.country.id)
    )

    self.fs_parent_profile = fs_parent_profile
  end

... and the simplified Factory definition is as follows:

Factory.define :valid_parent, :class => Parent do |p|

  tp.address { Factory.create(:address) }

end

If anyone can shed some light on this would be much appreciated!
Thank you

Adam

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to