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,71 @@
1
+ require "spec_helper"
2
+
3
+ describe FactoryGirl::DeclarationList, "#attribute_list" do
4
+ let(:static_attribute_1) { stub("static attribute 1") }
5
+ let(:static_attribute_2) { stub("static attribute 2") }
6
+ let(:dynamic_attribute_1) { stub("dynamic attribute 1") }
7
+ let(:static_declaration) { stub("static declaration", to_attributes: [static_attribute_1, static_attribute_2]) }
8
+ let(:dynamic_declaration) { stub("static declaration", to_attributes: [dynamic_attribute_1]) }
9
+
10
+ it "returns an AttributeList" do
11
+ subject.attribute_list.should be_a(FactoryGirl::AttributeList)
12
+ end
13
+
14
+ let(:attribute_list) { stub("attribute list", define_attribute: true) }
15
+
16
+ it "defines each attribute on the attribute list" do
17
+ FactoryGirl::AttributeList.stubs(new: attribute_list)
18
+
19
+ subject.declare_attribute(static_declaration)
20
+ subject.declare_attribute(dynamic_declaration)
21
+
22
+ subject.attribute_list
23
+
24
+ attribute_list.should have_received(:define_attribute).with(static_attribute_1)
25
+ attribute_list.should have_received(:define_attribute).with(static_attribute_2)
26
+ attribute_list.should have_received(:define_attribute).with(dynamic_attribute_1)
27
+ end
28
+
29
+ it "creates a new attribute list upon every invocation" do
30
+ subject.attribute_list.should_not == subject.attribute_list
31
+ end
32
+ end
33
+
34
+ describe FactoryGirl::DeclarationList, "#declare_attribute" do
35
+ let(:declaration_1) { stub("declaration", name: "declaration 1") }
36
+ let(:declaration_2) { stub("declaration", name: "declaration 2") }
37
+ let(:declaration_with_same_name) { stub("declaration", name: "declaration 1") }
38
+
39
+ context "when not overridable" do
40
+ it "adds the declaration to the list" do
41
+ subject.declare_attribute(declaration_1)
42
+ subject.to_a.should == [declaration_1]
43
+
44
+ subject.declare_attribute(declaration_2)
45
+ subject.to_a.should == [declaration_1, declaration_2]
46
+ end
47
+ end
48
+
49
+ context "when overridable" do
50
+ before { subject.overridable }
51
+
52
+ it "adds the declaration to the list" do
53
+ subject.declare_attribute(declaration_1)
54
+ subject.to_a.should == [declaration_1]
55
+
56
+ subject.declare_attribute(declaration_2)
57
+ subject.to_a.should == [declaration_1, declaration_2]
58
+ end
59
+
60
+ it "deletes declarations with the same name" do
61
+ subject.declare_attribute(declaration_1)
62
+ subject.to_a.should == [declaration_1]
63
+
64
+ subject.declare_attribute(declaration_2)
65
+ subject.to_a.should == [declaration_1, declaration_2]
66
+
67
+ subject.declare_attribute(declaration_with_same_name)
68
+ subject.to_a.should == [declaration_2, declaration_with_same_name]
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::DefinitionProxy, "#add_attribute" do
4
+ subject { FactoryGirl::Definition.new }
5
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
6
+
7
+ it "raises if both a block and value are given" do
8
+ expect {
9
+ proxy.add_attribute(:something, "great") { "will raise!" }
10
+ }.to raise_error(FactoryGirl::AttributeDefinitionError, "Both value and block given")
11
+ end
12
+
13
+ it "declares a static attribute on the factory" do
14
+ proxy.add_attribute(:attribute_name, "attribute value")
15
+ subject.should have_static_declaration(:attribute_name).with_value("attribute value")
16
+ end
17
+
18
+ it "declares a dynamic attribute on the factory" do
19
+ attribute_value = lambda { "dynamic attribute" }
20
+ proxy.add_attribute(:attribute_name, &attribute_value)
21
+ subject.should have_dynamic_declaration(:attribute_name).with_value(attribute_value)
22
+ end
23
+ end
24
+
25
+ describe FactoryGirl::DefinitionProxy, "#add_attribute when the proxy ignores attributes" do
26
+ subject { FactoryGirl::Definition.new }
27
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject, true) }
28
+
29
+ it "raises if both a block and value are given" do
30
+ expect {
31
+ proxy.add_attribute(:something, "great") { "will raise!" }
32
+ }.to raise_error(FactoryGirl::AttributeDefinitionError, "Both value and block given")
33
+ end
34
+
35
+ it "declares a static attribute on the factory" do
36
+ proxy.add_attribute(:attribute_name, "attribute value")
37
+ subject.should have_static_declaration(:attribute_name).ignored.with_value("attribute value")
38
+ end
39
+
40
+ it "declares a dynamic attribute on the factory" do
41
+ attribute_value = lambda { "dynamic attribute" }
42
+ proxy.add_attribute(:attribute_name, &attribute_value)
43
+ subject.should have_dynamic_declaration(:attribute_name).ignored.with_value(attribute_value)
44
+ end
45
+ end
46
+
47
+ describe FactoryGirl::DefinitionProxy, "#ignore" do
48
+ subject { FactoryGirl::Definition.new }
49
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
50
+
51
+ it "makes all attributes added ignored" do
52
+ proxy.ignore do
53
+ add_attribute(:attribute_name, "attribute value")
54
+ end
55
+
56
+ subject.should have_static_declaration(:attribute_name).ignored.with_value("attribute value")
57
+ end
58
+ end
59
+
60
+ describe FactoryGirl::DefinitionProxy, "#method_missing" do
61
+ subject { FactoryGirl::Definition.new }
62
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
63
+
64
+ it "declares an implicit declaration without args or a block" do
65
+ proxy.bogus
66
+ subject.should have_implicit_declaration(:bogus).with_factory(subject)
67
+ end
68
+
69
+ it "declares an association when :factory is passed" do
70
+ proxy.author factory: :user
71
+ subject.should have_association_declaration(:author).with_options(factory: :user)
72
+ end
73
+
74
+ it "declares a static attribute" do
75
+ proxy.attribute_name "attribute value"
76
+ subject.should have_static_declaration(:attribute_name).with_value("attribute value")
77
+ end
78
+
79
+ it "declares a dynamic attribute" do
80
+ attribute_value = lambda { "dynamic attribute" }
81
+ proxy.attribute_name &attribute_value
82
+ subject.should have_dynamic_declaration(:attribute_name).with_value(attribute_value)
83
+ end
84
+ end
85
+
86
+ describe FactoryGirl::DefinitionProxy, "#sequence" do
87
+ subject { FactoryGirl::Definition.new }
88
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
89
+
90
+ before { FactoryGirl::Sequence.stubs(:new) }
91
+
92
+ it "creates a new sequence starting at 1" do
93
+ proxy.sequence(:great)
94
+ FactoryGirl::Sequence.should have_received(:new).with(:great, 1)
95
+ end
96
+
97
+ it "creates a new sequence with an overridden starting vaue" do
98
+ proxy.sequence(:great, "C")
99
+ FactoryGirl::Sequence.should have_received(:new).with(:great, "C")
100
+ end
101
+
102
+ it "creates a new sequence with a block" do
103
+ sequence_block = Proc.new {|n| "user+#{n}@example.com" }
104
+ proxy.sequence(:great, 1, &sequence_block)
105
+ FactoryGirl::Sequence.should have_received(:new).with(:great, 1, &sequence_block)
106
+ end
107
+ end
108
+
109
+ describe FactoryGirl::DefinitionProxy, "#association" do
110
+ subject { FactoryGirl::Definition.new }
111
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
112
+
113
+ it "declares an association" do
114
+ proxy.association(:association_name)
115
+ subject.should have_association_declaration(:association_name)
116
+ end
117
+
118
+ it "declares an association with options" do
119
+ proxy.association(:association_name, { name: "Awesome" })
120
+ subject.should have_association_declaration(:association_name).with_options(name: "Awesome")
121
+ end
122
+ end
123
+
124
+ describe FactoryGirl::DefinitionProxy, "adding callbacks" do
125
+ subject { FactoryGirl::Definition.new }
126
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
127
+ let(:callback) { lambda { "my awesome callback!" } }
128
+
129
+ context "#after_build" do
130
+ before { proxy.after_build(&callback) }
131
+ it { should have_callback(:after_build).with_block(callback) }
132
+ end
133
+
134
+ context "#after_create" do
135
+ before { proxy.after_create(&callback) }
136
+ it { should have_callback(:after_create).with_block(callback) }
137
+ end
138
+
139
+ context "#after_stub" do
140
+ before { proxy.after_stub(&callback) }
141
+ it { should have_callback(:after_stub).with_block(callback) }
142
+ end
143
+ end
144
+
145
+ describe FactoryGirl::DefinitionProxy, "#to_create" do
146
+ subject { FactoryGirl::Definition.new }
147
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
148
+
149
+ it "accepts a block to run in place of #save!" do
150
+ to_create_block = lambda {|record| record.persist }
151
+ proxy.to_create(&to_create_block)
152
+ subject.to_create.should == to_create_block
153
+ end
154
+ end
155
+
156
+ describe FactoryGirl::DefinitionProxy, "#factory" do
157
+ subject { FactoryGirl::Definition.new }
158
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
159
+
160
+ it "without options" do
161
+ proxy.factory(:child)
162
+ proxy.child_factories.should include([:child, {}, nil])
163
+ end
164
+
165
+ it "with options" do
166
+ proxy.factory(:child, { awesome: true })
167
+ proxy.child_factories.should include([:child, { awesome: true }, nil])
168
+ end
169
+
170
+ it "with a block" do
171
+ child_block = lambda { }
172
+ proxy.factory(:child, {}, &child_block)
173
+ proxy.child_factories.should include([:child, {}, child_block])
174
+ end
175
+ end
176
+
177
+ describe FactoryGirl::DefinitionProxy, "#trait" do
178
+ subject { FactoryGirl::Definition.new }
179
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
180
+
181
+ it "declares a trait" do
182
+ male_trait = Proc.new { gender("Male") }
183
+ proxy.trait(:male, &male_trait)
184
+ subject.should have_trait(:male).with_block(male_trait)
185
+ end
186
+ end
187
+
188
+ describe FactoryGirl::DefinitionProxy, "#initialize_with" do
189
+ subject { FactoryGirl::Definition.new }
190
+ let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
191
+
192
+ it "defines the constructor on the definition" do
193
+ constructor = Proc.new { Array.new }
194
+ proxy.initialize_with(&constructor)
195
+ subject.constructor.should == constructor
196
+ end
197
+ end
@@ -0,0 +1,104 @@
1
+ require "spec_helper"
2
+
3
+ describe FactoryGirl::Definition do
4
+ it { should delegate(:declare_attribute).to(:declarations) }
5
+ it { should delegate(:attributes).to(:declarations).as(:attribute_list) }
6
+ end
7
+
8
+ describe FactoryGirl::Definition, "with a name" do
9
+ let(:name) { :"great name" }
10
+ subject { FactoryGirl::Definition.new(name) }
11
+
12
+ it "creates a new attribute list with the name passed" do
13
+ FactoryGirl::DeclarationList.stubs(:new)
14
+ subject
15
+ FactoryGirl::DeclarationList.should have_received(:new).with(name)
16
+ end
17
+ end
18
+
19
+ describe FactoryGirl::Definition, "#overridable" do
20
+ let(:list) { stub("declaration list", overridable: true) }
21
+ before { FactoryGirl::DeclarationList.stubs(new: list) }
22
+
23
+ it "sets the declaration list as overridable" do
24
+ subject.overridable.should == subject
25
+ list.should have_received(:overridable).once
26
+ end
27
+ end
28
+
29
+ describe FactoryGirl::Definition, "defining traits" do
30
+ let(:trait_1) { stub("trait") }
31
+ let(:trait_2) { stub("trait") }
32
+
33
+ it "maintains a list of traits" do
34
+ subject.define_trait(trait_1)
35
+ subject.define_trait(trait_2)
36
+ subject.defined_traits.should == [trait_1, trait_2]
37
+ end
38
+ end
39
+
40
+ describe FactoryGirl::Definition, "adding callbacks" do
41
+ let(:callback_1) { stub("callback") }
42
+ let(:callback_2) { stub("callback") }
43
+
44
+ it "maintains a list of callbacks" do
45
+ subject.add_callback(callback_1)
46
+ subject.add_callback(callback_2)
47
+ subject.callbacks.should == [callback_1, callback_2]
48
+ end
49
+ end
50
+
51
+ describe FactoryGirl::Definition, "#to_create" do
52
+ its(:to_create) { should be_a(Proc) }
53
+
54
+ it "calls save! on the object when run" do
55
+ instance = stub("model instance", :save! => true)
56
+ subject.to_create[instance]
57
+ instance.should have_received(:save!).once
58
+ end
59
+
60
+ it "returns the assigned value when given a block" do
61
+ block = proc { nil }
62
+ subject.to_create(&block)
63
+ subject.to_create.should == block
64
+ end
65
+ end
66
+
67
+ describe FactoryGirl::Definition, "#processing_order" do
68
+ let(:female_trait) { FactoryGirl::Trait.new(:female) }
69
+ let(:admin_trait) { FactoryGirl::Trait.new(:admin) }
70
+
71
+ before do
72
+ subject.define_trait(female_trait)
73
+ FactoryGirl.stubs(trait_by_name: admin_trait)
74
+ end
75
+
76
+ context "without base traits" do
77
+ it "returns the definition without any traits" do
78
+ subject.processing_order.should == [subject]
79
+ end
80
+
81
+ it "finds the correct traits after inheriting" do
82
+ subject.inherit_traits([:female])
83
+ subject.processing_order.should == [subject, female_trait]
84
+ end
85
+
86
+ it "looks for the trait on FactoryGirl" do
87
+ subject.inherit_traits([:female, :admin])
88
+ subject.processing_order.should == [subject, female_trait, admin_trait]
89
+ end
90
+ end
91
+
92
+ context "with base traits" do
93
+ subject { FactoryGirl::Definition.new("my definition", [:female]) }
94
+
95
+ it "returns the base traits and definition" do
96
+ subject.processing_order.should == [female_trait, subject]
97
+ end
98
+
99
+ it "finds the correct traits after inheriting" do
100
+ subject.inherit_traits([:admin])
101
+ subject.processing_order.should == [female_trait, subject, admin_trait]
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe FactoryGirl::EvaluatorClassDefiner do
4
+ let(:simple_attribute) { stub("simple attribute", name: :simple, to_proc: lambda { 1 }) }
5
+ let(:relative_attribute) { stub("relative attribute", name: :relative, to_proc: lambda { simple + 1 }) }
6
+ let(:attribute_that_raises_a_second_time) { stub("attribute that would raise without a cache", name: :raises_without_proper_cache, to_proc: lambda { raise "failed" if @run; @run = true; nil }) }
7
+ let(:callbacks) { [stub("callback 1"), stub("callback 2")] }
8
+
9
+ let(:attributes) { [simple_attribute, relative_attribute, attribute_that_raises_a_second_time] }
10
+ let(:class_definer) { FactoryGirl::EvaluatorClassDefiner.new(attributes, callbacks, FactoryGirl::Evaluator) }
11
+ let(:evaluator) { class_definer.evaluator_class.new(stub("build strategy", add_observer: true)) }
12
+
13
+ it "returns an evaluator when accessing the evaluator class" do
14
+ evaluator.should be_a(FactoryGirl::Evaluator)
15
+ end
16
+
17
+ it "adds each attribute to the evaluator" do
18
+ evaluator.simple.should == 1
19
+ end
20
+
21
+ it "evaluates the block in the context of the evaluator" do
22
+ evaluator.relative.should == 2
23
+ end
24
+
25
+ it "only instance_execs the block once even when returning nil" do
26
+ expect {
27
+ 2.times { evaluator.raises_without_proper_cache }
28
+ }.to_not raise_error
29
+ end
30
+
31
+ it "sets attributes on the evaluator class" do
32
+ class_definer.evaluator_class.attribute_lists.should == [attributes]
33
+ end
34
+
35
+ it "sets callbacks on the evaluator class" do
36
+ class_definer.evaluator_class.callbacks.should == callbacks
37
+ end
38
+
39
+ context "with a custom evaluator as a parent class" do
40
+ let(:child_callbacks) { [stub("child callback 1"), stub("child callback 2")] }
41
+ let(:child_attributes) { [stub("child attribute", name: :simple, to_proc: lambda { 1 })] }
42
+ let(:child_definer) { FactoryGirl::EvaluatorClassDefiner.new(child_attributes, child_callbacks, class_definer.evaluator_class) }
43
+
44
+ subject { child_definer.evaluator_class }
45
+
46
+ it "bases its attribute lists on itself and its parent evaluator" do
47
+ subject.attribute_lists.should == [attributes, child_attributes]
48
+ end
49
+
50
+ it "bases its callbacks on itself and its parent evaluator" do
51
+ subject.callbacks.should == callbacks + child_callbacks
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,279 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Factory do
4
+ before do
5
+ @name = :user
6
+ @class = define_class('User')
7
+ @factory = FactoryGirl::Factory.new(@name)
8
+ FactoryGirl.register_factory(@factory)
9
+ end
10
+
11
+ it "has a factory name" do
12
+ @factory.name.should == @name
13
+ end
14
+
15
+ it "has a build class" do
16
+ @factory.build_class.should == @class
17
+ end
18
+
19
+ it "passes a custom creation block" do
20
+ strategy = stub("strategy", result: nil, add_observer: true)
21
+ FactoryGirl::Strategy::Build.stubs(new: strategy)
22
+ block = lambda {}
23
+ factory = FactoryGirl::Factory.new(:object)
24
+ factory.to_create(&block)
25
+
26
+ factory.run(FactoryGirl::Strategy::Build, {})
27
+
28
+ strategy.should have_received(:result).with(instance_of(FactoryGirl::AttributeAssigner), block)
29
+ end
30
+
31
+ it "returns associations" do
32
+ factory = FactoryGirl::Factory.new(:post)
33
+ FactoryGirl.register_factory(FactoryGirl::Factory.new(:admin))
34
+ factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {}))
35
+ factory.declare_attribute(FactoryGirl::Declaration::Association.new(:editor, {}))
36
+ factory.declare_attribute(FactoryGirl::Declaration::Implicit.new(:admin, factory))
37
+ factory.associations.each do |association|
38
+ association.should be_association
39
+ end
40
+ factory.associations.size.should == 3
41
+ end
42
+
43
+ it "includes associations from the parent factory" do
44
+ association_on_parent = FactoryGirl::Declaration::Association.new(:association_on_parent, {})
45
+ association_on_child = FactoryGirl::Declaration::Association.new(:association_on_child, {})
46
+
47
+ factory = FactoryGirl::Factory.new(:post)
48
+ factory.declare_attribute(association_on_parent)
49
+ FactoryGirl.register_factory(factory)
50
+
51
+ child_factory = FactoryGirl::Factory.new(:child_post, parent: :post)
52
+ child_factory.declare_attribute(association_on_child)
53
+
54
+ child_factory.associations.map(&:name).should == [:association_on_parent, :association_on_child]
55
+ end
56
+
57
+ describe "when overriding generated attributes with a hash" do
58
+ before do
59
+ @name = :name
60
+ @value = 'The price is right!'
61
+ @hash = { @name => @value }
62
+ end
63
+
64
+ it "returns the overridden value in the generated attributes" do
65
+ declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!')
66
+ @factory.declare_attribute(declaration)
67
+ result = @factory.run(FactoryGirl::Strategy::AttributesFor, @hash)
68
+ result[@name].should == @value
69
+ end
70
+
71
+ it "does not call a lazy attribute block for an overridden attribute" do
72
+ declaration = FactoryGirl::Declaration::Dynamic.new(@name, false, lambda { flunk })
73
+ @factory.declare_attribute(declaration)
74
+ @factory.run(FactoryGirl::Strategy::AttributesFor, @hash)
75
+ end
76
+
77
+ it "overrides a symbol parameter with a string parameter" do
78
+ declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!')
79
+ @factory.declare_attribute(declaration)
80
+ @hash = { @name.to_s => @value }
81
+ result = @factory.run(FactoryGirl::Strategy::AttributesFor, @hash)
82
+ result[@name].should == @value
83
+ end
84
+ end
85
+
86
+ describe "overriding an attribute with an alias" do
87
+ before do
88
+ @factory.declare_attribute(FactoryGirl::Declaration::Static.new(:test, 'original'))
89
+ FactoryGirl.aliases << [/(.*)_alias/, '\1']
90
+ @result = @factory.run(FactoryGirl::Strategy::AttributesFor,
91
+ test_alias: 'new')
92
+ end
93
+
94
+ it "uses the passed in value for the alias" do
95
+ @result[:test_alias].should == 'new'
96
+ end
97
+
98
+ it "discards the predefined value for the attribute" do
99
+ @result[:test].should be_nil
100
+ end
101
+ end
102
+
103
+ it "guesses the build class from the factory name" do
104
+ @factory.build_class.should == User
105
+ end
106
+
107
+ it "creates a new factory using the class of the parent" do
108
+ child = FactoryGirl::Factory.new(:child, parent: @factory.name)
109
+ child.compile
110
+ child.build_class.should == @factory.build_class
111
+ end
112
+
113
+ it "creates a new factory while overriding the parent class" do
114
+ child = FactoryGirl::Factory.new(:child, class: String, parent: @factory.name)
115
+ child.compile
116
+ child.build_class.should == String
117
+ end
118
+ end
119
+
120
+ describe FactoryGirl::Factory, "when defined with a custom class" do
121
+ subject { FactoryGirl::Factory.new(:author, class: Float) }
122
+ its(:build_class) { should == Float }
123
+ end
124
+
125
+ describe FactoryGirl::Factory, "when given a class that overrides #to_s" do
126
+ let(:overriding_class) { Overriding::Class }
127
+
128
+ before do
129
+ define_class("Overriding")
130
+ define_class("Overriding::Class") do
131
+ def self.to_s
132
+ "Overriding"
133
+ end
134
+ end
135
+ end
136
+
137
+ subject { FactoryGirl::Factory.new(:overriding_class, class: Overriding::Class) }
138
+
139
+ it "sets build_class correctly" do
140
+ subject.build_class.should == overriding_class
141
+ end
142
+ end
143
+
144
+ describe FactoryGirl::Factory, "when defined with a class instead of a name" do
145
+ let(:factory_class) { ArgumentError }
146
+ let(:name) { :argument_error }
147
+
148
+ subject { FactoryGirl::Factory.new(factory_class) }
149
+
150
+ its(:name) { should == name }
151
+ its(:build_class) { should == factory_class }
152
+ end
153
+
154
+ describe FactoryGirl::Factory, "when defined with a custom class name" do
155
+ subject { FactoryGirl::Factory.new(:author, class: :argument_error) }
156
+ its(:build_class) { should == ArgumentError }
157
+ end
158
+
159
+ describe FactoryGirl::Factory, "with a name ending in s" do
160
+ let(:name) { :business }
161
+ let(:business_class) { Business }
162
+
163
+ before { define_class('Business') }
164
+ subject { FactoryGirl::Factory.new(name) }
165
+
166
+ its(:name) { should == name }
167
+ its(:build_class) { should == business_class }
168
+ end
169
+
170
+ describe FactoryGirl::Factory, "with a string for a name" do
171
+ let(:name) { :string }
172
+ subject { FactoryGirl::Factory.new(name.to_s) }
173
+ its(:name) { should == name }
174
+ end
175
+
176
+ describe FactoryGirl::Factory, "for namespaced class" do
177
+ let(:name) { :settings }
178
+ let(:settings_class) { Admin::Settings }
179
+
180
+ before do
181
+ define_class("Admin")
182
+ define_class("Admin::Settings")
183
+ end
184
+
185
+ context "with a namespaced class with Namespace::Class syntax" do
186
+ subject { FactoryGirl::Factory.new(name, class: "Admin::Settings") }
187
+
188
+ it "sets build_class correctly" do
189
+ subject.build_class.should == settings_class
190
+ end
191
+ end
192
+
193
+ context "with a namespaced class with namespace/class syntax" do
194
+ subject { FactoryGirl::Factory.new(name, class: "admin/settings") }
195
+
196
+ it "sets build_class correctly" do
197
+ subject.build_class.should == settings_class
198
+ end
199
+ end
200
+ end
201
+
202
+ describe FactoryGirl::Factory, "human names" do
203
+ context "factory name without underscores" do
204
+ subject { FactoryGirl::Factory.new(:user) }
205
+ its(:names) { should == [:user] }
206
+ its(:human_names) { should == ["user"] }
207
+ end
208
+
209
+ context "factory name with underscores" do
210
+ subject { FactoryGirl::Factory.new(:happy_user) }
211
+ its(:names) { should == [:happy_user] }
212
+ its(:human_names) { should == ["happy user"] }
213
+ end
214
+
215
+ context "factory name with big letters" do
216
+ subject { FactoryGirl::Factory.new(:LoL) }
217
+ its(:names) { should == [:LoL] }
218
+ its(:human_names) { should == ["lol"] }
219
+ end
220
+
221
+ context "factory name with aliases" do
222
+ subject { FactoryGirl::Factory.new(:happy_user, aliases: [:gleeful_user, :person]) }
223
+ its(:names) { should == [:happy_user, :gleeful_user, :person] }
224
+ its(:human_names) { should == ["happy user", "gleeful user", "person"] }
225
+ end
226
+ end
227
+
228
+ describe FactoryGirl::Factory, "running a factory" do
229
+ subject { FactoryGirl::Factory.new(:user) }
230
+ let(:attribute) { FactoryGirl::Attribute::Static.new(:name, "value", false) }
231
+ let(:declaration) { FactoryGirl::Declaration::Static.new(:name, "value", false) }
232
+ let(:strategy) { stub("strategy", result: "result", add_observer: true) }
233
+ let(:attributes) { [attribute] }
234
+ let(:attribute_list) { stub('attribute-list', declarations: [declaration], to_a: attributes) }
235
+
236
+ before do
237
+ define_model("User", name: :string)
238
+ FactoryGirl::Declaration::Static.stubs(new: declaration)
239
+ declaration.stubs(to_attributes: attributes)
240
+ FactoryGirl::Strategy::Build.stubs(new: strategy)
241
+ subject.declare_attribute(declaration)
242
+ end
243
+
244
+ it "creates the right strategy using the build class when running" do
245
+ subject.run(FactoryGirl::Strategy::Build, {})
246
+ FactoryGirl::Strategy::Build.should have_received(:new).once
247
+ end
248
+
249
+ it "returns the result from the strategy when running" do
250
+ subject.run(FactoryGirl::Strategy::Build, {}).should == "result"
251
+ end
252
+
253
+ it "calls the block and returns the result" do
254
+ block_run = nil
255
+ block = lambda {|result| block_run = "changed" }
256
+ subject.run(FactoryGirl::Strategy::Build, { }, &block)
257
+ block_run.should == "changed"
258
+ end
259
+ end
260
+
261
+ describe FactoryGirl::Factory, "#with_traits" do
262
+ subject { FactoryGirl::Factory.new(:user) }
263
+ let(:admin_trait) { FactoryGirl::Trait.new(:admin) }
264
+ let(:female_trait) { FactoryGirl::Trait.new(:female) }
265
+
266
+ before do
267
+ FactoryGirl.register_trait(admin_trait)
268
+ FactoryGirl.register_trait(female_trait)
269
+ end
270
+
271
+ it "returns a factory with the correct traits" do
272
+ subject.with_traits([:admin, :female]).processing_order[1, 2].should == [admin_trait, female_trait]
273
+ end
274
+
275
+ it "doesn't modify the original factory's processing order" do
276
+ subject.with_traits([:admin, :female])
277
+ subject.processing_order.should == [subject.definition]
278
+ end
279
+ end