I forgot to add -
this is only an issue with Spork and Cucumber. Rspec and Spork run
fine, and before I got Spork working (I think) this was working with
Cucumber.
I think it *may* have something to do with where I am loading the
Factories or "require 'factory_girl'"
I tried to copy the layout from the RSpec spec_helper.rb. This is how
my features/support/env.rb looks like:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/
environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't
want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'factory_girl'
Capybara.default_selector = :css
ActionController::Base.allow_rescue = false
Cucumber::Rails::World.use_transactional_fixtures = true
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
end
Spork.each_run do
require 'factory_girl_rails'
Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/
*.rb')).each {|f| require f }
end
On Jan 25, 2:42 am, adam <[email protected]> wrote:
> 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.