Created
March 13, 2009 23:13
-
-
Save dchelimsky/78821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Thing < ActiveRecord::Base | |
validates_presence_of :name | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe Thing do | |
describe "with valid attributes" do | |
it "has no errors" do | |
thing = Thing.create!(:name => "slam!!!!!") | |
thing.errors.on(:name).should be_nil | |
end | |
end | |
describe "#save" do | |
it "runs validations and stores errors" do | |
thing = Thing.new | |
thing.save | |
thing.errors.on(:name).should == "can't be blank" | |
end | |
end | |
describe "#save!" do | |
it "runs validations and raises errors" do | |
thing = Thing.new | |
lambda do | |
thing.save! | |
end.should raise_error(ActiveRecord::RecordInvalid) | |
end | |
end | |
describe "#create" do | |
it "runs validations and stores errors" do | |
thing = Thing.create | |
thing.errors.on(:name).should == "can't be blank" | |
end | |
end | |
describe "#create!" do | |
it "runs validations and raises errors" do | |
lambda do | |
Thing.create! | |
end.should raise_error(ActiveRecord::RecordInvalid) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment