pickle 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +15 -0
- data/README.rdoc +13 -0
- data/VERSION +1 -1
- data/features/pickle/create_from_active_record.feature +21 -4
- data/features/step_definitions/pickle_steps.rb +1 -2
- data/lib/pickle/session.rb +13 -3
- data/pickle.gemspec +2 -2
- data/rails_generators/pickle/templates/pickle_steps.rb +1 -2
- data/spec/lib/pickle_session_spec.rb +27 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
== 0.2.3 - 9 Mar 2010
|
2
|
+
|
3
|
+
* 1 major improvement
|
4
|
+
* You can now use pickle refs in tables. If you add a column which is the single factory name, the
|
5
|
+
contents of the column will be used as the pickle ref. [Stephan Hagemann]
|
6
|
+
e.g.
|
7
|
+
Given the following users exist:
|
8
|
+
| user | name | status |
|
9
|
+
| jack | Jack Spratt | alone |
|
10
|
+
| pete | Pete Sprong | dead |
|
11
|
+
|
12
|
+
* 1 minor improvement
|
13
|
+
* Fix bug in error message for when pickle ref can't be found [Myron Marston]
|
14
|
+
|
15
|
+
|
1
16
|
== 0.2.2 - 25 Feb 2010
|
2
17
|
|
3
18
|
* 3 improvements
|
data/README.rdoc
CHANGED
@@ -66,6 +66,8 @@ The following people have made Pickle better:
|
|
66
66
|
* {Tobi Knaup}[http://github.com/guenter]
|
67
67
|
* {Michael MacDonald}[http://github.com/schlick]
|
68
68
|
* {Michael Moen}[http://github.com/UnderpantsGnome]
|
69
|
+
* {Myron Marston}[http://github.com/myronmarston]
|
70
|
+
* {Stephan Hagemann}[http://github.com/xing]
|
69
71
|
|
70
72
|
== Get Started
|
71
73
|
|
@@ -198,6 +200,17 @@ You can use other models, booleans, numerics, and strings as fields
|
|
198
200
|
|
199
201
|
Then 2 people should exist with father: person "fred"
|
200
202
|
|
203
|
+
"Then the following <b>models</b> exist". This allows the creation of multiple models
|
204
|
+
using a table syntax. Using a column with the singularized name of the model creates a referenceable model. E.g.
|
205
|
+
|
206
|
+
Then the following users exist:
|
207
|
+
| name | activated |
|
208
|
+
| Freddy | false |
|
209
|
+
|
210
|
+
Then the following users exist:
|
211
|
+
| user | name | activated |
|
212
|
+
| Fred | Freddy | false |
|
213
|
+
|
201
214
|
===== Asserting associations
|
202
215
|
|
203
216
|
One-to-one assocs: "Then <b>a model</b> should be <b>other model</b>'s <b>association</b>", e.g.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -34,9 +34,9 @@ Feature: I can easily create models from my blueprints
|
|
34
34
|
|
35
35
|
Scenario: create and find using tables
|
36
36
|
Given the following users exist:
|
37
|
-
| name
|
38
|
-
| Jim
|
39
|
-
| Ethel
|
37
|
+
| name | status |
|
38
|
+
| Jim | married |
|
39
|
+
| Ethel | in a relationship with x |
|
40
40
|
Then the following users should exist:
|
41
41
|
| name |
|
42
42
|
| Jim |
|
@@ -46,4 +46,21 @@ Feature: I can easily create models from my blueprints
|
|
46
46
|
| married |
|
47
47
|
| in a relationship with x |
|
48
48
|
And the 1st user should be the 3rd user
|
49
|
-
And the 2nd user should be the last user
|
49
|
+
And the 2nd user should be the last user
|
50
|
+
|
51
|
+
Scenario: create and find using tables with referencable names
|
52
|
+
Given the following users exist:
|
53
|
+
| user | name | status |
|
54
|
+
| Jack | Jack | alone |
|
55
|
+
| Pete | Pete | dead |
|
56
|
+
Then the following users should exist:
|
57
|
+
| name |
|
58
|
+
| Jack |
|
59
|
+
| Pete |
|
60
|
+
And the following users should exist:
|
61
|
+
| status |
|
62
|
+
| alone |
|
63
|
+
| dead |
|
64
|
+
And the 1st user should be the user: "Jack"
|
65
|
+
And the 2nd user should be the user: "Pete"
|
66
|
+
|
@@ -12,8 +12,7 @@ end
|
|
12
12
|
|
13
13
|
# create models from a table
|
14
14
|
Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
|
15
|
-
|
16
|
-
table.hashes.each { |hash| create_model(name, hash) }
|
15
|
+
create_models_from_table(plural_factory, table)
|
17
16
|
end
|
18
17
|
|
19
18
|
# find a model
|
data/lib/pickle/session.rb
CHANGED
@@ -20,13 +20,23 @@ module Pickle
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def create_model(
|
24
|
-
factory, label = *parse_model(
|
23
|
+
def create_model(pickle_ref, fields = nil)
|
24
|
+
factory, label = *parse_model(pickle_ref)
|
25
25
|
raise ArgumentError, "Can't create with an ordinal (e.g. 1st user)" if label.is_a?(Integer)
|
26
26
|
fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
|
27
27
|
record = pickle_config.factories[factory].create(fields)
|
28
28
|
store_model(factory, label, record)
|
29
29
|
end
|
30
|
+
|
31
|
+
# if a column exists in the table which matches the singular factory name, this is used as the pickle ref
|
32
|
+
def create_models_from_table(plural_factory, table)
|
33
|
+
factory = plural_factory.singularize
|
34
|
+
table.hashes.each do |hash|
|
35
|
+
pickle_ref = factory
|
36
|
+
pickle_ref += ' "' + hash.delete(factory) + '"' if hash[factory]
|
37
|
+
create_model(pickle_ref, hash)
|
38
|
+
end
|
39
|
+
end
|
30
40
|
|
31
41
|
def find_model(a_model_name, fields = nil)
|
32
42
|
factory, name = *parse_model(a_model_name)
|
@@ -39,7 +49,7 @@ module Pickle
|
|
39
49
|
end
|
40
50
|
|
41
51
|
def find_model!(a_model_name, fields = nil)
|
42
|
-
find_model(a_model_name, fields) or raise "Can't find pickle model: '#{
|
52
|
+
find_model(a_model_name, fields) or raise "Can't find pickle model: '#{a_model_name}' in this scenario"
|
43
53
|
end
|
44
54
|
|
45
55
|
def find_models(factory, fields = nil)
|
data/pickle.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pickle}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
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"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-09}
|
13
13
|
s.description = %q{Easy model creation and reference in your cucumber features}
|
14
14
|
s.email = %q{ian.w.white@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -12,8 +12,7 @@ end
|
|
12
12
|
|
13
13
|
# create models from a table
|
14
14
|
Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
|
15
|
-
|
16
|
-
table.hashes.each { |hash| create_model(name, hash) }
|
15
|
+
create_models_from_table(plural_factory, table)
|
17
16
|
end
|
18
17
|
|
19
18
|
# find a model
|
@@ -207,6 +207,32 @@ describe Pickle::Session do
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
+
describe "#create_models_from_table(plural_factory, table)" do
|
211
|
+
context "when given a table without a matching pickle ref column" do
|
212
|
+
before do
|
213
|
+
@table = mock(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should call create_model for each of the table hashes with plain factory name" do
|
217
|
+
should_receive(:create_model).with("user", 'name' => "Fred").once.ordered
|
218
|
+
should_receive(:create_model).with("user", 'name' => "Betty").once.ordered
|
219
|
+
create_models_from_table("users", @table)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "when given a table with a matching pickle ref column" do
|
224
|
+
before do
|
225
|
+
@table = mock(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should call create_model for each of the table hashes with labelled pickle ref" do
|
229
|
+
should_receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered
|
230
|
+
should_receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered
|
231
|
+
create_models_from_table("users", @table)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
210
236
|
describe "#find_model!" do
|
211
237
|
it "should call find_model" do
|
212
238
|
should_receive(:find_model).with('name', 'fields').and_return(mock('User'))
|
@@ -215,7 +241,7 @@ describe Pickle::Session do
|
|
215
241
|
|
216
242
|
it "should call raise error if find_model returns nil" do
|
217
243
|
should_receive(:find_model).with('name', 'fields').and_return(nil)
|
218
|
-
lambda { find_model!('name', 'fields') }.should raise_error
|
244
|
+
lambda { find_model!('name', 'fields') }.should raise_error(RuntimeError, "Can't find pickle model: 'name' in this scenario")
|
219
245
|
end
|
220
246
|
end
|
221
247
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ian White
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-03-09 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|