testingrspecmongomappermocha.jsdiaspora

Why doesn't this test in the Diaspora app fail?


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?


Solution

  • 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.