views:

26

answers:

2

From http://github.com/diaspora/diaspora/blob/master/spec/models/profile_spec.rb

describe Profile do
  before do
    @person = Factory.build(:person)
  end

  describe 'requirements' do
    it "should include a first name" do
      @person.profile = Factory.build(:profile,:first_name => nil)
      @person.profile.valid?.should be false
      @person.profile.first_name = "Bob"
      @person.profile.valid?.should be true
    end   
  end
end

But in http://github.com/diaspora/diaspora/blob/master/app/models/profile.rb is validated the presense of both, the first and last name like so validates_presence_of :first_name, :last_name

Why does the above test pass even though a last name isn't specified?

A: 

I suspect the Factory.build(:profile, ...) call creates a profile model with a default first_name and last_name set, unless specified otherwise (by the :first_name => nil in this example).

However that's just an educated guess which I am inferring from the code above and what I see here.

Splash
Beat me to it. :)
randomguy
+1  A: 

last_name is actually specified. The profile is create using the Factory.build, which returns the predefined mock of :profile, which is

Factory.define :profile do |p|
  p.first_name "Robert"
  p.last_name "Grimm"
end
randomguy
Thanks for confirming my guess :)
Splash