ianwhite-pickle 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/README.rdoc +3 -0
- data/lib/pickle/adapter.rb +7 -8
- data/lib/pickle/version.rb +1 -1
- data/rails_generators/pickle/templates/env.rb +1 -1
- data/spec/lib/pickle_adapter_spec.rb +56 -51
- metadata +2 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -53,6 +53,9 @@ you've written, you can just do stuff like
|
|
53
53
|
|
54
54
|
==== Machinst: require your blueprints and reset Shams
|
55
55
|
|
56
|
+
(The latest version of pickle supports {multiple blueprints}[http://github.com/notahat/machinist/commit/d6492e6927a8aa1819926e48b22377171fd20496], for
|
57
|
+
earlier versions of machinist use pickle <= 0.1.10)
|
58
|
+
|
56
59
|
In your <tt>features/support/env.rb</tt> add the following lines at the bottom
|
57
60
|
|
58
61
|
require "#{Rails.root}/spec/blueprints" # or wherever they live
|
data/lib/pickle/adapter.rb
CHANGED
@@ -36,22 +36,21 @@ module Pickle
|
|
36
36
|
def self.factories
|
37
37
|
factories = []
|
38
38
|
model_classes.each do |klass|
|
39
|
-
|
40
|
-
|
41
|
-
klass.methods.select{|m| m =~ /^make_/ && m !~ /_unsaved$/}.each do |method|
|
42
|
-
factories << new(klass, method)
|
39
|
+
if blueprints = klass.instance_variable_get('@blueprints')
|
40
|
+
blueprints.keys.each {|blueprint| factories << new(klass, blueprint)}
|
43
41
|
end
|
44
42
|
end
|
45
43
|
factories
|
46
44
|
end
|
47
45
|
|
48
|
-
def initialize(klass,
|
49
|
-
@klass, @
|
50
|
-
@name =
|
46
|
+
def initialize(klass, blueprint)
|
47
|
+
@klass, @blueprint = klass, blueprint
|
48
|
+
@name = @klass.name.underscore.gsub('/','_')
|
49
|
+
@name = "#{@blueprint}_#{@name}" unless @blueprint == :master
|
51
50
|
end
|
52
51
|
|
53
52
|
def create(attrs = {})
|
54
|
-
@klass.send(@
|
53
|
+
@klass.send(:make, @blueprint, attrs)
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
data/lib/pickle/version.rb
CHANGED
@@ -38,18 +38,22 @@ describe Pickle::Adapter do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe
|
41
|
+
describe "adapters: " do
|
42
42
|
before do
|
43
|
-
|
44
|
-
@
|
45
|
-
@
|
46
|
-
Pickle::Adapter::ActiveRecord.stub!(:model_classes).and_return([@klass1, @klass2])
|
43
|
+
@klass1 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('One')}
|
44
|
+
@klass2 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('One::Two')}
|
45
|
+
@klass3 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('Three')}
|
47
46
|
end
|
48
47
|
|
49
|
-
describe
|
50
|
-
|
48
|
+
describe 'ActiveRecord' do
|
49
|
+
before do
|
50
|
+
Pickle::Adapter::ActiveRecord.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
|
51
|
+
end
|
52
|
+
|
53
|
+
it ".factories should create one for each active record class" do
|
51
54
|
Pickle::Adapter::ActiveRecord.should_receive(:new).with(@klass1).once
|
52
55
|
Pickle::Adapter::ActiveRecord.should_receive(:new).with(@klass2).once
|
56
|
+
Pickle::Adapter::ActiveRecord.should_receive(:new).with(@klass3).once
|
53
57
|
Pickle::Adapter::ActiveRecord.factories
|
54
58
|
end
|
55
59
|
|
@@ -57,100 +61,101 @@ describe Pickle::Adapter do
|
|
57
61
|
before do
|
58
62
|
@factory = Pickle::Adapter::ActiveRecord.new(@klass2)
|
59
63
|
end
|
60
|
-
|
64
|
+
|
61
65
|
it "should have underscored (s/_) name of Class as #name" do
|
62
66
|
@factory.name.should == 'one_two'
|
63
67
|
end
|
64
|
-
|
68
|
+
|
65
69
|
it "#create(attrs) should call Class.create!(attrs)" do
|
66
70
|
@klass2.should_receive(:create!).with({:key => "val"})
|
67
71
|
@factory.create(:key => "val")
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
71
|
-
end
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
describe 'FactoryGirl' do
|
77
|
+
before do
|
78
|
+
Pickle::Adapter::FactoryGirl.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
|
79
|
+
@orig_factories, Factory.factories = Factory.factories, {}
|
80
|
+
|
81
|
+
Factory.define(:one, :class => @klass1) {}
|
82
|
+
Factory.define(:two, :class => @klass2) {}
|
83
|
+
@factory1 = Factory.factories[:one]
|
84
|
+
@factory2 = Factory.factories[:two]
|
85
|
+
end
|
86
|
+
|
87
|
+
after do
|
88
|
+
Factory.factories = @orig_factories
|
89
|
+
end
|
80
90
|
|
81
|
-
|
82
|
-
it "should create one for each factory" do
|
91
|
+
it ".factories should create one for each factory" do
|
83
92
|
Pickle::Adapter::FactoryGirl.should_receive(:new).with(@factory1).once
|
84
93
|
Pickle::Adapter::FactoryGirl.should_receive(:new).with(@factory2).once
|
85
94
|
Pickle::Adapter::FactoryGirl.factories
|
86
95
|
end
|
87
|
-
|
96
|
+
|
88
97
|
describe ".new(factory)" do
|
89
98
|
before do
|
90
99
|
@factory = Pickle::Adapter::FactoryGirl.new(@factory1)
|
91
100
|
end
|
92
|
-
|
101
|
+
|
93
102
|
it "should have name of factory_name" do
|
94
103
|
@factory.name.should == 'one'
|
95
104
|
end
|
96
|
-
|
105
|
+
|
97
106
|
it "should have klass of build_class" do
|
98
|
-
@factory.klass.should == @
|
107
|
+
@factory.klass.should == @klass1
|
99
108
|
end
|
100
|
-
|
109
|
+
|
101
110
|
it "#create(attrs) should call Factory(<:key>, attrs)" do
|
102
111
|
Factory.should_receive(:create).with("one", {:key => "val"})
|
103
112
|
@factory.create(:key => "val")
|
104
113
|
end
|
105
114
|
end
|
106
115
|
end
|
107
|
-
end
|
108
116
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
@klass3.instance_variable_set('@blueprint', true)
|
117
|
-
Pickle::Adapter::Machinist.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
|
118
|
-
end
|
119
|
-
|
120
|
-
describe ".factories" do
|
121
|
-
it "should create one for each machinist make method, except make_unsaved" do
|
122
|
-
Pickle::Adapter::Machinist.should_receive(:new).with(@klass1, 'make').once
|
123
|
-
Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, 'make').once
|
124
|
-
Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, 'make_special').once
|
125
|
-
Pickle::Adapter::Machinist.factories
|
117
|
+
describe 'Machinist' do
|
118
|
+
before do
|
119
|
+
Pickle::Adapter::Machinist.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
|
120
|
+
|
121
|
+
@klass1.blueprint {}
|
122
|
+
@klass3.blueprint {}
|
123
|
+
@klass3.blueprint(:special) {}
|
126
124
|
end
|
127
125
|
|
128
|
-
|
126
|
+
it ".factories should create one for each master blueprint, and special case" do
|
127
|
+
Pickle::Adapter::Machinist.should_receive(:new).with(@klass1, :master).once
|
128
|
+
Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, :master).once
|
129
|
+
Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, :special).once
|
130
|
+
Pickle::Adapter::Machinist.factories
|
131
|
+
end
|
132
|
+
|
133
|
+
describe ".new(Class, :master)" do
|
129
134
|
before do
|
130
|
-
@factory = Pickle::Adapter::Machinist.new(@klass1,
|
135
|
+
@factory = Pickle::Adapter::Machinist.new(@klass1, :master)
|
131
136
|
end
|
132
137
|
|
133
138
|
it "should have underscored (s/_) name of Class as #name" do
|
134
139
|
@factory.name.should == 'one'
|
135
140
|
end
|
136
141
|
|
137
|
-
it "#create(attrs) should call Class.make(attrs)" do
|
138
|
-
@klass1.should_receive(:make).with({:key => "val"})
|
142
|
+
it "#create(attrs) should call Class.make(:master, attrs)" do
|
143
|
+
@klass1.should_receive(:make).with(:master, {:key => "val"})
|
139
144
|
@factory.create(:key => "val")
|
140
145
|
end
|
141
146
|
end
|
142
147
|
|
143
|
-
describe ".new(Class,
|
148
|
+
describe ".new(Class, :special)" do
|
144
149
|
before do
|
145
|
-
@factory = Pickle::Adapter::Machinist.new(@klass3,
|
150
|
+
@factory = Pickle::Adapter::Machinist.new(@klass3, :special)
|
146
151
|
end
|
147
152
|
|
148
153
|
it "should have 'special_<Class name>' as #name" do
|
149
|
-
@factory.name.should == '
|
154
|
+
@factory.name.should == 'special_three'
|
150
155
|
end
|
151
156
|
|
152
|
-
it "#create(attrs) should call Class.
|
153
|
-
@klass3.should_receive(:
|
157
|
+
it "#create(attrs) should call Class.make(:special, attrs)" do
|
158
|
+
@klass3.should_receive(:make).with(:special, {:key => "val"})
|
154
159
|
@factory.create(:key => "val")
|
155
160
|
end
|
156
161
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ianwhite-pickle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian White
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-22 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|