fabrication 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +12 -4
- data/lib/fabrication.rb +16 -27
- data/lib/fabrication/attribute.rb +16 -0
- data/lib/fabrication/fabricator.rb +4 -10
- data/lib/fabrication/generator/active_record.rb +4 -3
- data/lib/fabrication/generator/base.rb +2 -3
- data/lib/fabrication/schematic.rb +33 -25
- data/lib/fabrication/version.rb +1 -1
- data/spec/fabrication/attribute_spec.rb +107 -0
- data/spec/fabrication_spec.rb +72 -2
- data/spec/schematic_spec.rb +27 -6
- data/spec/spec_helper.rb +0 -1
- data/spec/support/active_record.rb +0 -1
- data/spec/support/helper_objects.rb +18 -7
- metadata +17 -22
data/README.markdown
CHANGED
@@ -33,7 +33,7 @@ Define your fabricators.
|
|
33
33
|
Fabricator(:company) do
|
34
34
|
name "Fun Factory"
|
35
35
|
employees(:count => 20) { |company, i| Fabricate(:drone, :company => company, :name => "Drone #{i}") }
|
36
|
-
location!
|
36
|
+
location!
|
37
37
|
after_build { |company| company.name = "Another #{company.name}" }
|
38
38
|
after_create { |company| company.update_attribute(:ceo, Fabricate(:drone, :name => 'Lead Drone') }
|
39
39
|
end
|
@@ -42,12 +42,20 @@ Breaking down the above, we are defining a "company" fabricator, which will gene
|
|
42
42
|
|
43
43
|
* The object has a name field, which is statically filled with "Fun Factory".
|
44
44
|
* It has a has_many association to employees and will generate an array of 20 records as indicated by the :count => 20. The block is passed the company object being fabricated and index of the array being created.
|
45
|
-
* It has a belongs_to association to location and this will be generated immediately with the company object. This is because of the "!" after the association name.
|
45
|
+
* It has a belongs_to association to location and this will be generated immediately with the company object. This is because of the "!" after the association name. Also, leaving off the block will cause "{ Fabricate(:location) }" to be automatically generated for you. It will singularize the name of the attribute (if String#singularize is present) and use that as the fabricator name.
|
46
46
|
* After the object is built but before it is saved, it will update the name to "Another Fun Factory".
|
47
47
|
* After the object is created, it will update the "ceo" association with a new "drone" record.
|
48
48
|
|
49
49
|
Alternatively, you can Fabricate(:company) without first defining the Fabricator. Doing so will create an empty Fabricator called ":company" and prevent you from defining the Fabricator explicitly later.
|
50
50
|
|
51
|
+
### Important Thing To Note! ###
|
52
|
+
|
53
|
+
If you are fabricating an activerecord backed object and it has attributes that are not columns in the underlying table, Fabrication will lazily generate them even if they are not defined associations. You can easily work around this by adding a "!" to the end of the attribute definition in the Fabricator.
|
54
|
+
|
55
|
+
Fabricator(:user) do
|
56
|
+
some_delegated_something_or_other! { Fabricate(:something) }
|
57
|
+
end
|
58
|
+
|
51
59
|
### Inheritance ###
|
52
60
|
|
53
61
|
So you already have a company fabricator, but you need one that specifically generates an LLC. No problem!
|
@@ -116,8 +124,8 @@ I (paulelliott) am actively maintaining this project. If you would like to contr
|
|
116
124
|
To run rake successfully:
|
117
125
|
|
118
126
|
1. Clone the project
|
119
|
-
2. Install mongodb and sqlite3
|
120
|
-
3. Install bundler
|
127
|
+
2. Install mongodb and sqlite3 (brew install ...)
|
128
|
+
3. Install bundler (gem install bundler)
|
121
129
|
4. Run `bundle install` from the project root
|
122
130
|
5. Run `rake` and the test suite should be all green!
|
123
131
|
|
data/lib/fabrication.rb
CHANGED
@@ -3,6 +3,7 @@ module Fabrication
|
|
3
3
|
autoload :DuplicateFabricatorError, 'fabrication/errors'
|
4
4
|
autoload :UnfabricatableError, 'fabrication/errors'
|
5
5
|
|
6
|
+
autoload :Attribute, 'fabrication/attribute'
|
6
7
|
autoload :Fabricator, 'fabrication/fabricator'
|
7
8
|
autoload :Sequencer, 'fabrication/sequencer'
|
8
9
|
autoload :Schematic, 'fabrication/schematic'
|
@@ -14,27 +15,9 @@ module Fabrication
|
|
14
15
|
autoload :Base, 'fabrication/generator/base'
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
hash = defined?(HashWithIndifferentAccess) ? HashWithIndifferentAccess.new : {}
|
21
|
-
fetch_schematic(name).attributes.inject(hash) do |hash, attribute|
|
22
|
-
value = attribute.value.respond_to?(:call) ? attribute.value.call : attribute.value
|
23
|
-
hash.merge(attribute.name => value)
|
24
|
-
end.merge(options)
|
25
|
-
end
|
26
|
-
|
27
|
-
def clear_definitions
|
28
|
-
Fabricator.schematics.clear
|
29
|
-
Sequencer.sequences.clear
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def fetch_schematic(name)
|
35
|
-
Fabricator.schematics[name] || Fabricator.define(name)
|
36
|
-
end
|
37
|
-
|
18
|
+
def self.clear_definitions
|
19
|
+
Fabricator.schematics.clear
|
20
|
+
Sequencer.sequences.clear
|
38
21
|
end
|
39
22
|
|
40
23
|
end
|
@@ -44,25 +27,31 @@ def Fabricator(name, options={}, &block)
|
|
44
27
|
end
|
45
28
|
|
46
29
|
def Fabricate(name, overrides={}, &block)
|
47
|
-
Fabrication::Fabricator.generate(name, {
|
30
|
+
Fabrication::Fabricator.generate(name, {
|
31
|
+
:save => true
|
32
|
+
}, overrides, &block)
|
48
33
|
end
|
49
34
|
|
50
35
|
class Fabricate
|
51
36
|
|
52
37
|
class << self
|
53
38
|
|
39
|
+
def attributes_for(name, options={}, &block)
|
40
|
+
Fabrication::Fabricator.generate(name, {
|
41
|
+
:save => false, :attributes => true
|
42
|
+
}, options, &block)
|
43
|
+
end
|
44
|
+
|
54
45
|
def build(name, options={}, &block)
|
55
|
-
Fabrication::Fabricator.generate(name, {
|
46
|
+
Fabrication::Fabricator.generate(name, {
|
47
|
+
:save => false
|
48
|
+
}, options, &block)
|
56
49
|
end
|
57
50
|
|
58
51
|
def sequence(name, start=0, &block)
|
59
52
|
Fabrication::Sequencer.sequence(name, start, &block)
|
60
53
|
end
|
61
54
|
|
62
|
-
def attributes_for(name, options={})
|
63
|
-
Fabrication.attributes_for(name, options)
|
64
|
-
end
|
65
|
-
|
66
55
|
end
|
67
56
|
|
68
57
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Fabrication::Attribute
|
2
|
+
|
3
|
+
attr_accessor :name, :params, :value
|
4
|
+
|
5
|
+
def initialize(name, params, value)
|
6
|
+
self.name = name
|
7
|
+
self.params = params
|
8
|
+
self.value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def update!(attrs)
|
12
|
+
self.params = attrs[:params] if attrs.has_key?(:params)
|
13
|
+
self.value = attrs[:value] if attrs.has_key?(:value)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -19,16 +19,10 @@ class Fabrication::Fabricator
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def class_name_for(name, parent, options)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
elsif options[:from]
|
27
|
-
class_name = options[:from]
|
28
|
-
else
|
29
|
-
class_name = name
|
30
|
-
end
|
31
|
-
class_name
|
22
|
+
options[:class_name] ||
|
23
|
+
(parent && parent.klass.name) ||
|
24
|
+
options[:from] ||
|
25
|
+
name
|
32
26
|
end
|
33
27
|
|
34
28
|
def schematic_for(name, options, &block)
|
@@ -7,8 +7,9 @@ class Fabrication::Generator::ActiveRecord < Fabrication::Generator::Base
|
|
7
7
|
def method_missing(method_name, *args, &block)
|
8
8
|
method_name = method_name.to_s
|
9
9
|
if block_given?
|
10
|
-
|
11
|
-
|
10
|
+
options = args.first || {}
|
11
|
+
count = options[:count] || 0
|
12
|
+
unless options[:force] || instance.class.columns.map(&:name).include?(method_name)
|
12
13
|
# copy the original getter
|
13
14
|
instance.instance_variable_set("@__#{method_name}_original", instance.method(method_name).clone)
|
14
15
|
|
@@ -32,7 +33,7 @@ class Fabrication::Generator::ActiveRecord < Fabrication::Generator::Base
|
|
32
33
|
end
|
33
34
|
>
|
34
35
|
else
|
35
|
-
assign(method_name,
|
36
|
+
assign(method_name, options, &block)
|
36
37
|
end
|
37
38
|
else
|
38
39
|
assign(method_name, args.first)
|
@@ -37,15 +37,14 @@ class Fabrication::Generator::Base
|
|
37
37
|
def after_generation(options); end
|
38
38
|
|
39
39
|
def assign(method_name, param)
|
40
|
-
|
41
|
-
if param.is_a?(Hash) && param.has_key?(:count) && param[:count] > 1
|
40
|
+
if param.is_a?(Hash) && param.has_key?(:count)
|
42
41
|
value = (1..param[:count]).map do |i|
|
43
42
|
block_given? ? yield(instance, i) : param
|
44
43
|
end
|
45
44
|
else
|
46
45
|
value = block_given? ? yield(instance) : param
|
47
46
|
end
|
48
|
-
instance.send("#{method_name
|
47
|
+
instance.send("#{method_name}=", value)
|
49
48
|
end
|
50
49
|
|
51
50
|
def process_attributes(attributes)
|
@@ -24,12 +24,16 @@ class Fabrication::Schematic
|
|
24
24
|
|
25
25
|
def generate(options={}, overrides={}, &block)
|
26
26
|
attributes = merge(overrides, &block).attributes
|
27
|
-
|
27
|
+
if options[:attributes]
|
28
|
+
to_hash(attributes, overrides)
|
29
|
+
else
|
30
|
+
generator.new(klass).generate(options, attributes)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def initialize_copy(original)
|
31
35
|
self.attributes = original.attributes.map do |a|
|
32
|
-
Attribute.new(a.name, a.params, a.value)
|
36
|
+
Fabrication::Attribute.new(a.name, a.params, a.value)
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -38,10 +42,9 @@ class Fabrication::Schematic
|
|
38
42
|
schematic.instance_eval(&block) if block_given?
|
39
43
|
overrides.each do |name, value|
|
40
44
|
if attribute = schematic.attribute(name)
|
41
|
-
attribute.params
|
42
|
-
attribute.value = value
|
45
|
+
attribute.update!(:params => nil, :value => value)
|
43
46
|
else
|
44
|
-
schematic.attributes << Attribute.new(name, nil, value)
|
47
|
+
schematic.attributes << Fabrication::Attribute.new(name, nil, value)
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
@@ -49,20 +52,18 @@ class Fabrication::Schematic
|
|
49
52
|
|
50
53
|
def method_missing(method_name, *args, &block)
|
51
54
|
method_name = parse_method_name(method_name, args)
|
52
|
-
if
|
53
|
-
|
54
|
-
|
55
|
-
attr.value = block
|
56
|
-
else
|
57
|
-
attr.params = nil
|
58
|
-
attr.value = args.first
|
59
|
-
end
|
55
|
+
if args.empty? or args.first.is_a?(Hash)
|
56
|
+
params = args.first || {}
|
57
|
+
value = block_given? ? block : generate_value(method_name, params)
|
60
58
|
else
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
params = {}
|
60
|
+
value = args.first
|
61
|
+
end
|
62
|
+
|
63
|
+
if attr = attribute(method_name)
|
64
|
+
attr.update!(:params => params, :value => value)
|
65
|
+
else
|
66
|
+
attributes.push(Fabrication::Attribute.new(method_name, params, value))
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
@@ -75,14 +76,21 @@ class Fabrication::Schematic
|
|
75
76
|
method_name
|
76
77
|
end
|
77
78
|
|
78
|
-
|
79
|
-
attr_accessor :name, :params, :value
|
79
|
+
private
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
def generate_value(name, params)
|
82
|
+
name = name.to_s
|
83
|
+
name = name.singularize if name.respond_to?(:singularize)
|
84
|
+
params[:count] ||= 1 if !params[:count] && name != name.to_s
|
85
|
+
Proc.new { Fabricate(name.to_sym) }
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_hash(attrs, overrides)
|
89
|
+
hash = defined?(HashWithIndifferentAccess) ? HashWithIndifferentAccess.new : {}
|
90
|
+
attributes.inject(hash) do |hash, attribute|
|
91
|
+
value = attribute.value.respond_to?(:call) ? attribute.value.call : attribute.value
|
92
|
+
hash.merge(attribute.name => value)
|
93
|
+
end.merge(overrides)
|
86
94
|
end
|
87
95
|
|
88
96
|
end
|
data/lib/fabrication/version.rb
CHANGED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fabrication::Attribute do
|
4
|
+
|
5
|
+
describe ".new" do
|
6
|
+
|
7
|
+
context "with name, params, and a static value" do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Fabrication::Attribute.new("a", {:b => 1}, "c")
|
11
|
+
end
|
12
|
+
|
13
|
+
its(:name) { should == "a" }
|
14
|
+
its(:params) { should == {:b => 1} }
|
15
|
+
its(:value) { should == "c" }
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with a block value" do
|
20
|
+
|
21
|
+
subject do
|
22
|
+
Fabrication::Attribute.new("a", nil, Proc.new { "c" })
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a proc for a value" do
|
26
|
+
Proc.should === subject.value
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with a nil value" do
|
32
|
+
|
33
|
+
subject do
|
34
|
+
Fabrication::Attribute.new("a", nil, nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
its(:value) { should be_nil }
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with nil params" do
|
42
|
+
|
43
|
+
subject do
|
44
|
+
Fabrication::Attribute.new("a", nil, nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
its(:params) { should be_nil }
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#update!" do
|
54
|
+
|
55
|
+
let(:attr) do
|
56
|
+
Fabrication::Attribute.new("a", nil, nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with name, params, and a static value" do
|
60
|
+
|
61
|
+
subject { attr }
|
62
|
+
before do
|
63
|
+
attr.update!(:params => { :b => :c }, :value => "d")
|
64
|
+
end
|
65
|
+
|
66
|
+
its(:params) { should == { :b => :c } }
|
67
|
+
its(:value) { should == "d" }
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with a block value" do
|
72
|
+
|
73
|
+
before do
|
74
|
+
attr.update!(:value => Proc.new { "c" })
|
75
|
+
end
|
76
|
+
|
77
|
+
it "has a proc for a value" do
|
78
|
+
Proc.should === attr.value
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with a nil value" do
|
84
|
+
|
85
|
+
subject { attr }
|
86
|
+
before do
|
87
|
+
attr.update!(:value => nil)
|
88
|
+
end
|
89
|
+
|
90
|
+
its(:value) { should be_nil }
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with nil params" do
|
95
|
+
|
96
|
+
subject { attr }
|
97
|
+
before do
|
98
|
+
attr.update!(:params => nil)
|
99
|
+
end
|
100
|
+
|
101
|
+
its(:params) { should be_nil }
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/spec/fabrication_spec.rb
CHANGED
@@ -5,6 +5,12 @@ describe Fabrication do
|
|
5
5
|
context 'static fields' do
|
6
6
|
|
7
7
|
let(:person) { Fabricate(:person, :last_name => 'Awesome') }
|
8
|
+
let(:location) { Fabricate(:location) }
|
9
|
+
let(:dog) do
|
10
|
+
Fabricate(:dog) do
|
11
|
+
name nil
|
12
|
+
end
|
13
|
+
end
|
8
14
|
|
9
15
|
it 'has the default first name' do
|
10
16
|
person.first_name.should == 'John'
|
@@ -18,6 +24,18 @@ describe Fabrication do
|
|
18
24
|
Fabricate(:person).should_not == person
|
19
25
|
end
|
20
26
|
|
27
|
+
it "has the latitude" do
|
28
|
+
location.lat.should == 35
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has the longitude" do
|
32
|
+
location.lng.should == 40
|
33
|
+
end
|
34
|
+
|
35
|
+
it "handles nil values" do
|
36
|
+
dog.name.should be_nil
|
37
|
+
end
|
38
|
+
|
21
39
|
end
|
22
40
|
|
23
41
|
context 'block generated fields' do
|
@@ -38,6 +56,58 @@ describe Fabrication do
|
|
38
56
|
|
39
57
|
end
|
40
58
|
|
59
|
+
context "when referring to other fabricators" do
|
60
|
+
|
61
|
+
let(:person) { Fabricate(:person) }
|
62
|
+
|
63
|
+
it "has the latitude" do
|
64
|
+
person.location.lat.should == 35
|
65
|
+
end
|
66
|
+
|
67
|
+
it "has the longitude" do
|
68
|
+
person.location.lng.should == 40
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with a count" do
|
72
|
+
|
73
|
+
context "of one" do
|
74
|
+
|
75
|
+
let(:greyhound) do
|
76
|
+
Fabricate(:greyhound) do
|
77
|
+
locations(:count => 1)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have one location" do
|
82
|
+
greyhound.locations.size.should == 1
|
83
|
+
greyhound.locations.first.lat.should == 35
|
84
|
+
greyhound.locations.first.lng.should == 40
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context "of two" do
|
90
|
+
|
91
|
+
let(:greyhound) do
|
92
|
+
Fabricate(:greyhound) do
|
93
|
+
locations(:count => 2)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have two locations" do
|
98
|
+
greyhound.locations.size.should == 2
|
99
|
+
greyhound.locations.each do |loc|
|
100
|
+
loc.lat.should == 35
|
101
|
+
loc.lng.should == 40
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
41
111
|
context 'with the generation parameter' do
|
42
112
|
|
43
113
|
let(:person) do
|
@@ -96,12 +166,12 @@ describe Fabrication do
|
|
96
166
|
before(:all) do
|
97
167
|
Fabricator(:company) do
|
98
168
|
name { Faker::Company.name }
|
99
|
-
divisions!(:count => 4)
|
169
|
+
divisions!(:count => 4)
|
100
170
|
after_create { |o| o.update_attribute(:city, "Jacksonville Beach") }
|
101
171
|
end
|
102
172
|
|
103
173
|
Fabricator(:other_company, :from => :company) do
|
104
|
-
divisions(:count => 2)
|
174
|
+
divisions(:count => 2)
|
105
175
|
after_build { |o| o.name = "Crazysauce" }
|
106
176
|
end
|
107
177
|
end
|
data/spec/schematic_spec.rb
CHANGED
@@ -40,8 +40,29 @@ describe Fabrication::Schematic do
|
|
40
40
|
|
41
41
|
describe "#generate" do
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
context "an instance" do
|
44
|
+
|
45
|
+
it "generates a new instance" do
|
46
|
+
schematic.generate.should be_kind_of(OpenStruct)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "an attributes hash" do
|
52
|
+
|
53
|
+
let(:hash) { schematic.generate(:attributes => true) }
|
54
|
+
|
55
|
+
it "generates a hash with the object's attributes" do
|
56
|
+
hash.should be_kind_of(Hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "has the correct attributes" do
|
60
|
+
hash.size.should == 3
|
61
|
+
hash[:name].should == 'Orgasmo'
|
62
|
+
hash[:something].should == "hi!"
|
63
|
+
hash[:another_thing].should == 25
|
64
|
+
end
|
65
|
+
|
45
66
|
end
|
46
67
|
|
47
68
|
end
|
@@ -55,7 +76,7 @@ describe Fabrication::Schematic do
|
|
55
76
|
it "stored 'name' correctly" do
|
56
77
|
attribute = subject.attribute(:name)
|
57
78
|
attribute.name.should == :name
|
58
|
-
attribute.params.should
|
79
|
+
attribute.params.should == {}
|
59
80
|
attribute.value.should == "Orgasmo"
|
60
81
|
end
|
61
82
|
|
@@ -70,7 +91,7 @@ describe Fabrication::Schematic do
|
|
70
91
|
it "stored 'another_thing' correctly" do
|
71
92
|
attribute = subject.attribute(:another_thing)
|
72
93
|
attribute.name.should == :another_thing
|
73
|
-
attribute.params.should
|
94
|
+
attribute.params.should == {}
|
74
95
|
Proc.should === attribute.value
|
75
96
|
attribute.value.call.should == 25
|
76
97
|
end
|
@@ -90,7 +111,7 @@ describe Fabrication::Schematic do
|
|
90
111
|
it "stored 'name' correctly" do
|
91
112
|
attribute = subject.attribute(:name)
|
92
113
|
attribute.name.should == :name
|
93
|
-
attribute.params.should
|
114
|
+
attribute.params.should == {}
|
94
115
|
Proc.should === attribute.value
|
95
116
|
attribute.value.call.should == "Willis"
|
96
117
|
end
|
@@ -98,7 +119,7 @@ describe Fabrication::Schematic do
|
|
98
119
|
it "stored 'something' correctly" do
|
99
120
|
attribute = subject.attribute(:something)
|
100
121
|
attribute.name.should == :something
|
101
|
-
attribute.params.should
|
122
|
+
attribute.params.should == {}
|
102
123
|
attribute.value.should == "Else!"
|
103
124
|
end
|
104
125
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
class Dog
|
2
|
+
attr_accessor :name, :breed, :locations
|
3
|
+
end
|
4
|
+
|
5
|
+
class Location
|
6
|
+
attr_accessor :lat, :lng
|
7
|
+
end
|
8
|
+
|
1
9
|
class Person
|
2
|
-
attr_accessor :age, :first_name, :last_name, :shoes
|
10
|
+
attr_accessor :age, :first_name, :last_name, :shoes, :location
|
3
11
|
end
|
4
12
|
|
5
|
-
|
6
|
-
|
13
|
+
Fabricator(:greyhound, :from => :dog) do
|
14
|
+
breed "greyhound"
|
15
|
+
locations(:count => 2)
|
16
|
+
end
|
17
|
+
|
18
|
+
Fabricator(:location) do
|
19
|
+
lat 35
|
20
|
+
lng 40
|
7
21
|
end
|
8
22
|
|
9
23
|
Fabricator(:person) do
|
@@ -11,8 +25,5 @@ Fabricator(:person) do
|
|
11
25
|
last_name { Faker::Name.last_name }
|
12
26
|
age { rand(100) }
|
13
27
|
shoes(:count => 10) { |person, i| "shoe #{i}" }
|
14
|
-
|
15
|
-
|
16
|
-
Fabricator(:greyhound, :from => :dog) do
|
17
|
-
breed "greyhound"
|
28
|
+
location
|
18
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 15
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Paul Elliott
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-08
|
17
|
+
date: 2010-09-08 00:00:00 -04:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 27
|
30
28
|
segments:
|
31
29
|
- 1
|
32
30
|
- 3
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 15
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
- 4
|
@@ -58,12 +55,11 @@ dependencies:
|
|
58
55
|
requirements:
|
59
56
|
- - ">="
|
60
57
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 9
|
62
58
|
segments:
|
63
|
-
- 2
|
64
59
|
- 3
|
65
|
-
-
|
66
|
-
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
version: 3.0.0
|
67
63
|
type: :development
|
68
64
|
version_requirements: *id003
|
69
65
|
- !ruby/object:Gem::Dependency
|
@@ -74,7 +70,6 @@ dependencies:
|
|
74
70
|
requirements:
|
75
71
|
- - ">="
|
76
72
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 27
|
78
73
|
segments:
|
79
74
|
- 1
|
80
75
|
- 3
|
@@ -90,12 +85,11 @@ dependencies:
|
|
90
85
|
requirements:
|
91
86
|
- - ">="
|
92
87
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 21
|
94
88
|
segments:
|
95
89
|
- 1
|
96
90
|
- 0
|
97
|
-
-
|
98
|
-
version: 1.0.
|
91
|
+
- 7
|
92
|
+
version: 1.0.7
|
99
93
|
type: :development
|
100
94
|
version_requirements: *id005
|
101
95
|
- !ruby/object:Gem::Dependency
|
@@ -106,12 +100,13 @@ dependencies:
|
|
106
100
|
requirements:
|
107
101
|
- - ">="
|
108
102
|
- !ruby/object:Gem::Version
|
109
|
-
hash: 49
|
110
103
|
segments:
|
111
|
-
-
|
112
|
-
-
|
113
|
-
-
|
114
|
-
|
104
|
+
- 2
|
105
|
+
- 0
|
106
|
+
- 0
|
107
|
+
- beta
|
108
|
+
- 17
|
109
|
+
version: 2.0.0.beta.17
|
115
110
|
type: :development
|
116
111
|
version_requirements: *id006
|
117
112
|
description: Fabrication is an object generation framework for ActiveRecord and Mongoid. It has a flexible syntax and lazily generates ActiveRecord associations!
|
@@ -124,6 +119,7 @@ extensions: []
|
|
124
119
|
extra_rdoc_files: []
|
125
120
|
|
126
121
|
files:
|
122
|
+
- lib/fabrication/attribute.rb
|
127
123
|
- lib/fabrication/errors.rb
|
128
124
|
- lib/fabrication/fabricator.rb
|
129
125
|
- lib/fabrication/generator/active_record.rb
|
@@ -134,6 +130,7 @@ files:
|
|
134
130
|
- lib/fabrication/support.rb
|
135
131
|
- lib/fabrication/version.rb
|
136
132
|
- lib/fabrication.rb
|
133
|
+
- spec/fabrication/attribute_spec.rb
|
137
134
|
- spec/fabrication_spec.rb
|
138
135
|
- spec/fabricator_spec.rb
|
139
136
|
- spec/fabricators/cool_object_fabricator.rb
|
@@ -164,7 +161,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
161
|
requirements:
|
165
162
|
- - ">="
|
166
163
|
- !ruby/object:Gem::Version
|
167
|
-
hash: 3
|
168
164
|
segments:
|
169
165
|
- 0
|
170
166
|
version: "0"
|
@@ -173,7 +169,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
169
|
requirements:
|
174
170
|
- - ">="
|
175
171
|
- !ruby/object:Gem::Version
|
176
|
-
hash: 3
|
177
172
|
segments:
|
178
173
|
- 0
|
179
174
|
version: "0"
|