forked from mongodb/mongoid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec and code to use serialized values for changes, to correctly pers…
…ist Date and DateTime fields to mongodb
- Loading branch information
Derick Bailey
committed
Jul 5, 2011
1 parent
978ad66
commit b9d43f0
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'spec_helper' | ||
|
||
describe "Date/Time attributes" do | ||
|
||
context "when a DateTime attribute is updated and persisted" do | ||
let(:user) do | ||
user = User.create! :last_login => 2.days.ago | ||
user.last_login = DateTime.now | ||
user | ||
end | ||
|
||
it "should be read for persistance as a UTC Time" do | ||
user.changes["last_login"].last.class.should == Time | ||
end | ||
|
||
it "should persist with no exceptions thrown" do | ||
user.save! | ||
end | ||
end | ||
|
||
context "when a Date attribute is persisted" do | ||
let(:user) do | ||
user = User.create! :account_expires => 2.years.from_now | ||
user.account_expires = "2/2/2002".to_date | ||
user | ||
end | ||
|
||
it "should be read for persistance as a UTC Time" do | ||
user.changes["account_expires"].last.class.should == Time | ||
end | ||
|
||
it "should persist with no exceptions thrown" do | ||
user.save! | ||
end | ||
end | ||
|
||
end |
This file contains 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