factory_girl 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/GETTING_STARTED.md CHANGED
@@ -101,7 +101,7 @@ are defined in files at the following locations:
101
101
  Using factories
102
102
  ---------------
103
103
 
104
- factory\_girl supports several different build strategies: build, create, attributes\_for and stub:
104
+ factory\_girl supports several different build strategies: build, create, attributes\_for and build\_stubbed:
105
105
 
106
106
  ```ruby
107
107
  # Returns a User instance that's not saved
@@ -714,6 +714,16 @@ Calling FactoryGirl.create will invoke both `after_build` and `after_create` cal
714
714
 
715
715
  Also, like standard attributes, child factories will inherit (and can also define) callbacks from their parent factory.
716
716
 
717
+ Multiple callbacks can be assigned to run a block; this is useful when building various strategies that run the same code (since there are no callbacks that are shared across all strategies).
718
+
719
+ ```ruby
720
+ factory :user do
721
+ callback(:after_stub, :before_create) { do_something }
722
+ after(:stub, :create) { do_something_else }
723
+ before(:create, :custom) { do_a_third_thing }
724
+ end
725
+ ```
726
+
717
727
  Modifying factories
718
728
  -------------------
719
729
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (4.0.0)
4
+ factory_girl (4.1.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/NEWS CHANGED
@@ -1,3 +1,7 @@
1
+ 4.1.0 (September 11, 2012)
2
+ Allow multiple callbacks to bind to the same block
3
+ Fix documentation surrounding the stub strategy
4
+
1
5
  4.0.0 (August 3, 2012)
2
6
  Remove deprecated cucumber_steps
3
7
  Remove deprecated alternate syntaxes
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (4.0.0)
4
+ factory_girl (4.1.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 (4.0.0)
4
+ factory_girl (4.1.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 (4.0.0)
4
+ factory_girl (4.1.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -158,17 +158,19 @@ module FactoryGirl
158
158
  @definition.define_constructor(&block)
159
159
  end
160
160
 
161
- def before(name, &block)
162
- callback("before_#{name}", &block)
161
+ def before(*names, &block)
162
+ callback(*names.map {|name| "before_#{name}" }, &block)
163
163
  end
164
164
 
165
- def after(name, &block)
166
- callback("after_#{name}", &block)
165
+ def after(*names, &block)
166
+ callback(*names.map {|name| "after_#{name}" }, &block)
167
167
  end
168
168
 
169
- def callback(name, &block)
170
- FactoryGirl.register_callback(name)
171
- @definition.add_callback(Callback.new(name, block))
169
+ def callback(*names, &block)
170
+ names.each do |name|
171
+ FactoryGirl.register_callback(name)
172
+ @definition.add_callback(Callback.new(name, block))
173
+ end
172
174
  end
173
175
  end
174
176
  end
@@ -1,3 +1,3 @@
1
1
  module FactoryGirl
2
- VERSION = '4.0.0'
2
+ VERSION = '4.1.0'
3
3
  end
@@ -149,3 +149,29 @@ describe "custom callbacks" do
149
149
  FactoryGirl.totally_custom(:user).name.should == "Totally Custom"
150
150
  end
151
151
  end
152
+
153
+ describe 'binding a callback to multiple callbacks' do
154
+ before do
155
+ define_model('User', name: :string)
156
+
157
+ FactoryGirl.define do
158
+ factory :user do
159
+ callback(:before_create, :after_stub) do |instance|
160
+ instance.name = instance.name.upcase
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ it 'binds the callback to creation' do
167
+ FactoryGirl.create(:user, name: 'John Doe').name.should == 'JOHN DOE'
168
+ end
169
+
170
+ it 'does not bind the callback to building' do
171
+ FactoryGirl.build(:user, name: 'John Doe').name.should == 'John Doe'
172
+ end
173
+
174
+ it 'binds the callback to stubbing' do
175
+ FactoryGirl.build_stubbed(:user, name: 'John Doe').name.should == 'JOHN DOE'
176
+ end
177
+ end
@@ -140,6 +140,24 @@ describe FactoryGirl::DefinitionProxy, "adding callbacks" do
140
140
  before { proxy.after(:stub, &callback) }
141
141
  it { should have_callback(:after_stub).with_block(callback) }
142
142
  end
143
+
144
+ context "#after(:stub, :create)" do
145
+ before { proxy.after(:stub, :create, &callback) }
146
+ it { should have_callback(:after_stub).with_block(callback) }
147
+ it { should have_callback(:after_create).with_block(callback) }
148
+ end
149
+
150
+ context "#before(:stub, :create)" do
151
+ before { proxy.before(:stub, :create, &callback) }
152
+ it { should have_callback(:before_stub).with_block(callback) }
153
+ it { should have_callback(:before_create).with_block(callback) }
154
+ end
155
+
156
+ context "#callback(:after_stub, :before_create)" do
157
+ before { proxy.callback(:after_stub, :before_create, &callback) }
158
+ it { should have_callback(:after_stub).with_block(callback) }
159
+ it { should have_callback(:before_create).with_block(callback) }
160
+ end
143
161
  end
144
162
 
145
163
  describe FactoryGirl::DefinitionProxy, "#to_create" do
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: 4.0.0
4
+ version: 4.1.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-08-03 00:00:00.000000000 Z
13
+ date: 2012-09-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport