Skip to content

Commit

Permalink
Improved spec coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
pahanix committed Jan 8, 2010
1 parent 6596da0 commit d0455ab
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
56 changes: 56 additions & 0 deletions spec/model/with_defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,61 @@
@user.should respond_to("#{col}=")
end
end

# UserDefault.default_rejected_delegate_columns
# can not be used because it contains :id, :created_at, :updated_at and others
[:parent_id, :lft ].each do |col|
it "should NOT respond_to #{name}" do
@user.should_not respond_to(col)
end

it "should NOT respond_to #{name}=" do
@user.should_not respond_to("#{col}=")
end
end

describe "reading from no contact" do
it "should return nil as firstname" do
@user.firstname.should be_nil
end

it "should return nil as lastname" do
@user.lastname.should be_nil
end
end


describe "reading from existing contact" do
before :each do
@user.build_contact
@user.contact.firstname = "John"
@user.contact.lastname = "Smith"
end

it "should read firstname" do
@user.firstname.should == "John"
end

it "should read lastname" do
@user.lastname.should == "Smith"
end
end

describe "assigning value to delegators" do
it "should initialize association" do
@user.contact.should be_nil
@user.firstname = "John"
@user.contact.should_not be_nil
@user.firstname.should == "John"
end

it "should NOT initialize association second time" do
@user.firstname = "John"
contact_object_id = @user.contact.object_id
@user.lastname = "Smith"
@user.contact.object_id.should == contact_object_id
@user.firstname.should == "John"
end

end
end
6 changes: 5 additions & 1 deletion spec/model/with_mixed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

before :each do
@user = UserMixed.new
@user = UserMixed.new
end

it 'should declare the association' do
Expand All @@ -26,4 +26,8 @@
@user.should respond_to("#{col}=")
end
end

it "should raise NoMethodError for #fullname=" do
lambda { @user.fullname = "John Smith" }.should raise_error(NoMethodError)
end
end

0 comments on commit d0455ab

Please sign in to comment.