Skip to content
Browse files

Match build_stubbed's created_at type to ActiveRecord

Closes #469
  • Loading branch information...
1 parent b8719ff commit af282a178b02ea9cc85b7b0767fce836a76108b4 @aripollak aripollak committed with joshuaclayton
Showing with 12 additions and 2 deletions.
  1. +1 −1 lib/factory_girl/strategy/stub.rb
  2. +11 −1 spec/acceptance/build_stubbed_spec.rb
View
2 lib/factory_girl/strategy/stub.rb
@@ -63,7 +63,7 @@ def update_column(*args)
if created_at_missing_default || result_instance_missing_created_at
result_instance.instance_eval do
def created_at
- @created_at ||= Time.now
+ @created_at ||= Time.now.in_time_zone
end
end
end
View
12 spec/acceptance/build_stubbed_spec.rb
@@ -115,13 +115,23 @@
factory :thing_without_timestamp
end
- Timecop.freeze Time.now
+ Timecop.freeze 2012, 1, 1
end
it "defaults created_at for objects with created_at" do
build_stubbed(:thing_with_timestamp).created_at.should == Time.now
end
+ it "defaults created_at for objects with created_at to the correct time with zone" do
+ original_timezone = ENV['TZ']
+ ENV['TZ'] = 'UTC'
+ Time.zone = 'Eastern Time (US & Canada)'
+
+ build_stubbed(:thing_with_timestamp).created_at.zone.should == 'EST'
+
+ ENV['TZ'] = original_timezone
+ end
+
it "adds created_at to objects who don't have the method" do
build_stubbed(:thing_without_timestamp).should respond_to(:created_at)
end

0 comments on commit af282a1

Please sign in to comment.
Something went wrong with that request. Please try again.