challah 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/CHANGELOG.md +9 -2
  2. data/README.md +18 -18
  3. data/lib/challah/test.rb +22 -5
  4. data/lib/challah/version.rb +1 -1
  5. data/test/audit_test.rb +32 -32
  6. data/test/controller_test.rb +9 -9
  7. data/test/cookie_store_test.rb +25 -25
  8. data/test/factories.rb +7 -7
  9. data/test/helper.rb +14 -12
  10. data/test/permission_test.rb +14 -14
  11. data/test/restrictions_controller_test.rb +29 -30
  12. data/test/role_test.rb +26 -26
  13. data/test/session_test.rb +65 -65
  14. data/test/sessions_controller_test.rb +13 -13
  15. data/test/simple_cookie_store_test.rb +25 -25
  16. data/test/user_test.rb +79 -79
  17. data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
  18. data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
  19. data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
  20. data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
  21. data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
  22. data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
  23. data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
  24. data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
  25. data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
  26. data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
  27. data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
  28. data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
  29. data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
  30. data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
  31. data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
  32. data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
  33. data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
  34. data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
  35. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
  36. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
  37. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
  38. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
  39. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
  40. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
  41. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
  42. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
  43. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
  44. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
  45. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
  46. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
  47. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
  48. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
  49. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
  50. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
  51. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
  52. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
  53. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
  54. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
  55. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
  56. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
  57. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
  58. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
  59. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
  60. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
  61. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
  62. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
  63. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
  64. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
  65. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
  66. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
  67. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
  68. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
  69. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
  70. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
  71. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
  72. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
  73. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
  74. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
  75. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
  76. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
  77. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
  78. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
  79. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
  80. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
  81. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
  82. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
  83. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
  84. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
  85. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
  86. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
  87. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
  88. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
  89. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
  90. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
  91. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
  92. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
  93. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
  94. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
  95. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
  96. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
  97. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
  98. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
  99. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
  100. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
  101. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
  102. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
  103. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
  104. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
  105. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
  106. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
  107. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
  108. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
  109. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
  110. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
  111. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
  112. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
  113. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
  114. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
  115. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
  116. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
  117. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
  118. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
  119. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
  120. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
  121. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
  122. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
  123. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
  124. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
  125. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
  126. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
  127. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
  128. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
  129. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
  130. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
  131. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
  132. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
  133. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
  134. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
  135. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
  136. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
  137. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
  138. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
  139. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
  140. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
  141. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
  142. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
  143. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
  144. data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
  145. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
  146. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
  147. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
  148. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
  149. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
  150. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
  151. data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
  152. metadata +147 -12
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe "defining a child factory before a parent" do
4
+ before do
5
+ define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
6
+
7
+ FactoryGirl.define do
8
+ factory :admin, parent: :user do
9
+ admin true
10
+ end
11
+
12
+ factory :user do
13
+ name "awesome"
14
+ end
15
+ end
16
+ end
17
+
18
+ it "creates admin factories correctly" do
19
+ FactoryGirl.create(:admin).should be_admin
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "an instance generated by a factory with a custom class name" do
4
+ before do
5
+ define_model("User", admin: :boolean)
6
+
7
+ FactoryGirl.define do
8
+ factory :user
9
+
10
+ factory :admin, class: User do
11
+ admin { true }
12
+ end
13
+ end
14
+ end
15
+
16
+ subject { FactoryGirl.create(:admin) }
17
+
18
+ it "uses the correct class name" do
19
+ should be_kind_of(User)
20
+ end
21
+
22
+ it "uses the correct factory definition" do
23
+ should be_admin
24
+ end
25
+ end
26
+
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "an instance generated by a factory" do
4
+ before do
5
+ define_model("User")
6
+
7
+ FactoryGirl.define do
8
+ factory :user
9
+ end
10
+ end
11
+
12
+ it "registers the user factory" do
13
+ FactoryGirl.factory_by_name(:user).should be_a(FactoryGirl::Factory)
14
+ end
15
+ end
@@ -0,0 +1,147 @@
1
+ require "spec_helper"
2
+
3
+ describe "initialize_with with non-FG attributes" do
4
+ include FactoryGirl::Syntax::Methods
5
+
6
+ before do
7
+ define_model("User", name: :string, age: :integer) do
8
+ def self.construct(name, age)
9
+ new(name: name, age: age)
10
+ end
11
+ end
12
+
13
+ FactoryGirl.define do
14
+ factory :user do
15
+ initialize_with { User.construct("John Doe", 21) }
16
+ end
17
+ end
18
+ end
19
+
20
+ subject { build(:user) }
21
+ its(:name) { should == "John Doe" }
22
+ its(:age) { should == 21 }
23
+ end
24
+
25
+ describe "initialize_with with FG attributes that are ignored" do
26
+ include FactoryGirl::Syntax::Methods
27
+
28
+ before do
29
+ define_model("User", name: :string) do
30
+ def self.construct(name)
31
+ new(name: "#{name} from .construct")
32
+ end
33
+ end
34
+
35
+ FactoryGirl.define do
36
+ factory :user do
37
+ ignore do
38
+ name { "Handsome Chap" }
39
+ end
40
+
41
+ initialize_with { User.construct(name) }
42
+ end
43
+ end
44
+ end
45
+
46
+ subject { build(:user) }
47
+ its(:name) { should == "Handsome Chap from .construct" }
48
+ end
49
+
50
+ describe "initialize_with with FG attributes that are not ignored" do
51
+ include FactoryGirl::Syntax::Methods
52
+
53
+ before do
54
+ define_model("User", name: :string) do
55
+ def self.construct(name)
56
+ new(name: "#{name} from .construct")
57
+ end
58
+ end
59
+
60
+ FactoryGirl.define do
61
+ factory :user do
62
+ name { "Handsome Chap" }
63
+
64
+ initialize_with { User.construct(name) }
65
+ end
66
+ end
67
+ end
68
+
69
+ it "assigns each attribute even if the attribute has been used in the constructor" do
70
+ build(:user).name.should == "Handsome Chap"
71
+ end
72
+ end
73
+
74
+ describe "initialize_with non-ORM-backed objects" do
75
+ include FactoryGirl::Syntax::Methods
76
+
77
+ before do
78
+ define_class("ReportGenerator") do
79
+ attr_reader :name, :data
80
+
81
+ def initialize(name, data)
82
+ @name = name
83
+ @data = data
84
+ end
85
+ end
86
+
87
+ FactoryGirl.define do
88
+ sequence(:random_data) { 5.times.map { Kernel.rand(200) } }
89
+
90
+ factory :report_generator do
91
+ ignore do
92
+ name "My Awesome Report"
93
+ end
94
+
95
+ initialize_with { ReportGenerator.new(name, FactoryGirl.generate(:random_data)) }
96
+ end
97
+ end
98
+ end
99
+
100
+ it "allows for overrides" do
101
+ build(:report_generator, name: "Overridden").name.should == "Overridden"
102
+ end
103
+
104
+ it "generates random data" do
105
+ build(:report_generator).data.length.should == 5
106
+ end
107
+ end
108
+
109
+ describe "initialize_with parent and child factories" do
110
+ before do
111
+ define_class("Awesome") do
112
+ attr_reader :name
113
+
114
+ def initialize(name)
115
+ @name = name
116
+ end
117
+ end
118
+
119
+ FactoryGirl.define do
120
+ factory :awesome do
121
+ ignore do
122
+ name "Great"
123
+ end
124
+
125
+ initialize_with { Awesome.new(name) }
126
+
127
+ factory :sub_awesome do
128
+ ignore do
129
+ name "Sub"
130
+ end
131
+ end
132
+
133
+ factory :super_awesome do
134
+ initialize_with { Awesome.new("Super") }
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ it "uses the parent's constructor when the child factory doesn't assign it" do
141
+ FactoryGirl.build(:sub_awesome).name.should == "Sub"
142
+ end
143
+
144
+ it "allows child factories to override initialize_with" do
145
+ FactoryGirl.build(:super_awesome).name.should == "Super"
146
+ end
147
+ end
@@ -0,0 +1,184 @@
1
+ require "spec_helper"
2
+
3
+ describe "modifying factories" do
4
+ include FactoryGirl::Syntax::Methods
5
+
6
+ before do
7
+ define_model('User', name: :string, admin: :boolean, email: :string, login: :string)
8
+
9
+ FactoryGirl.define do
10
+ sequence(:email) {|n| "user#{n}@example.com" }
11
+
12
+ factory :user do
13
+ email
14
+
15
+ after_create do |user|
16
+ user.login = user.name.upcase if user.name
17
+ end
18
+
19
+ factory :admin do
20
+ admin true
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ context "simple modification" do
27
+ before do
28
+ FactoryGirl.modify do
29
+ factory :user do
30
+ name "Great User"
31
+ end
32
+ end
33
+ end
34
+
35
+ subject { create(:user) }
36
+ its(:name) { should == "Great User" }
37
+ its(:login) { should == "GREAT USER" }
38
+
39
+ it "doesn't allow the factory to be subsequently defined" do
40
+ expect do
41
+ FactoryGirl.define { factory :user }
42
+ end.to raise_error(FactoryGirl::DuplicateDefinitionError, "Factory already registered: user")
43
+ end
44
+
45
+ it "does allow the factory to be subsequently modified" do
46
+ FactoryGirl.modify do
47
+ factory :user do
48
+ name "Overridden again!"
49
+ end
50
+ end
51
+
52
+ create(:user).name.should == "Overridden again!"
53
+ end
54
+ end
55
+
56
+ context "adding callbacks" do
57
+ before do
58
+ FactoryGirl.modify do
59
+ factory :user do
60
+ name "Great User"
61
+ after_create do |user|
62
+ user.name = user.name.downcase
63
+ user.login = nil
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ subject { create(:user) }
70
+
71
+ its(:name) { should == "great user" }
72
+ its(:login) { should be_nil }
73
+ end
74
+
75
+ context "reusing traits" do
76
+ before do
77
+ FactoryGirl.define do
78
+ trait :rockstar do
79
+ name "Johnny Rockstar!!!"
80
+ end
81
+ end
82
+
83
+ FactoryGirl.modify do
84
+ factory :user do
85
+ rockstar
86
+ email { "#{name}@example.com" }
87
+ end
88
+ end
89
+ end
90
+
91
+ subject { create(:user) }
92
+
93
+ its(:name) { should == "Johnny Rockstar!!!" }
94
+ its(:email) { should == "Johnny Rockstar!!!@example.com" }
95
+ its(:login) { should == "JOHNNY ROCKSTAR!!!" }
96
+ end
97
+
98
+ context "redefining attributes" do
99
+ before do
100
+ FactoryGirl.modify do
101
+ factory :user do
102
+ email { "#{name}-modified@example.com" }
103
+ name "Great User"
104
+ end
105
+ end
106
+ end
107
+
108
+ context "creating user" do
109
+ context "without overrides" do
110
+ subject { create(:user) }
111
+
112
+ its(:name) { should == "Great User" }
113
+ its(:email) { should == "Great User-modified@example.com" }
114
+ end
115
+
116
+ context "overriding dynamic attributes" do
117
+ subject { create(:user, email: "perfect@example.com") }
118
+
119
+ its(:name) { should == "Great User" }
120
+ its(:email) { should == "perfect@example.com" }
121
+ end
122
+
123
+ context "overriding static attributes" do
124
+ subject { create(:user, name: "wonderful") }
125
+
126
+ its(:name) { should == "wonderful" }
127
+ its(:email) { should == "wonderful-modified@example.com" }
128
+ end
129
+ end
130
+
131
+ context "creating admin" do
132
+ context "without overrides" do
133
+ subject { create(:admin) }
134
+
135
+ its(:name) { should == "Great User" }
136
+ its(:email) { should == "Great User-modified@example.com" }
137
+ its(:admin) { should be_true }
138
+ end
139
+
140
+ context "overriding dynamic attributes" do
141
+ subject { create(:admin, email: "perfect@example.com") }
142
+
143
+ its(:name) { should == "Great User" }
144
+ its(:email) { should == "perfect@example.com" }
145
+ its(:admin) { should be_true }
146
+ end
147
+
148
+ context "overriding static attributes" do
149
+ subject { create(:admin, name: "wonderful") }
150
+
151
+ its(:name) { should == "wonderful" }
152
+ its(:email) { should == "wonderful-modified@example.com" }
153
+ its(:admin) { should be_true }
154
+ end
155
+ end
156
+ end
157
+
158
+ it "doesn't overwrite already defined child's attributes" do
159
+ FactoryGirl.modify do
160
+ factory :user do
161
+ admin false
162
+ end
163
+ end
164
+ create(:admin).should be_admin
165
+ end
166
+
167
+ it "allows for overriding child classes" do
168
+ FactoryGirl.modify do
169
+ factory :admin do
170
+ admin false
171
+ end
172
+ end
173
+
174
+ create(:admin).should_not be_admin
175
+ end
176
+
177
+ it "raises an exception if the factory was not defined before" do
178
+ lambda {
179
+ FactoryGirl.modify do
180
+ factory :unknown_factory
181
+ end
182
+ }.should raise_error(ArgumentError)
183
+ end
184
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe "modifying inherited factories with traits" do
4
+ before do
5
+ define_model('User', gender: :string, admin: :boolean, age: :integer)
6
+ FactoryGirl.define do
7
+ factory :user do
8
+ trait(:female) { gender "Female" }
9
+ trait(:male) { gender "Male" }
10
+
11
+ trait(:young_admin) do
12
+ admin true
13
+ age 17
14
+ end
15
+
16
+ female
17
+ young_admin
18
+
19
+ factory :female_user do
20
+ gender "Female"
21
+ age 25
22
+ end
23
+
24
+ factory :male_user do
25
+ gender "Male"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ it "returns the correct value for overridden attributes from traits" do
32
+ FactoryGirl.build(:male_user).gender.should == "Male"
33
+ end
34
+
35
+ it "returns the correct value for overridden attributes from traits defining multiple attributes" do
36
+ FactoryGirl.build(:female_user).gender.should == "Female"
37
+ FactoryGirl.build(:female_user).age.should == 25
38
+ FactoryGirl.build(:female_user).admin.should == true
39
+ end
40
+
41
+ it "allows modification of attributes created via traits" do
42
+ FactoryGirl.modify do
43
+ factory :male_user do
44
+ age 20
45
+ end
46
+ end
47
+
48
+ FactoryGirl.build(:male_user).gender.should == "Male"
49
+ FactoryGirl.build(:male_user).age.should == 20
50
+ FactoryGirl.build(:male_user).admin.should == true
51
+ end
52
+ end