Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created March 13, 2009 23:13
Show Gist options
  • Save dchelimsky/78821 to your computer and use it in GitHub Desktop.
Save dchelimsky/78821 to your computer and use it in GitHub Desktop.
class Thing < ActiveRecord::Base
validates_presence_of :name
end
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