Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created March 24, 2010 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacquescrocker/342856 to your computer and use it in GitHub Desktop.
Save jacquescrocker/342856 to your computer and use it in GitHub Desktop.
require "spec_helper"
describe Mongoid::Document do
before do
Dog.delete_all
end
describe "changed?" do
context "newly created model" do
before do
@dog = Dog.new
end
it "should not be dirty when initialized" do
@dog.should_not be_changed
end
it "should be dirty after setting name" do
@dog.name = "Fido"
@dog.should be_changed
end
it "should not be dirty after saving" do
@dog.name = "Fido"
@dog.save
@dog.should_not be_changed
end
end
context "existing model" do
before do
Dog.create!(:name => "Rover")
@dog = Dog.where(:name => "Rover").first
end
it "should not be dirty after retrieving" do
@dog.should_not be_changed
end
it "should be dirty after changing name" do
@dog.name = "Rover2"
@dog.should be_changed
end
it "should not be dirty after saving" do
@dog.name = "Rover2"
@dog.save
@dog.should_not be_changed
end
end
end
end
class Dog
include Mongoid::Document
field :name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment