factory_girl 2.1.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.travis.yml +3 -0
  2. data/Changelog +9 -0
  3. data/GETTING_STARTED.md +47 -16
  4. data/Gemfile.lock +10 -9
  5. data/gemfiles/2.1.gemfile.lock +2 -1
  6. data/gemfiles/2.3.gemfile.lock +2 -1
  7. data/gemfiles/3.0.gemfile.lock +2 -1
  8. data/gemfiles/3.1.gemfile.lock +2 -1
  9. data/lib/factory_girl.rb +6 -3
  10. data/lib/factory_girl/attribute/static.rb +8 -0
  11. data/lib/factory_girl/attribute_list.rb +20 -12
  12. data/lib/factory_girl/callback.rb +30 -0
  13. data/lib/factory_girl/declaration.rb +19 -0
  14. data/lib/factory_girl/declaration/association.rb +17 -0
  15. data/lib/factory_girl/declaration/dynamic.rb +16 -0
  16. data/lib/factory_girl/declaration/implicit.rb +23 -0
  17. data/lib/factory_girl/declaration/static.rb +16 -0
  18. data/lib/factory_girl/definition_proxy.rb +6 -6
  19. data/lib/factory_girl/factory.rb +63 -79
  20. data/lib/factory_girl/proxy.rb +7 -11
  21. data/lib/factory_girl/proxy/attributes_for.rb +1 -0
  22. data/lib/factory_girl/proxy/build.rb +1 -0
  23. data/lib/factory_girl/proxy/stub.rb +1 -0
  24. data/lib/factory_girl/syntax/default.rb +4 -2
  25. data/lib/factory_girl/syntax/vintage.rb +1 -1
  26. data/lib/factory_girl/trait.rb +12 -4
  27. data/lib/factory_girl/version.rb +1 -1
  28. data/spec/acceptance/callbacks_spec.rb +7 -1
  29. data/spec/acceptance/modify_inherited_spec.rb +52 -0
  30. data/spec/acceptance/syntax/vintage_spec.rb +19 -7
  31. data/spec/factory_girl/attribute_list_spec.rb +18 -45
  32. data/spec/factory_girl/callback_spec.rb +41 -0
  33. data/spec/factory_girl/{attribute → declaration}/implicit_spec.rb +16 -11
  34. data/spec/factory_girl/definition_proxy_spec.rb +16 -12
  35. data/spec/factory_girl/factory_spec.rb +43 -34
  36. data/spec/factory_girl/proxy/create_spec.rb +7 -9
  37. data/spec/factory_girl/proxy_spec.rb +26 -39
  38. data/spec/support/shared_examples/proxy.rb +1 -1
  39. metadata +137 -114
  40. data/lib/factory_girl/attribute/callback.rb +0 -14
  41. data/lib/factory_girl/attribute/implicit.rb +0 -39
  42. data/lib/factory_girl/attribute/trait.rb +0 -22
  43. data/spec/factory_girl/attribute/callback_spec.rb +0 -22
@@ -1,14 +0,0 @@
1
- module FactoryGirl
2
- class Attribute #:nodoc:
3
- class Callback < Attribute #:nodoc:
4
- def initialize(name, block)
5
- @name = name.to_sym
6
- @block = block
7
- end
8
-
9
- def add_to(proxy)
10
- proxy.add_callback(name, @block)
11
- end
12
- end
13
- end
14
- end
@@ -1,39 +0,0 @@
1
- module FactoryGirl
2
- class Attribute
3
-
4
- class Implicit < Attribute
5
- def initialize(name, factory = nil)
6
- super(name)
7
- @factory = factory
8
- end
9
-
10
- def add_to(proxy)
11
- implementation.add_to(proxy)
12
- end
13
-
14
- def association?
15
- implementation.association?
16
- end
17
-
18
- def factory
19
- name
20
- end
21
-
22
- private
23
-
24
- def implementation
25
- @implementation ||= resolve_name
26
- end
27
-
28
- def resolve_name
29
- if FactoryGirl.factories.registered?(name)
30
- Attribute::Association.new(name, name, {})
31
- elsif FactoryGirl.sequences.registered?(name)
32
- Attribute::Sequence.new(name, name)
33
- else
34
- Attribute::Trait.new(name, @factory)
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,22 +0,0 @@
1
- module FactoryGirl
2
- class Attribute #:nodoc:
3
-
4
- class Trait < Attribute #:nodoc:
5
- def initialize(name, factory)
6
- super(name)
7
- @factory = factory
8
- end
9
-
10
- def add_to(proxy)
11
- trait.attributes.each { |attr| attr.add_to(proxy) }
12
- end
13
-
14
- private
15
-
16
- def trait
17
- (@factory || FactoryGirl).trait_by_name(name)
18
- end
19
- end
20
-
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FactoryGirl::Attribute::Callback do
4
- let(:name) { :after_create }
5
- let(:block) { proc { "block" } }
6
- let(:proxy) { stub("proxy") }
7
-
8
- subject { FactoryGirl::Attribute::Callback.new(name, block) }
9
-
10
- its(:name) { should == name }
11
-
12
- it "set its callback on a proxy" do
13
- proxy.stubs(:add_callback)
14
- subject.add_to(proxy)
15
- proxy.should have_received(:add_callback).with(name, block)
16
- end
17
- end
18
-
19
- describe FactoryGirl::Attribute::Callback, "with a string name" do
20
- subject { FactoryGirl::Attribute::Callback.new("name", nil) }
21
- its(:name) { should == :name }
22
- end