challah 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -2
- data/README.md +18 -18
- data/lib/challah/test.rb +22 -5
- data/lib/challah/version.rb +1 -1
- data/test/audit_test.rb +32 -32
- data/test/controller_test.rb +9 -9
- data/test/cookie_store_test.rb +25 -25
- data/test/factories.rb +7 -7
- data/test/helper.rb +14 -12
- data/test/permission_test.rb +14 -14
- data/test/restrictions_controller_test.rb +29 -30
- data/test/role_test.rb +26 -26
- data/test/session_test.rb +65 -65
- data/test/sessions_controller_test.rb +13 -13
- data/test/simple_cookie_store_test.rb +25 -25
- data/test/user_test.rb +79 -79
- data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
- data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
- metadata +147 -12
@@ -0,0 +1,45 @@
|
|
1
|
+
module FactoryGirl
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
# Adds a Sham module, which provides an alternate interface to
|
5
|
+
# FactoryGirl::Sequence.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# require 'factory_girl/syntax/sham'
|
10
|
+
#
|
11
|
+
# Sham.email {|n| "somebody#{n}@example.com" }
|
12
|
+
#
|
13
|
+
# FactoryGirl.define do
|
14
|
+
# factory :user do
|
15
|
+
# email
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Note that you can also use Faker, but it is recommended that you simply
|
20
|
+
# use a sequence as in the above example, as factory_girl does not provide
|
21
|
+
# protection against duplication in randomized sequences, and a randomized
|
22
|
+
# value does not provide any tangible benefits over an ascending sequence.
|
23
|
+
#
|
24
|
+
# This syntax was derived from Pete Yandell's machinist.
|
25
|
+
module Sham
|
26
|
+
module Sham #:nodoc:
|
27
|
+
def self.method_missing(name, *args, &block)
|
28
|
+
if block_given?
|
29
|
+
start_value = args.first
|
30
|
+
FactoryGirl.register_sequence(Sequence.new(name, start_value || 1, &block))
|
31
|
+
else
|
32
|
+
FactoryGirl.sequence_by_name(name).next
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# overrides name on Module
|
37
|
+
def self.name(&block)
|
38
|
+
method_missing('name', &block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
include FactoryGirl::Syntax::Sham
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module FactoryGirl
|
2
|
+
module Syntax
|
3
|
+
module Vintage
|
4
|
+
module ::Factory
|
5
|
+
# Defines a new factory that can be used by the build strategies (create and
|
6
|
+
# build) to build new objects.
|
7
|
+
#
|
8
|
+
# Arguments:
|
9
|
+
# * name: +Symbol+ or +String+
|
10
|
+
# A unique name used to identify this factory.
|
11
|
+
# * options: +Hash+
|
12
|
+
#
|
13
|
+
# Options:
|
14
|
+
# * class: +Symbol+, +Class+, or +String+
|
15
|
+
# The class that will be used when generating instances for this factory. If not specified, the class will be guessed from the factory name.
|
16
|
+
# * parent: +Symbol+
|
17
|
+
# The parent factory. If specified, the attributes from the parent
|
18
|
+
# factory will be copied to the current one with an ability to override
|
19
|
+
# them.
|
20
|
+
#
|
21
|
+
# Yields: +Factory+
|
22
|
+
# The newly created factory.
|
23
|
+
def self.define(name, options = {})
|
24
|
+
$stderr.puts "DEPRECATION WARNING: Factory.define is deprecated; use the FactoryGirl.define block syntax to declare your factory."
|
25
|
+
factory = FactoryGirl::Factory.new(name, options)
|
26
|
+
proxy = FactoryGirl::DefinitionProxy.new(factory)
|
27
|
+
yield(proxy)
|
28
|
+
FactoryGirl.register_factory(factory)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Defines a new sequence that can be used to generate unique values in a specific format.
|
32
|
+
#
|
33
|
+
# Arguments:
|
34
|
+
# name: (Symbol)
|
35
|
+
# A unique name for this sequence. This name will be referenced when
|
36
|
+
# calling next to generate new values from this sequence.
|
37
|
+
# block: (Proc)
|
38
|
+
# The code to generate each value in the sequence. This block will be
|
39
|
+
# called with a unique number each time a value in the sequence is to be
|
40
|
+
# generated. The block should return the generated value for the
|
41
|
+
# sequence.
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
#
|
45
|
+
# Factory.sequence(:email) {|n| "somebody_#{n}@example.com" }
|
46
|
+
def self.sequence(name, start_value = 1, &block)
|
47
|
+
$stderr.puts "DEPRECATION WARNING: Factory.sequence is deprecated; use the FactoryGirl.define block syntax to declare your sequence."
|
48
|
+
FactoryGirl.register_sequence(Sequence.new(name, start_value, &block))
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generates and returns the next value in a sequence.
|
52
|
+
#
|
53
|
+
# Arguments:
|
54
|
+
# name: (Symbol)
|
55
|
+
# The name of the sequence that a value should be generated for.
|
56
|
+
#
|
57
|
+
# Returns:
|
58
|
+
# The next value in the sequence. (Object)
|
59
|
+
def self.next(name)
|
60
|
+
$stderr.puts "DEPRECATION WARNING: Factory.next is deprecated; use FactoryGirl.generate instead."
|
61
|
+
FactoryGirl.generate(name)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Defines a new alias for attributes.
|
65
|
+
#
|
66
|
+
# Arguments:
|
67
|
+
# * pattern: +Regexp+
|
68
|
+
# A pattern that will be matched against attributes when looking for
|
69
|
+
# aliases. Contents captured in the pattern can be used in the alias.
|
70
|
+
# * replace: +String+
|
71
|
+
# The alias that results from the matched pattern. Captured strings can
|
72
|
+
# be substituted like with +String#sub+.
|
73
|
+
#
|
74
|
+
# Example:
|
75
|
+
#
|
76
|
+
# Factory.alias /(.*)_confirmation/, '\1'
|
77
|
+
#
|
78
|
+
# factory_girl starts with aliases for foreign keys, so that a :user
|
79
|
+
# association can be overridden by a :user_id parameter:
|
80
|
+
#
|
81
|
+
# Factory.define :post do |p|
|
82
|
+
# p.association :user
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# # The user association will not be built in this example. The user_id
|
86
|
+
# # will be used instead.
|
87
|
+
# Factory(:post, user_id: 1)
|
88
|
+
def self.alias(pattern, replace)
|
89
|
+
$stderr.puts "DEPRECATION WARNING: Factory.alias is deprecated; use FactoryGirl.aliases << [pattern, replace] instead."
|
90
|
+
FactoryGirl.aliases << [pattern, replace]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Alias for FactoryGirl.attributes_for
|
94
|
+
def self.attributes_for(name, overrides = {})
|
95
|
+
$stderr.puts "DEPRECATION WARNING: Factory.attributes_for is deprecated; use FactoryGirl.attributes_for instead."
|
96
|
+
FactoryGirl.attributes_for(name, overrides)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Alias for FactoryGirl.build
|
100
|
+
def self.build(name, overrides = {})
|
101
|
+
$stderr.puts "DEPRECATION WARNING: Factory.build is deprecated; use FactoryGirl.build instead."
|
102
|
+
FactoryGirl.build(name, overrides)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Alias for FactoryGirl.create
|
106
|
+
def self.create(name, overrides = {})
|
107
|
+
$stderr.puts "DEPRECATION WARNING: Factory.create is deprecated; use FactoryGirl.create instead."
|
108
|
+
FactoryGirl.create(name, overrides)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Alias for FactoryGirl.build_stubbed.
|
112
|
+
def self.stub(name, overrides = {})
|
113
|
+
$stderr.puts "DEPRECATION WARNING: Factory.stub is deprecated; use FactoryGirl.build_stubbed instead."
|
114
|
+
FactoryGirl.build_stubbed(name, overrides)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Shortcut for Factory.create.
|
119
|
+
#
|
120
|
+
# Example:
|
121
|
+
# Factory(:user, name: 'Joe')
|
122
|
+
def Factory(name, attrs = {})
|
123
|
+
$stderr.puts "DEPRECATION WARNING: Factory(:name) is deprecated; use FactoryGirl.create(:name) instead."
|
124
|
+
FactoryGirl.create(name, attrs)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
include FactoryGirl::Syntax::Vintage
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FactoryGirl
|
2
|
+
class Trait
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name, &block) #:nodoc:
|
6
|
+
@name = name
|
7
|
+
@block = block
|
8
|
+
@definition = Definition.new
|
9
|
+
|
10
|
+
proxy = FactoryGirl::DefinitionProxy.new(@definition)
|
11
|
+
proxy.instance_eval(&@block) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
delegate :add_callback, :declare_attribute, :to_create, :define_trait,
|
15
|
+
:callbacks, :attributes, to: :@definition
|
16
|
+
|
17
|
+
def names
|
18
|
+
[@name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
name == other.name &&
|
23
|
+
block == other.block
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
attr_reader :block
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "aliases and overrides" do
|
4
|
+
before do
|
5
|
+
FactoryGirl.aliases << [/one/, "two"]
|
6
|
+
|
7
|
+
define_model("User", two: :string, one: :string)
|
8
|
+
|
9
|
+
FactoryGirl.define do
|
10
|
+
factory :user do
|
11
|
+
two "set value"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { FactoryGirl.create(:user, one: "override") }
|
17
|
+
its(:one) { should == "override" }
|
18
|
+
its(:two) { should be_nil }
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "attribute aliases" do
|
4
|
+
before do
|
5
|
+
define_model('User', name: :string, age: :integer)
|
6
|
+
|
7
|
+
define_model('Post', user_id: :integer) do
|
8
|
+
belongs_to :user
|
9
|
+
end
|
10
|
+
|
11
|
+
FactoryGirl.define do
|
12
|
+
factory :user do
|
13
|
+
factory :user_with_name do
|
14
|
+
name "John Doe"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
factory :post do
|
19
|
+
user
|
20
|
+
end
|
21
|
+
|
22
|
+
factory :post_with_named_user, class: Post do
|
23
|
+
user factory: :user_with_name, age: 20
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "assigning an association by foreign key" do
|
29
|
+
subject { FactoryGirl.build(:post, user_id: 1) }
|
30
|
+
|
31
|
+
it "doesn't assign both an association and its foreign key" do
|
32
|
+
subject.user_id.should == 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "assigning an association by passing factory" do
|
37
|
+
subject { FactoryGirl.create(:post_with_named_user).user }
|
38
|
+
|
39
|
+
it "assigns attributes correctly" do
|
40
|
+
subject.name.should == "John Doe"
|
41
|
+
subject.age.should == 20
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "declaring attributes on a Factory that are private methods on Object" do
|
4
|
+
before do
|
5
|
+
define_model("Website", system: :boolean, link: :string, sleep: :integer)
|
6
|
+
|
7
|
+
FactoryGirl.define do
|
8
|
+
factory :website do
|
9
|
+
system false
|
10
|
+
link "http://example.com"
|
11
|
+
sleep 15
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { FactoryGirl.build(:website, sleep: -5) }
|
17
|
+
|
18
|
+
its(:system) { should == false }
|
19
|
+
its(:link) { should == "http://example.com" }
|
20
|
+
its(:sleep) { should == -5 }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "assigning overrides that are also private methods on object" do
|
24
|
+
before do
|
25
|
+
define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string)
|
26
|
+
|
27
|
+
Object.class_eval do
|
28
|
+
private
|
29
|
+
def some_funky_method(args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
FactoryGirl.define do
|
34
|
+
factory :website do
|
35
|
+
more_format { "format: #{format}" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
after do
|
41
|
+
Object.send(:undef_method, :some_funky_method)
|
42
|
+
end
|
43
|
+
|
44
|
+
subject { FactoryGirl.build(:website, format: "Great", y: 12345, some_funky_method: "foobar!") }
|
45
|
+
its(:format) { should == "Great" }
|
46
|
+
its(:y) { should == 12345 }
|
47
|
+
its(:more_format) { should == "format: Great" }
|
48
|
+
its(:some_funky_method) { should == "foobar!" }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "accessing methods from the instance within a dynamic attribute that is also a private method on object" do
|
52
|
+
before do
|
53
|
+
define_model("Website", more_format: :string) do
|
54
|
+
def format
|
55
|
+
"This is an awesome format"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
FactoryGirl.define do
|
60
|
+
factory :website do
|
61
|
+
more_format { "format: #{format}" }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
subject { FactoryGirl.build(:website) }
|
67
|
+
its(:more_format) { should == "format: This is an awesome format" }
|
68
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "a generated attributes hash" do
|
4
|
+
include FactoryGirl::Syntax::Methods
|
5
|
+
|
6
|
+
before do
|
7
|
+
define_model('User')
|
8
|
+
|
9
|
+
define_model('Post', title: :string,
|
10
|
+
body: :string,
|
11
|
+
summary: :string,
|
12
|
+
user_id: :integer) do
|
13
|
+
belongs_to :user
|
14
|
+
end
|
15
|
+
|
16
|
+
FactoryGirl.define do
|
17
|
+
factory :user
|
18
|
+
|
19
|
+
factory :post do
|
20
|
+
title { "default title" }
|
21
|
+
body { "default body" }
|
22
|
+
summary { title }
|
23
|
+
user
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
subject { attributes_for(:post, title: 'overridden title') }
|
29
|
+
|
30
|
+
it "assigns an overridden value" do
|
31
|
+
subject[:title].should == "overridden title"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "assigns a default value" do
|
35
|
+
subject[:body].should == "default body"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "assigns a lazy, dependent attribute" do
|
39
|
+
subject[:summary].should == "overridden title"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "doesn't assign associations" do
|
43
|
+
subject.should_not have_key(:user_id)
|
44
|
+
subject.should_not have_key(:user)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "calling `attributes_for` with a block" do
|
49
|
+
include FactoryGirl::Syntax::Methods
|
50
|
+
|
51
|
+
before do
|
52
|
+
define_model('Company', name: :string)
|
53
|
+
|
54
|
+
FactoryGirl.define do
|
55
|
+
factory :company
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "passes the hash of attributes" do
|
60
|
+
attributes_for(:company, name: 'thoughtbot') do |attributes|
|
61
|
+
attributes[:name].should eq('thoughtbot')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns the hash of attributes" do
|
66
|
+
expected = nil
|
67
|
+
attributes_for(:company) do |attributes|
|
68
|
+
expected = attributes
|
69
|
+
"hello!"
|
70
|
+
end.should == expected
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "`attributes_for` for a class whose constructor has required params" do
|
75
|
+
before do
|
76
|
+
define_model("User", name: :string) do
|
77
|
+
def initialize(arg1, arg2); end
|
78
|
+
end
|
79
|
+
|
80
|
+
FactoryGirl.define do
|
81
|
+
factory :user do
|
82
|
+
name "John Doe"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
subject { FactoryGirl.attributes_for(:user) }
|
88
|
+
its([:name]) { should == "John Doe" }
|
89
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "calling methods on the model instance" do
|
4
|
+
before do
|
5
|
+
define_model('User', age: :integer, age_copy: :integer) do
|
6
|
+
def age
|
7
|
+
read_attribute(:age) || 18
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
FactoryGirl.define do
|
12
|
+
factory :user do
|
13
|
+
age_copy { age }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "without the attribute being overridden" do
|
19
|
+
it "returns the correct value from the instance" do
|
20
|
+
FactoryGirl.build(:user).age_copy.should == 18
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns nil during attributes_for" do
|
24
|
+
FactoryGirl.attributes_for(:user)[:age_copy].should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "doesn't instantiate a record with attributes_for" do
|
28
|
+
User.stubs(:new)
|
29
|
+
FactoryGirl.attributes_for(:user)
|
30
|
+
User.should have_received(:new).never
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with the attribute being overridden" do
|
35
|
+
it "uses the overridden value" do
|
36
|
+
FactoryGirl.build(:user, age_copy: nil).age_copy.should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "uses the overridden value during attributes_for" do
|
40
|
+
FactoryGirl.attributes_for(:user, age_copy: 25)[:age_copy].should == 25
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with the referenced attribute being overridden" do
|
45
|
+
it "uses the overridden value" do
|
46
|
+
FactoryGirl.build(:user, age: nil).age_copy.should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "uses the overridden value during attributes_for" do
|
50
|
+
FactoryGirl.attributes_for(:user, age: 25)[:age_copy].should == 25
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|