GreenSaguaro
GreenSaguaro

Reputation: 3387

FactoryGirl attribute value not populated on ActiveRecord class instance

I have a FactoryGirl factory defining some default values for an ActiveRecord::Base class. All of the values except one are making it to the instantiated class except for one.

Here is my factory:

FactoryGirl.define do
  factory :office, :class => Office do
    open_date '03/01/2011'
    set_up_date '04/28/2011'
    type_code 'D'
  end

  after(:build) do |office|
    puts "Office open_date: #{office.open_date}"
    puts "Office set_up_date: #{office.set_up_date}"
  end
end

Here is my base class:

class Office < ActiveRecord::Base
end

When I do FactoryGirl.build :office, I get the following output:

Office open_date: 2011-01-03 00:00:00 -0500
Office set_up_date:

Both columns are DATE datatypes on the database. For some reason, only open_date is getting populated on the base class. I have not, so far, been able to determine why. Since I am only calling build, I think I can safely assume that there is no kind of interference from a database trigger.

Any ideas what would cause set_up_date to not get populated on the class instance?

Versions:

activemodel (3.2.11)
activerecord (3.2.11)
activerecord-oracle_enhanced-adapter (1.4.1)
activesupport (3.2.11)
factory_girl (4.2.0)

JRuby 1.7.2 (Running Ruby in 1.9 mode)

Thanks

Upvotes: 0

Views: 244

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

Just out of curiousity, would your try set_up_date '28/04/2011' instead of 04/28/2011? It looks like FactoryGirl understands your input as DD/MM/YYYY according to:

Office open_date: 2011-01-03 00:00:00 -0500

See 01-03 not 03-01 there?

Upvotes: 1

Related Questions