pickle 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/License.txt +1 -1
- data/VERSION +1 -1
- data/features/pickle/create_from_active_record.feature +5 -4
- data/features/step_definitions/pickle_steps.rb +1 -2
- data/lib/pickle/session.rb +11 -3
- data/pickle.gemspec +1 -1
- data/rails_generators/pickle/templates/pickle_steps.rb +1 -2
- data/spec/lib/pickle_session_spec.rb +15 -3
- metadata +2 -2
data/History.txt
CHANGED
data/License.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -58,9 +58,10 @@ Feature: I can easily create models from my blueprints
|
|
58
58
|
| Jack |
|
59
59
|
| Pete |
|
60
60
|
And the following users should exist:
|
61
|
-
| status |
|
62
|
-
| alone |
|
63
|
-
| dead |
|
61
|
+
| user | status |
|
62
|
+
| lonely | alone |
|
63
|
+
| rotting | dead |
|
64
64
|
And the 1st user should be the user: "Jack"
|
65
65
|
And the 2nd user should be the user: "Pete"
|
66
|
-
|
66
|
+
And the user: "lonely" should be the user: "Jack"
|
67
|
+
And the user: "rotting" should be the user: "Pete"
|
@@ -27,8 +27,7 @@ end
|
|
27
27
|
|
28
28
|
# find models with a table
|
29
29
|
Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
|
30
|
-
|
31
|
-
table.hashes.each { |hash| find_model!(name, hash)}
|
30
|
+
find_models_from_table(plural_factory, table)
|
32
31
|
end
|
33
32
|
|
34
33
|
# find exactly n models
|
data/lib/pickle/session.rb
CHANGED
@@ -32,8 +32,7 @@ module Pickle
|
|
32
32
|
def create_models_from_table(plural_factory, table)
|
33
33
|
factory = plural_factory.singularize
|
34
34
|
table.hashes.each do |hash|
|
35
|
-
pickle_ref = factory
|
36
|
-
pickle_ref += ' "' + hash.delete(factory) + '"' if hash[factory]
|
35
|
+
pickle_ref = factory + (hash[factory] ? " \"#{hash.delete(factory)}\"" : "")
|
37
36
|
create_model(pickle_ref, hash)
|
38
37
|
end
|
39
38
|
end
|
@@ -58,7 +57,16 @@ module Pickle
|
|
58
57
|
records = model_class.find(:all, :conditions => convert_models_to_attributes(model_class, parse_fields(fields)))
|
59
58
|
records.each {|record| store_model(factory, nil, record)}
|
60
59
|
end
|
61
|
-
|
60
|
+
|
61
|
+
# if a column exists in the table which matches the singular factory name, this is used as the pickle ref
|
62
|
+
def find_models_from_table(plural_factory, table)
|
63
|
+
factory = plural_factory.singularize
|
64
|
+
table.hashes.each do |hash|
|
65
|
+
pickle_ref = factory + (hash[factory] ? " \"#{hash.delete(factory)}\"" : "")
|
66
|
+
find_model(pickle_ref, hash)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
62
70
|
# return the original model stored by create_model or find_model
|
63
71
|
def created_model(name)
|
64
72
|
factory, name_or_index = *parse_model(name)
|
data/pickle.gemspec
CHANGED
@@ -27,8 +27,7 @@ end
|
|
27
27
|
|
28
28
|
# find models with a table
|
29
29
|
Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
|
30
|
-
|
31
|
-
table.hashes.each { |hash| find_model!(name, hash)}
|
30
|
+
find_models_from_table(plural_factory, table)
|
32
31
|
end
|
33
32
|
|
34
33
|
# find exactly n models
|
@@ -207,17 +207,23 @@ describe Pickle::Session do
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
-
describe "
|
210
|
+
describe "create and find using plural_factory and table" do
|
211
211
|
context "when given a table without a matching pickle ref column" do
|
212
212
|
before do
|
213
213
|
@table = mock(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
|
214
214
|
end
|
215
215
|
|
216
|
-
it "should call create_model for each of the table hashes with plain factory name" do
|
216
|
+
it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with plain factory name" do
|
217
217
|
should_receive(:create_model).with("user", 'name' => "Fred").once.ordered
|
218
218
|
should_receive(:create_model).with("user", 'name' => "Betty").once.ordered
|
219
219
|
create_models_from_table("users", @table)
|
220
220
|
end
|
221
|
+
|
222
|
+
it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with plain factory name" do
|
223
|
+
should_receive(:find_model).with("user", 'name' => "Fred").once.ordered
|
224
|
+
should_receive(:find_model).with("user", 'name' => "Betty").once.ordered
|
225
|
+
find_models_from_table("users", @table)
|
226
|
+
end
|
221
227
|
end
|
222
228
|
|
223
229
|
context "when given a table with a matching pickle ref column" do
|
@@ -225,11 +231,17 @@ describe Pickle::Session do
|
|
225
231
|
@table = mock(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
|
226
232
|
end
|
227
233
|
|
228
|
-
it "should call create_model for each of the table hashes with labelled pickle ref" do
|
234
|
+
it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with labelled pickle ref" do
|
229
235
|
should_receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered
|
230
236
|
should_receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered
|
231
237
|
create_models_from_table("users", @table)
|
232
238
|
end
|
239
|
+
|
240
|
+
it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with labelled pickle ref" do
|
241
|
+
should_receive(:find_model).with("user \"fred\"", 'name' => "Fred").once.ordered
|
242
|
+
should_receive(:find_model).with("user \"betty\"", 'name' => "Betty").once.ordered
|
243
|
+
find_models_from_table("users", @table)
|
244
|
+
end
|
233
245
|
end
|
234
246
|
end
|
235
247
|
|