pickle 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock.development +33 -35
- data/History.txt +15 -0
- data/README.md +566 -0
- data/features/step_definitions/email_steps.rb +11 -9
- data/features/step_definitions/pickle_steps.rb +9 -4
- data/lib/pickle.rb +3 -3
- data/lib/pickle/adapter.rb +16 -4
- data/lib/pickle/adapters/active_record.rb +17 -7
- data/lib/pickle/adapters/data_mapper.rb +1 -1
- data/lib/pickle/adapters/mongoid.rb +13 -3
- data/lib/pickle/config.rb +8 -8
- data/lib/pickle/email.rb +13 -3
- data/lib/pickle/email/parser.rb +2 -2
- data/lib/pickle/parser.rb +9 -9
- data/lib/pickle/parser/matchers.rb +18 -18
- data/lib/pickle/path.rb +3 -3
- data/lib/pickle/session.rb +72 -39
- data/lib/pickle/session/parser.rb +3 -3
- data/lib/pickle/version.rb +1 -1
- data/pickle.gemspec +3 -3
- data/rails_generators/pickle/templates/email_steps.rb +11 -9
- data/rails_generators/pickle/templates/pickle_steps.rb +9 -4
- data/spec/pickle/adapter_spec.rb +40 -52
- data/spec/pickle/email_spec.rb +37 -16
- data/spec/pickle/session_spec.rb +21 -5
- metadata +4 -6
- data/README.rdoc +0 -483
data/lib/pickle/path.rb
CHANGED
@@ -21,7 +21,7 @@ module Pickle
|
|
21
21
|
pickle_path_for_resources_action_segment(resources, options[:action], options[:segment])
|
22
22
|
end or raise "Could not figure out a path for #{pickle_names.inspect} #{options.inspect}"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
protected
|
26
26
|
def find_pickle_path_using_action_segment_combinations(resources, parts)
|
27
27
|
path = nil
|
@@ -32,7 +32,7 @@ module Pickle
|
|
32
32
|
end
|
33
33
|
path
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def pickle_path_for_resources_action_segment(resources, action, segment)
|
37
37
|
action.blank? or action = action.downcase.gsub(' ','_')
|
38
38
|
segment.blank? or segment = segment.downcase.gsub(' ','_')
|
@@ -42,4 +42,4 @@ module Pickle
|
|
42
42
|
send("#{parts.join('_')}_path", *models) rescue nil
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
data/lib/pickle/session.rb
CHANGED
@@ -2,29 +2,29 @@ module Pickle
|
|
2
2
|
module Session
|
3
3
|
class ModelNotKnownError < RuntimeError
|
4
4
|
attr_reader :name
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(name, message = nil)
|
7
7
|
@name = name
|
8
8
|
@message = message.presence || "The model: '#{name}' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario."
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def to_s
|
12
12
|
@message
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
class ModelNotFoundError < RuntimeError
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
class << self
|
20
20
|
def included(world_class)
|
21
21
|
proxy_to_pickle_parser(world_class)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def extended(world_object)
|
25
25
|
proxy_to_pickle_parser(class << world_object; self; end) # metaclass is not 2.1 compatible
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
protected
|
29
29
|
def proxy_to_pickle_parser(world_class)
|
30
30
|
world_class.class_eval do
|
@@ -35,16 +35,23 @@ module Pickle
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def create_model(pickle_ref, fields = nil)
|
40
|
-
|
41
|
-
raise ArgumentError, "Can't create with an ordinal (e.g. 1st user)" if label.is_a?(Integer)
|
42
|
-
fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
|
43
|
-
record = pickle_config.factories[factory].create(fields)
|
44
|
-
store_model(factory, label, record)
|
45
|
-
record
|
40
|
+
create_or_build_model(:create, 1, pickle_ref, fields)
|
46
41
|
end
|
47
|
-
|
42
|
+
|
43
|
+
def create_models(count, pickle_ref, fields = nil)
|
44
|
+
create_or_build_model(:create, count, pickle_ref, fields)
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_model(pickle_ref, fields = nil)
|
48
|
+
create_or_build_model(:build, 1, pickle_ref, fields)
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_models(count, pickle_ref, fields = nil)
|
52
|
+
create_or_build_model(:build, count, pickle_ref, fields)
|
53
|
+
end
|
54
|
+
|
48
55
|
# if a column exists in the table which matches the singular factory name, this is used as the pickle ref
|
49
56
|
def create_models_from_table(plural_factory, table)
|
50
57
|
factory = plural_factory.singularize
|
@@ -68,14 +75,14 @@ module Pickle
|
|
68
75
|
|
69
76
|
record
|
70
77
|
end
|
71
|
-
|
78
|
+
|
72
79
|
def find_model!(name, fields = nil)
|
73
80
|
find_model(name, fields) or raise ModelNotFoundError, "Can't find #{name}#{" with #{fields}" if fields.present?} from the orm in this scenario"
|
74
81
|
end
|
75
|
-
|
82
|
+
|
76
83
|
def find_models(factory, fields = nil)
|
77
84
|
factory = pickle_parser.canonical(factory)
|
78
|
-
|
85
|
+
|
79
86
|
models_by_index(factory).clear
|
80
87
|
|
81
88
|
model_class = pickle_config.factories[factory].klass
|
@@ -84,7 +91,7 @@ module Pickle
|
|
84
91
|
|
85
92
|
records.each {|record| store_model(factory, nil, record)}
|
86
93
|
end
|
87
|
-
|
94
|
+
|
88
95
|
# if a column exists in the table which matches the singular factory name, this is used as the pickle ref
|
89
96
|
def find_models_from_table(plural_factory, table)
|
90
97
|
factory = plural_factory.singularize
|
@@ -93,11 +100,11 @@ module Pickle
|
|
93
100
|
find_model(pickle_ref, hash)
|
94
101
|
end
|
95
102
|
end
|
96
|
-
|
103
|
+
|
97
104
|
# return the original model stored by create_model or find_model
|
98
105
|
def created_model(name)
|
99
106
|
factory, name_or_index = *parse_model(name)
|
100
|
-
|
107
|
+
|
101
108
|
if name_or_index.blank?
|
102
109
|
models_by_index(factory).last
|
103
110
|
elsif name_or_index.is_a?(Integer)
|
@@ -111,46 +118,59 @@ module Pickle
|
|
111
118
|
def created_model?(name)
|
112
119
|
(created_model(name) rescue nil) ? true : false
|
113
120
|
end
|
114
|
-
|
121
|
+
|
115
122
|
# return a newly selected model
|
116
123
|
def model(name)
|
117
124
|
model = created_model(name)
|
118
125
|
return nil unless model
|
119
126
|
Pickle::Adapter.get_model(model.class, model.id)
|
120
127
|
end
|
121
|
-
|
128
|
+
|
122
129
|
# predicate version which raises no errors
|
123
130
|
def model?(name)
|
124
131
|
(model(name) rescue nil) ? true : false
|
125
132
|
end
|
126
|
-
|
133
|
+
|
127
134
|
# like model, but raise an error if it can't be found
|
128
135
|
def model!(name)
|
129
136
|
model(name) or raise ModelNotKnownError, name
|
130
137
|
end
|
131
|
-
|
138
|
+
|
132
139
|
# like created_model, but raise an error if it can't be found
|
133
140
|
def created_model!(name)
|
134
141
|
created_model(name) or raise ModelNotKnownError, name
|
135
142
|
end
|
136
|
-
|
143
|
+
|
137
144
|
# return all original models of specified type
|
138
145
|
def created_models(factory)
|
139
146
|
models_by_index(factory)
|
140
147
|
end
|
141
|
-
|
148
|
+
|
142
149
|
# return all models of specified type (freshly selected from the database)
|
143
150
|
def models(factory)
|
144
151
|
created_models(factory).map do |model|
|
145
152
|
Pickle::Adapter.get_model(model.class, model.id)
|
146
153
|
end
|
147
154
|
end
|
148
|
-
|
155
|
+
|
149
156
|
def respond_to_with_pickle_parser?(method, include_private = false)
|
150
157
|
respond_to_without_pickle_parser?(method, include_private) || pickle_parser.respond_to?(method, include_private)
|
151
158
|
end
|
152
|
-
|
159
|
+
|
153
160
|
protected
|
161
|
+
def create_or_build_model(method, count, pickle_ref, fields = nil)
|
162
|
+
factory, label = *parse_model(pickle_ref)
|
163
|
+
raise ArgumentError, "Can't #{method} with an ordinal (e.g. 1st user)" if label.is_a?(Integer)
|
164
|
+
fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
|
165
|
+
|
166
|
+
count.to_i.times.map do
|
167
|
+
record = pickle_config.factories[factory].send(method, fields)
|
168
|
+
store_model(factory, label, record)
|
169
|
+
return record if count == 1
|
170
|
+
record
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
154
174
|
def method_missing_with_pickle_parser(method, *args, &block)
|
155
175
|
if pickle_parser.respond_to?(method)
|
156
176
|
pickle_parser.send(method, *args, &block)
|
@@ -158,12 +178,12 @@ module Pickle
|
|
158
178
|
method_missing_without_pickle_parser(method, *args, &block)
|
159
179
|
end
|
160
180
|
end
|
161
|
-
|
181
|
+
|
162
182
|
def pickle_parser=(parser)
|
163
183
|
parser.session = self
|
164
184
|
@pickle_parser = parser
|
165
185
|
end
|
166
|
-
|
186
|
+
|
167
187
|
def pickle_parser
|
168
188
|
@pickle_parser or self.pickle_parser = Pickle.parser
|
169
189
|
end
|
@@ -172,37 +192,50 @@ module Pickle
|
|
172
192
|
pickle_parser.config
|
173
193
|
end
|
174
194
|
|
175
|
-
def convert_models_to_attributes(
|
195
|
+
def convert_models_to_attributes(klass, attrs)
|
196
|
+
columns = nil
|
176
197
|
conditions = {}
|
198
|
+
|
177
199
|
attrs.each do |key, val|
|
178
|
-
if
|
179
|
-
|
180
|
-
|
200
|
+
if supported = supported_association_model_type?(val) or val.nil?
|
201
|
+
columns ||= Pickle::Adapter.column_names(klass)
|
202
|
+
end
|
203
|
+
|
204
|
+
if supported && columns.include?("#{key}_id")
|
181
205
|
conditions["#{key}_id"] = val.id
|
182
|
-
conditions["#{key}_type"] = val.class.base_class.name if
|
206
|
+
conditions["#{key}_type"] = val.class.base_class.name if columns.include?("#{key}_type")
|
207
|
+
elsif val.nil? && columns.include?("#{key}_id") && !columns.include?("#{key}")
|
208
|
+
# NOOP
|
183
209
|
else
|
184
210
|
conditions[key] = val
|
185
211
|
end
|
186
212
|
end
|
213
|
+
|
187
214
|
conditions
|
188
215
|
end
|
189
|
-
|
216
|
+
|
217
|
+
def supported_association_model_type?(associated_model)
|
218
|
+
(defined?(ActiveRecord::Base) && associated_model.is_a?(ActiveRecord::Base)) ||
|
219
|
+
(defined?(DataMapper::Model) && associated_model.is_a?(DataMapper::Model)) ||
|
220
|
+
(defined?(Mongoid::Document) && associated_model.is_a?(Mongoid::Document))
|
221
|
+
end
|
222
|
+
|
190
223
|
def models_by_name(factory)
|
191
224
|
@models_by_name ||= {}
|
192
225
|
@models_by_name[pickle_parser.canonical(factory)] ||= {}
|
193
226
|
end
|
194
|
-
|
227
|
+
|
195
228
|
def models_by_index(factory)
|
196
229
|
@models_by_index ||= {}
|
197
230
|
@models_by_index[pickle_parser.canonical(factory)] ||= []
|
198
231
|
end
|
199
|
-
|
232
|
+
|
200
233
|
# if the factory name != the model name, store under both names
|
201
234
|
def store_model(factory, name, record)
|
202
235
|
store_record(record.class.name, name, record) unless pickle_parser.canonical(factory) == pickle_parser.canonical(record.class.name)
|
203
236
|
store_record(factory, name, record)
|
204
237
|
end
|
205
|
-
|
238
|
+
|
206
239
|
def store_record(factory, name, record)
|
207
240
|
models_by_name(factory)[name] = record
|
208
241
|
models_by_index(factory) << record
|
@@ -18,8 +18,8 @@ module Pickle
|
|
18
18
|
else
|
19
19
|
parse_field_without_model(field)
|
20
20
|
end
|
21
|
-
end
|
22
|
-
|
21
|
+
end
|
22
|
+
|
23
23
|
def parse_hash(hash)
|
24
24
|
hash.inject({}) do |parsed, (key, val)|
|
25
25
|
if session && val =~ /^#{capture_model}$/
|
@@ -31,4 +31,4 @@ module Pickle
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
data/lib/pickle/version.rb
CHANGED
data/pickle.gemspec
CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.version = Pickle::VERSION.dup
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.licenses = ["MIT"]
|
9
|
-
s.authors = ["Ian White", "James Le Cuirot"
|
9
|
+
s.authors = ["Ian White", "James Le Cuirot"]
|
10
10
|
s.description = "Easy model creation and reference in your cucumber features"
|
11
11
|
s.summary = "Easy model creation and reference in your cucumber features."
|
12
|
-
s.email = ["ian.w.white@gmail.com", "chewi@aura-online.co.uk"
|
12
|
+
s.email = ["ian.w.white@gmail.com", "chewi@aura-online.co.uk"]
|
13
13
|
s.homepage = "https://github.com/ianwhite/pickle"
|
14
14
|
|
15
15
|
s.rubyforge_project = "pickle"
|
@@ -34,5 +34,5 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.add_development_dependency "machinist", "~>2.0"
|
35
35
|
s.add_development_dependency "database_cleaner"
|
36
36
|
s.add_development_dependency "capybara"
|
37
|
-
s.add_development_dependency "sqlite3
|
37
|
+
s.add_development_dependency "sqlite3"
|
38
38
|
end
|
@@ -27,37 +27,39 @@ When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
|
|
27
27
|
end
|
28
28
|
|
29
29
|
Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
|
30
|
-
|
30
|
+
actual = emails("to: \"#{email_for(to)}\"").size
|
31
|
+
expect(actual).to eq(count.to_i), "Expected #{count} emails but encountered #{actual} delivered to #{to}"
|
31
32
|
end
|
32
33
|
|
33
34
|
Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
|
34
|
-
|
35
|
+
actual = emails(fields).size
|
36
|
+
expect(actual).to eq(count.to_i), "Expected #{count} emails but encountered #{actual} to be delivered with #{fields}"
|
35
37
|
end
|
36
38
|
|
37
39
|
Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
|
38
|
-
expect(email(email_ref, "to: \"#{email_for(to)}\"")).not_to be_nil
|
40
|
+
expect(email(email_ref, "to: \"#{email_for(to)}\"")).not_to be_nil, "Failed to find #{email_ref} delivered to: #{to}"
|
39
41
|
end
|
40
42
|
|
41
43
|
Then(/^#{capture_email} should not be delivered to (.+)$/) do |email_ref, to|
|
42
|
-
expect(email(email_ref, "to: \"#{email_for(to)}\"")).to be_nil
|
44
|
+
expect(email(email_ref, "to: \"#{email_for(to)}\"")).to be_nil, "Unexpectedly found #{email_ref} delivered to: #{to}"
|
43
45
|
end
|
44
46
|
|
45
47
|
Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
|
46
|
-
expect(email(email_ref, fields)).not_to be_nil
|
48
|
+
expect(email(email_ref, fields)).not_to be_nil, "Failed to find #{fields} in #{email_ref}"
|
47
49
|
end
|
48
50
|
|
49
51
|
Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
|
50
|
-
expect(email(email_ref).body).to match(/#{text}/)
|
52
|
+
expect(email(email_ref).body).to match(/#{text}/), "Failed to find \"#{text}\" in #{email_ref}"
|
51
53
|
end
|
52
54
|
|
53
55
|
Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
|
54
|
-
expect(email(email_ref).body).not_to match(/#{text}/)
|
56
|
+
expect(email(email_ref).body).not_to match(/#{text}/), "Unexpectedly found \"#{text}\" in #{email_ref}"
|
55
57
|
end
|
56
58
|
|
57
59
|
Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
|
58
|
-
expect(email(email_ref).body).to match(/#{path_to(page)}/)
|
60
|
+
expect(email(email_ref).body).to match(/#{path_to(page)}/), "Failed to find link to #{page} in #{email_ref}"
|
59
61
|
end
|
60
62
|
|
61
63
|
Then(/^show me the emails?$/) do
|
62
|
-
|
64
|
+
save_and_open_emails
|
63
65
|
end
|
@@ -7,7 +7,7 @@ end
|
|
7
7
|
|
8
8
|
# create n models
|
9
9
|
Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
10
|
-
count
|
10
|
+
create_models(count, plural_factory.singularize, fields)
|
11
11
|
end
|
12
12
|
|
13
13
|
# create models from a table
|
@@ -26,10 +26,15 @@ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# find models with a table
|
29
|
-
Then(/^the following #{capture_plural_factory} should
|
29
|
+
Then(/^the following #{capture_plural_factory} should exist:?$/) do |plural_factory, table|
|
30
30
|
expect(find_models_from_table(plural_factory, table)).not_to be_any(&:nil?)
|
31
31
|
end
|
32
32
|
|
33
|
+
# not find models with a table
|
34
|
+
Then(/^the following #{capture_plural_factory} should not exists?:?$/) do |plural_factory, table|
|
35
|
+
find_models_from_table(plural_factory, table).should be_all(&:nil?)
|
36
|
+
end
|
37
|
+
|
33
38
|
# find exactly n models
|
34
39
|
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
35
40
|
expect(find_models(plural_factory.singularize, fields).size).to eq(count.to_i)
|
@@ -60,7 +65,7 @@ Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |targe
|
|
60
65
|
expect(model!(owner).send(association)).not_to eq(model!(target))
|
61
66
|
end
|
62
67
|
|
63
|
-
# assert model.predicate?
|
68
|
+
# assert model.predicate?
|
64
69
|
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
65
70
|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
66
71
|
expect(model!(name)).to send("have_#{predicate.gsub(' ', '_')}")
|
@@ -83,7 +88,7 @@ end
|
|
83
88
|
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
|
84
89
|
actual_value = model(name).send(attribute)
|
85
90
|
expectation = expectation.gsub("should", "to").gsub(" ", "_")
|
86
|
-
|
91
|
+
|
87
92
|
case expected
|
88
93
|
when 'nil', 'true', 'false'
|
89
94
|
expect(actual_value).send(expectation, eq(eval(expected)))
|
data/spec/pickle/adapter_spec.rb
CHANGED
@@ -15,47 +15,35 @@ describe Pickle::Adapter do
|
|
15
15
|
expect { Pickle::Adapter.new.create }.to raise_error(NotImplementedError)
|
16
16
|
end
|
17
17
|
|
18
|
-
describe ".model_classes" do
|
19
|
-
before do
|
20
|
-
Pickle::Adapter.model_classes = nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
18
|
describe "adapters: " do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
around do |example|
|
20
|
+
begin
|
21
|
+
class One < ActiveRecord::Base; end
|
22
|
+
class One::Two < ActiveRecord::Base; end
|
23
|
+
class Three < ActiveRecord::Base; end
|
24
|
+
example.run
|
25
|
+
ensure
|
26
|
+
Object.send :remove_const, :One
|
27
|
+
Object.send :remove_const, :Three
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'ActiveRecord' do
|
32
|
-
|
33
|
-
#DEPRECATION WARNING: subclasses is deprecated and will be removed from Rails 3.0 (use descendants instead). (called from __send__ at /Users/pivotal/workspace/factorylabs/protosite/vendor/cache/ruby/1.8/gems/pickle-0.3.1/lib/pickle/adapters/active_record.rb:21)
|
34
|
-
|
35
|
-
describe ".model_classes" do
|
36
|
-
it "calls .descendants" do
|
37
|
-
expect(::ActiveRecord::Base).to receive(:descendants).and_return([])
|
38
|
-
expect(::ActiveRecord::Base).not_to receive(:subclasses)
|
39
|
-
|
40
|
-
ActiveRecord::Base::PickleAdapter.model_classes
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
32
|
describe 'with class stubs' do
|
45
33
|
before do
|
46
|
-
allow(Pickle::Adapter::Orm).to receive(:model_classes).and_return([
|
34
|
+
allow(Pickle::Adapter::Orm).to receive(:model_classes).and_return([One, One::Two, Three])
|
47
35
|
end
|
48
36
|
|
49
37
|
it ".factories should create one for each active record class" do
|
50
|
-
expect(Pickle::Adapter::Orm).to receive(:new).with(
|
51
|
-
expect(Pickle::Adapter::Orm).to receive(:new).with(
|
52
|
-
expect(Pickle::Adapter::Orm).to receive(:new).with(
|
38
|
+
expect(Pickle::Adapter::Orm).to receive(:new).with(One).once
|
39
|
+
expect(Pickle::Adapter::Orm).to receive(:new).with(One::Two).once
|
40
|
+
expect(Pickle::Adapter::Orm).to receive(:new).with(Three).once
|
53
41
|
expect(Pickle::Adapter::Orm.factories.length).to eq(3)
|
54
42
|
end
|
55
43
|
|
56
44
|
describe ".new(Class)" do
|
57
45
|
before do
|
58
|
-
@factory = Pickle::Adapter::Orm.new(
|
46
|
+
@factory = Pickle::Adapter::Orm.new(One::Two)
|
59
47
|
end
|
60
48
|
|
61
49
|
it "should have underscored (s/_) name of Class as #name" do
|
@@ -63,7 +51,7 @@ describe Pickle::Adapter do
|
|
63
51
|
end
|
64
52
|
|
65
53
|
it "#create(attrs) should call Class.create!(attrs)" do
|
66
|
-
expect(
|
54
|
+
expect(One::Two).to receive(:create!).with({:key => "val"})
|
67
55
|
@factory.create(:key => "val")
|
68
56
|
end
|
69
57
|
end
|
@@ -72,19 +60,19 @@ describe Pickle::Adapter do
|
|
72
60
|
|
73
61
|
describe 'FactoryGirl' do
|
74
62
|
before do
|
75
|
-
allow(Pickle::Adapter::FactoryGirl).to receive(:model_classes).and_return([
|
63
|
+
allow(Pickle::Adapter::FactoryGirl).to receive(:model_classes).and_return([One, One::Two, Three])
|
76
64
|
|
77
65
|
if defined? ::FactoryGirl
|
78
66
|
@orig_factories = ::FactoryGirl.factories.dup
|
79
67
|
::FactoryGirl.factories.clear
|
80
|
-
::FactoryGirl::Syntax::Default::DSL.new.factory(:one, :class =>
|
81
|
-
::FactoryGirl::Syntax::Default::DSL.new.factory(:two, :class =>
|
68
|
+
::FactoryGirl::Syntax::Default::DSL.new.factory(:one, :class => One) {}
|
69
|
+
::FactoryGirl::Syntax::Default::DSL.new.factory(:two, :class => One::Two) {}
|
82
70
|
@factory1 = ::FactoryGirl.factories[:one]
|
83
71
|
@factory2 = ::FactoryGirl.factories[:two]
|
84
72
|
else
|
85
73
|
@orig_factories, Factory.factories = Factory.factories, {}
|
86
|
-
Factory.define(:one, :class =>
|
87
|
-
Factory.define(:two, :class =>
|
74
|
+
Factory.define(:one, :class => One) {}
|
75
|
+
Factory.define(:two, :class => One::Two) {}
|
88
76
|
@factory1 = Factory.factories[:one]
|
89
77
|
@factory2 = Factory.factories[:two]
|
90
78
|
end
|
@@ -100,14 +88,14 @@ describe Pickle::Adapter do
|
|
100
88
|
end
|
101
89
|
|
102
90
|
it ".factories should create one for each factory" do
|
103
|
-
expect(Pickle::Adapter::FactoryGirl).to receive(:new).with(@factory1).once
|
104
|
-
expect(Pickle::Adapter::FactoryGirl).to receive(:new).with(@factory2).once
|
91
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:new).with(@factory1, @factory1.name).once
|
92
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:new).with(@factory2, @factory2.name).once
|
105
93
|
Pickle::Adapter::FactoryGirl.factories
|
106
94
|
end
|
107
95
|
|
108
|
-
describe ".new(factory)" do
|
96
|
+
describe ".new(factory, factory_name)" do
|
109
97
|
before do
|
110
|
-
@factory = Pickle::Adapter::FactoryGirl.new(@factory1)
|
98
|
+
@factory = Pickle::Adapter::FactoryGirl.new(@factory1, @factory1.name)
|
111
99
|
end
|
112
100
|
|
113
101
|
it "should have name of factory_name" do
|
@@ -115,7 +103,7 @@ describe Pickle::Adapter do
|
|
115
103
|
end
|
116
104
|
|
117
105
|
it "should have klass of build_class" do
|
118
|
-
expect(@factory.klass).to eq(
|
106
|
+
expect(@factory.klass).to eq(One)
|
119
107
|
end
|
120
108
|
|
121
109
|
unless defined? ::FactoryGirl
|
@@ -129,8 +117,8 @@ describe Pickle::Adapter do
|
|
129
117
|
|
130
118
|
describe 'Fabrication' do
|
131
119
|
before do
|
132
|
-
@schematic1 = [:one, Fabrication::Schematic::Definition.new(
|
133
|
-
@schematic2 = [:two, Fabrication::Schematic::Definition.new(
|
120
|
+
@schematic1 = [:one, Fabrication::Schematic::Definition.new(One)]
|
121
|
+
@schematic2 = [:two, Fabrication::Schematic::Definition.new(One::Two)]
|
134
122
|
allow(::Fabrication.manager).to receive(:schematics).and_return(Hash[[@schematic1, @schematic2]])
|
135
123
|
end
|
136
124
|
|
@@ -151,7 +139,7 @@ describe Pickle::Adapter do
|
|
151
139
|
end
|
152
140
|
|
153
141
|
it "should have klass of build_class" do
|
154
|
-
expect(@factory.klass).to eq(
|
142
|
+
expect(@factory.klass).to eq(One)
|
155
143
|
end
|
156
144
|
end
|
157
145
|
|
@@ -167,23 +155,23 @@ describe Pickle::Adapter do
|
|
167
155
|
|
168
156
|
describe 'Machinist' do
|
169
157
|
before do
|
170
|
-
allow(Pickle::Adapter::Machinist).to receive(:model_classes).and_return([
|
158
|
+
allow(Pickle::Adapter::Machinist).to receive(:model_classes).and_return([One, One::Two, Three])
|
171
159
|
|
172
|
-
|
173
|
-
|
174
|
-
|
160
|
+
One.blueprint {}
|
161
|
+
Three.blueprint {}
|
162
|
+
Three.blueprint(:special) {}
|
175
163
|
end
|
176
164
|
|
177
165
|
it ".factories should create one for each master blueprint, and special case" do
|
178
|
-
expect(Pickle::Adapter::Machinist).to receive(:new).with(
|
179
|
-
expect(Pickle::Adapter::Machinist).to receive(:new).with(
|
180
|
-
expect(Pickle::Adapter::Machinist).to receive(:new).with(
|
166
|
+
expect(Pickle::Adapter::Machinist).to receive(:new).with(One, :master).once
|
167
|
+
expect(Pickle::Adapter::Machinist).to receive(:new).with(Three, :master).once
|
168
|
+
expect(Pickle::Adapter::Machinist).to receive(:new).with(Three, :special).once
|
181
169
|
Pickle::Adapter::Machinist.factories
|
182
170
|
end
|
183
171
|
|
184
172
|
describe ".new(Class, :master)" do
|
185
173
|
before do
|
186
|
-
@factory = Pickle::Adapter::Machinist.new(
|
174
|
+
@factory = Pickle::Adapter::Machinist.new(One, :master)
|
187
175
|
end
|
188
176
|
|
189
177
|
it "should have underscored (s/_) name of Class as #name" do
|
@@ -191,14 +179,14 @@ describe Pickle::Adapter do
|
|
191
179
|
end
|
192
180
|
|
193
181
|
it "#create(attrs) should call Class.make!(:master, attrs)" do
|
194
|
-
expect(
|
182
|
+
expect(One).to receive(:make!).with(:master, {:key => "val"})
|
195
183
|
@factory.create(:key => "val")
|
196
184
|
end
|
197
185
|
end
|
198
186
|
|
199
187
|
describe ".new(Class, :special)" do
|
200
188
|
before do
|
201
|
-
@factory = Pickle::Adapter::Machinist.new(
|
189
|
+
@factory = Pickle::Adapter::Machinist.new(Three, :special)
|
202
190
|
end
|
203
191
|
|
204
192
|
it "should have 'special_<Class name>' as #name" do
|
@@ -206,7 +194,7 @@ describe Pickle::Adapter do
|
|
206
194
|
end
|
207
195
|
|
208
196
|
it "#create(attrs) should call Class.make!(:special, attrs)" do
|
209
|
-
expect(
|
197
|
+
expect(Three).to receive(:make!).with(:special, {:key => "val"})
|
210
198
|
@factory.create(:key => "val")
|
211
199
|
end
|
212
200
|
end
|