masa-iwasaki-factory_girl 1.2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTION_GUIDELINES.rdoc +9 -0
- data/Changelog +29 -0
- data/LICENSE +19 -0
- data/README.rdoc +261 -0
- data/Rakefile +74 -0
- data/lib/factory_girl/aliases.rb +50 -0
- data/lib/factory_girl/attribute/association.rb +18 -0
- data/lib/factory_girl/attribute/dynamic.rb +20 -0
- data/lib/factory_girl/attribute/static.rb +17 -0
- data/lib/factory_girl/attribute.rb +29 -0
- data/lib/factory_girl/factory.rb +395 -0
- data/lib/factory_girl/proxy/attributes_for.rb +21 -0
- data/lib/factory_girl/proxy/build.rb +29 -0
- data/lib/factory_girl/proxy/create.rb +10 -0
- data/lib/factory_girl/proxy/stub.rb +49 -0
- data/lib/factory_girl/proxy.rb +62 -0
- data/lib/factory_girl/sequence.rb +63 -0
- data/lib/factory_girl/syntax/blueprint.rb +42 -0
- data/lib/factory_girl/syntax/generate.rb +68 -0
- data/lib/factory_girl/syntax/make.rb +39 -0
- data/lib/factory_girl/syntax/sham.rb +42 -0
- data/lib/factory_girl/syntax.rb +12 -0
- data/lib/factory_girl.rb +34 -0
- metadata +78 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
class Factory
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
# Extends ActiveRecord::Base to provide generation methods for factories.
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# require 'factory_girl/syntax/generate'
|
9
|
+
#
|
10
|
+
# Factory.define :user do |factory|
|
11
|
+
# factory.name 'Billy Bob'
|
12
|
+
# factory.email 'billy@bob.example.com'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # Creates a saved instance without raising (same as saving the result
|
16
|
+
# # of Factory.build)
|
17
|
+
# User.generate(:name => 'Johnny')
|
18
|
+
#
|
19
|
+
# # Creates a saved instance and raises when invalid (same as
|
20
|
+
# # Factory.create)
|
21
|
+
# User.generate!
|
22
|
+
#
|
23
|
+
# # Creates an unsaved instance (same as Factory.build)
|
24
|
+
# User.spawn
|
25
|
+
#
|
26
|
+
# # Creates an instance and yields it to the passed block
|
27
|
+
# User.generate do |user|
|
28
|
+
# # ...do something with user...
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# This syntax was derived from Rick Bradley and Yossef Mendelssohn's
|
32
|
+
# object_daddy.
|
33
|
+
module Generate
|
34
|
+
module ActiveRecord #:nodoc:
|
35
|
+
|
36
|
+
def self.included(base) # :nodoc:
|
37
|
+
base.extend ClassMethods
|
38
|
+
end
|
39
|
+
|
40
|
+
module ClassMethods #:nodoc:
|
41
|
+
|
42
|
+
def generate(overrides = {}, &block)
|
43
|
+
instance = Factory.build(name.underscore, overrides)
|
44
|
+
instance.save
|
45
|
+
yield(instance) if block_given?
|
46
|
+
instance
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate!(overrides = {}, &block)
|
50
|
+
instance = Factory.create(name.underscore, overrides)
|
51
|
+
yield(instance) if block_given?
|
52
|
+
instance
|
53
|
+
end
|
54
|
+
|
55
|
+
def spawn(overrides = {}, &block)
|
56
|
+
instance = Factory.build(name.underscore, overrides)
|
57
|
+
yield(instance) if block_given?
|
58
|
+
instance
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
ActiveRecord::Base.send(:include, Factory::Syntax::Generate::ActiveRecord)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Factory
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
# Extends ActiveRecord::Base to provide a make class method, which is a
|
5
|
+
# shortcut for Factory.create.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# require 'factory_girl/syntax/make'
|
10
|
+
#
|
11
|
+
# Factory.define :user do |factory|
|
12
|
+
# factory.name 'Billy Bob'
|
13
|
+
# factory.email 'billy@bob.example.com'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# User.make(:name => 'Johnny')
|
17
|
+
#
|
18
|
+
# This syntax was derived from Pete Yandell's machinist.
|
19
|
+
module Make
|
20
|
+
module ActiveRecord #:nodoc:
|
21
|
+
|
22
|
+
def self.included(base) # :nodoc:
|
23
|
+
base.extend ClassMethods
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods #:nodoc:
|
27
|
+
|
28
|
+
def make(overrides = {})
|
29
|
+
Factory.create(name.underscore, overrides)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ActiveRecord::Base.send(:include, Factory::Syntax::Make::ActiveRecord)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Factory
|
2
|
+
module Syntax
|
3
|
+
|
4
|
+
# Adds a Sham module, which provides an alternate interface to
|
5
|
+
# Factory::Sequence.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# require 'factory_girl/syntax/sham'
|
10
|
+
#
|
11
|
+
# Sham.email {|n| "somebody#{n}@example.com" }
|
12
|
+
#
|
13
|
+
# Factory.define :user do |factory|
|
14
|
+
# factory.email { Sham.email }
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Note that you can also use Faker, but it is recommended that you simply
|
18
|
+
# use a sequence as in the above example, as factory_girl does not provide
|
19
|
+
# protection against duplication in randomized sequences, and a randomized
|
20
|
+
# value does not provide any tangible benefits over an ascending sequence.
|
21
|
+
#
|
22
|
+
# This syntax was derived from Pete Yandell's machinist.
|
23
|
+
module Sham
|
24
|
+
module Sham #:nodoc:
|
25
|
+
def self.method_missing(name, &block)
|
26
|
+
if block_given?
|
27
|
+
Factory.sequence(name, &block)
|
28
|
+
else
|
29
|
+
Factory.next(name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# overrides name on Module
|
34
|
+
def self.name(&block)
|
35
|
+
method_missing('name', &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
include Factory::Syntax::Sham
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Factory
|
2
|
+
# Provides alternate syntaxes for factory_girl. If you don't like the default
|
3
|
+
# syntax for defining or using factories, look at one of the Factory::Syntax
|
4
|
+
# modules:
|
5
|
+
#
|
6
|
+
# * Factory::Syntax::Blueprint: definition syntax similar to Machinist
|
7
|
+
# * Factory::Syntax::Generate: usage syntax similar to Object Daddy
|
8
|
+
# * Factory::Syntax::Make: usage syntax similar to Machinist
|
9
|
+
# * Factory::Syntax::Sham: sequence syntax similar to Machinist
|
10
|
+
module Syntax
|
11
|
+
end
|
12
|
+
end
|
data/lib/factory_girl.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'factory_girl/proxy'
|
3
|
+
require 'factory_girl/proxy/build'
|
4
|
+
require 'factory_girl/proxy/create'
|
5
|
+
require 'factory_girl/proxy/attributes_for'
|
6
|
+
require 'factory_girl/proxy/stub'
|
7
|
+
require 'factory_girl/factory'
|
8
|
+
require 'factory_girl/attribute'
|
9
|
+
require 'factory_girl/attribute/static'
|
10
|
+
require 'factory_girl/attribute/dynamic'
|
11
|
+
require 'factory_girl/attribute/association'
|
12
|
+
require 'factory_girl/sequence'
|
13
|
+
require 'factory_girl/aliases'
|
14
|
+
|
15
|
+
# Shortcut for Factory.default_strategy.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
# Factory(:user, :name => 'Joe')
|
19
|
+
def Factory (name, attrs = {})
|
20
|
+
Factory.default_strategy(name, attrs)
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined? Rails.configuration
|
24
|
+
Rails.configuration.after_initialize do
|
25
|
+
Factory.definition_file_paths = [
|
26
|
+
File.join(RAILS_ROOT, 'test', 'factories'),
|
27
|
+
File.join(RAILS_ROOT, 'spec', 'factories')
|
28
|
+
]
|
29
|
+
Factory.find_definitions
|
30
|
+
end
|
31
|
+
else
|
32
|
+
Factory.find_definitions
|
33
|
+
end
|
34
|
+
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: masa-iwasaki-factory_girl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masatoshi Iwasaki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-09 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Added Factory#find_or_create to thoughtbot-factory_girl
|
17
|
+
email: mstshiwasaki@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- Changelog
|
26
|
+
- CONTRIBUTION_GUIDELINES.rdoc
|
27
|
+
- LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- README.rdoc
|
30
|
+
- lib/factory_girl/aliases.rb
|
31
|
+
- lib/factory_girl/attribute/association.rb
|
32
|
+
- lib/factory_girl/attribute/dynamic.rb
|
33
|
+
- lib/factory_girl/attribute/static.rb
|
34
|
+
- lib/factory_girl/attribute.rb
|
35
|
+
- lib/factory_girl/factory.rb
|
36
|
+
- lib/factory_girl/proxy/attributes_for.rb
|
37
|
+
- lib/factory_girl/proxy/build.rb
|
38
|
+
- lib/factory_girl/proxy/create.rb
|
39
|
+
- lib/factory_girl/proxy/stub.rb
|
40
|
+
- lib/factory_girl/proxy.rb
|
41
|
+
- lib/factory_girl/sequence.rb
|
42
|
+
- lib/factory_girl/syntax/blueprint.rb
|
43
|
+
- lib/factory_girl/syntax/generate.rb
|
44
|
+
- lib/factory_girl/syntax/make.rb
|
45
|
+
- lib/factory_girl/syntax/sham.rb
|
46
|
+
- lib/factory_girl/syntax.rb
|
47
|
+
- lib/factory_girl.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/masa-iwasaki/factory_girl
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --line-numbers
|
53
|
+
- --inline-source
|
54
|
+
- --main
|
55
|
+
- README.rdoc
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.2.0
|
74
|
+
signing_key:
|
75
|
+
specification_version: 2
|
76
|
+
summary: factory_girl provides a framework and DSL for defining and using model instance factories.
|
77
|
+
test_files: []
|
78
|
+
|