pickle 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ == 0.2.4 - 9 Mar 2010
2
+
3
+ * 1 major improvement
4
+ * Finding models via a table now works in the same way as creating models via a table (0.2.3), you
5
+ can create pickle refs
6
+
1
7
  == 0.2.3 - 9 Mar 2010
2
8
 
3
9
  * 1 major improvement
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2009 Ian White - ian.w.white@gmail.com
1
+ Copyright (c) 2008-2010 Ian White - ian.w.white@gmail.com
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
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
- name = plural_factory.singularize
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
@@ -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)
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pickle}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ian White"]
@@ -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
- name = plural_factory.singularize
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 "#create_models_from_table(plural_factory, table)" do
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
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian White