factory_girl 3.4.2 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (3.4.2)
4
+ factory_girl (3.5.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/NEWS CHANGED
@@ -1,4 +1,8 @@
1
- 3.4.2 (June 12, 2012)
1
+ 3.5.0 (June 22, 2012)
2
+ Allow created_at to be set when using build_stubbed
3
+ Deprecate FactoryGirl step definitions
4
+
5
+ 3.4.2 (June 19, 2012)
2
6
  Fix bug in traits with callbacks called implicitly in factories whose
3
7
  callbacks trigger multiple times
4
8
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.4.2)
4
+ factory_girl (3.5.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.4.2)
4
+ factory_girl (3.5.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.4.2)
4
+ factory_girl (3.5.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  # @api private
2
4
  module FactoryGirlStepHelpers
3
5
  def convert_human_hash_to_attribute_hash(human_hash, associations = [])
@@ -109,6 +111,8 @@ FactoryGirl.factories.each do |factory|
109
111
  end
110
112
 
111
113
  Given /^the following (?:#{human_name}|#{human_name.pluralize}) exists?:?$/i do |table|
114
+ ActiveSupport::Deprecation.warn %{The step 'Given the following #{human_name} exists:' is deprecated and will be removed in 4.0}
115
+
112
116
  table.hashes.each do |human_hash|
113
117
  attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)
114
118
  FactoryGirl.create(factory.name, attributes)
@@ -116,10 +120,14 @@ FactoryGirl.factories.each do |factory|
116
120
  end
117
121
 
118
122
  Given /^an? #{human_name} exists$/i do
123
+ ActiveSupport::Deprecation.warn %{The step 'Given a #{human_name} exists' is deprecated and will be removed in 4.0}
124
+
119
125
  FactoryGirl.create(factory.name)
120
126
  end
121
127
 
122
128
  Given /^(\d+) #{human_name.pluralize} exist$/i do |count|
129
+ ActiveSupport::Deprecation.warn %{The step 'Given #{count} #{human_name.pluralize} exist' is deprecated and will be removed in 4.0}
130
+
123
131
  FactoryGirl.create_list(factory.name, count.to_i)
124
132
  end
125
133
 
@@ -127,10 +135,14 @@ FactoryGirl.factories.each do |factory|
127
135
  human_column_name = attribute_name.downcase.gsub('_', ' ')
128
136
 
129
137
  Given /^an? #{human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
138
+ ActiveSupport::Deprecation.warn %{The step 'Given a #{human_name} exists with a #{human_column_name} of "#{value}"' is deprecated and will be removed in 4.0}
139
+
130
140
  FactoryGirl.create(factory.name, attribute_name => value)
131
141
  end
132
142
 
133
143
  Given /^(\d+) #{human_name.pluralize} exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value|
144
+ ActiveSupport::Deprecation.warn %{The step 'Given #{count} #{human_name.pluralize} exists with a #{human_column_name} of "#{value}"' is deprecated and will be removed in 4.0}
145
+
134
146
  FactoryGirl.create_list(factory.name, count.to_i, attribute_name => value)
135
147
  end
136
148
  end
@@ -22,15 +22,12 @@ module FactoryGirl
22
22
 
23
23
  def stub_database_interaction_on_result(result_instance)
24
24
  result_instance.id = next_id
25
+
25
26
  result_instance.instance_eval do
26
27
  def persisted?
27
28
  !new_record?
28
29
  end
29
30
 
30
- def created_at
31
- @created_at ||= Time.now
32
- end
33
-
34
31
  def new_record?
35
32
  id.nil?
36
33
  end
@@ -55,6 +52,17 @@ module FactoryGirl
55
52
  raise 'stubbed models are not allowed to access the database'
56
53
  end
57
54
  end
55
+
56
+ created_at_missing_default = result_instance.respond_to?(:created_at) && !result_instance.created_at
57
+ result_instance_missing_created_at = !result_instance.respond_to?(:created_at)
58
+
59
+ if created_at_missing_default || result_instance_missing_created_at
60
+ result_instance.instance_eval do
61
+ def created_at
62
+ @created_at ||= Time.now
63
+ end
64
+ end
65
+ end
58
66
  end
59
67
  end
60
68
  end
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '3.4.2'
2
+ VERSION = '3.5.0'
3
3
  end
@@ -102,3 +102,38 @@ describe "calling `build_stubbed` with a block" do
102
102
  end.should == expected
103
103
  end
104
104
  end
105
+
106
+ describe "defaulting `created_at`" do
107
+ include FactoryGirl::Syntax::Methods
108
+
109
+ before do
110
+ define_model('ThingWithTimestamp', created_at: :datetime)
111
+ define_model('ThingWithoutTimestamp')
112
+
113
+ FactoryGirl.define do
114
+ factory :thing_with_timestamp
115
+ factory :thing_without_timestamp
116
+ end
117
+
118
+ Timecop.freeze Time.now
119
+ end
120
+
121
+ after { Timecop.return }
122
+
123
+ it "defaults created_at for objects with created_at" do
124
+ build_stubbed(:thing_with_timestamp).created_at.should == Time.now
125
+ end
126
+
127
+ it "adds created_at to objects who don't have the method" do
128
+ build_stubbed(:thing_without_timestamp).should respond_to(:created_at)
129
+ end
130
+
131
+ it "allows overriding created_at for objects with created_at" do
132
+ build_stubbed(:thing_with_timestamp, created_at: 3.days.ago).created_at.should == 3.days.ago
133
+ end
134
+
135
+ it "doesn't allow setting created_at on an object that doesn't define it" do
136
+ expect { build_stubbed(:thing_without_timestamp, :created_at => Time.now) }.to
137
+ raise_error(NoMethodError, /created_at=/)
138
+ end
139
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-20 00:00:00.000000000 Z
13
+ date: 2012-06-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport