Permalink
Browse files

When creating a stubbed model, assign created_at

Closes issue 32 from factory_girl_rails
  • Loading branch information...
1 parent 661e8ff commit 00503eec6c11c87e842abf1c1a96a185d8c0e1d2 @joshuaclayton joshuaclayton committed Sep 2, 2011
View
@@ -68,6 +68,7 @@ GEM
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
term-ansicolor (1.0.6)
+ timecop (0.3.5)
tzinfo (0.3.29)
yard (0.7.2)
@@ -86,4 +87,5 @@ DEPENDENCIES
rcov
rspec (~> 2.0)
sqlite3-ruby
+ timecop
yard
View
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("rspec", "~> 2.0")
s.add_development_dependency("cucumber", "~> 1.0.0")
+ s.add_development_dependency("timecop")
s.add_development_dependency("rcov")
s.add_development_dependency("aruba")
s.add_development_dependency("mocha")
@@ -50,6 +50,7 @@ GEM
sqlite3 (>= 1.3.3)
term-ansicolor (1.0.5)
test-unit (2.3.0)
+ timecop (0.3.5)
yard (0.7.2)
PLATFORMS
@@ -68,4 +69,5 @@ DEPENDENCIES
rspec (~> 2.0)
sqlite3-ruby
test-unit (~> 2.3.0)
+ timecop
yard
@@ -49,6 +49,7 @@ GEM
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
term-ansicolor (1.0.5)
+ timecop (0.3.5)
yard (0.7.2)
PLATFORMS
@@ -66,4 +67,5 @@ DEPENDENCIES
rcov
rspec (~> 2.0)
sqlite3-ruby
+ timecop
yard
@@ -58,6 +58,7 @@ GEM
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
term-ansicolor (1.0.5)
+ timecop (0.3.5)
tzinfo (0.3.28)
yard (0.7.2)
@@ -76,4 +77,5 @@ DEPENDENCIES
rcov
rspec (~> 2.0)
sqlite3-ruby
+ timecop
yard
@@ -68,6 +68,7 @@ GEM
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
term-ansicolor (1.0.6)
+ timecop (0.3.5)
tzinfo (0.3.29)
yard (0.7.2)
@@ -86,4 +87,5 @@ DEPENDENCIES
rcov
rspec (~> 2.0)
sqlite3-ruby
+ timecop
yard
@@ -12,6 +12,10 @@ def persisted?
!new_record?
end
+ def created_at
+ @created_at ||= Time.now
+ end
+
def new_record?
id.nil?
end
@@ -13,9 +13,21 @@
FactoryGirl::Proxy::Stub
context "asking for a result" do
+ before { Timecop.freeze(Time.now) }
+ after { Timecop.return }
+
it { subject.result(nil).should_not be_new_record }
it { subject.result(nil).should be_persisted }
+ it "assigns created_at" do
+ created_at = subject.result(nil).created_at
+ created_at.should == Time.now
+
+ Timecop.travel(150000)
+
+ subject.result(nil).created_at.should == created_at
+ end
+
[:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
it "raises when attempting to connect to the database by calling #{database_method}" do
expect do
View
@@ -8,6 +8,7 @@
require 'factory_girl'
require "mocha"
require "bourne"
+require "timecop"
Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }

0 comments on commit 00503ee

Please sign in to comment.