chop 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/chop/create.rb +13 -9
- data/lib/chop/definition_list.rb +1 -1
- data/lib/chop/diff.rb +12 -10
- data/lib/chop/dsl.rb +4 -4
- data/lib/chop/form.rb +4 -1
- data/lib/chop/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f361d4f1d6428136b9187e57b495e8a7a2d1b8cb
|
4
|
+
data.tar.gz: 7405d53d647c0af2468fc92cbeaf8f860cb8a921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a991f6f01794ef5dc5cf033713daeaae096c09b358a602302893491329a23a55e2c5fbaf592a920903370e77972862aea944e2c7036d1a071612f2883573a6f
|
7
|
+
data.tar.gz: 3ebb468ac5ad8ce0aeacb38611ee92b4cc2932fd809d9b61ec7142e802468987d70729af4c45c81c7054a04f1b902a4eb0acbaed965f71a09eed4a08f8336ab5
|
data/README.md
CHANGED
@@ -142,7 +142,7 @@ end
|
|
142
142
|
Load `chop` before `cucumber` in your Gemfile, and call the two methods directly on the `Chop` module, passing the cucumber table in as the first argument.
|
143
143
|
|
144
144
|
```ruby
|
145
|
-
Chop.create!
|
145
|
+
Chop.create! Users, table
|
146
146
|
Chop.diff! table, "table"
|
147
147
|
Chop.fill_in! table
|
148
148
|
```
|
data/lib/chop/create.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require "active_support/core_ext/string/inflections"
|
2
2
|
require "active_support/core_ext/object/blank"
|
3
|
+
require "active_support/hash_with_indifferent_access"
|
3
4
|
|
4
5
|
module Chop
|
5
|
-
class Create < Struct.new(:
|
6
|
-
def self.create!
|
7
|
-
new(
|
6
|
+
class Create < Struct.new(:klass, :table, :block)
|
7
|
+
def self.create! klass, table, &block
|
8
|
+
new(klass, table, block).create!
|
8
9
|
end
|
9
10
|
|
10
11
|
attr_accessor :transformations
|
@@ -18,7 +19,10 @@ module Chop
|
|
18
19
|
|
19
20
|
def create! cucumber_table = table
|
20
21
|
cucumber_table.hashes.map do |attributes|
|
21
|
-
|
22
|
+
attributes = HashWithIndifferentAccess.new(attributes)
|
23
|
+
attributes = transformations.reduce(attributes) do |attrs, transformation|
|
24
|
+
transformation.call(attrs)
|
25
|
+
end
|
22
26
|
if klass.is_a?(Hash)
|
23
27
|
if factory = klass[:factory_girl]
|
24
28
|
FactoryGirl.create factory, attributes
|
@@ -37,8 +41,9 @@ module Chop
|
|
37
41
|
|
38
42
|
def rename mappings
|
39
43
|
transformation do |attributes|
|
40
|
-
mappings.
|
41
|
-
|
44
|
+
mappings.reduce(attributes) do |attrs, (old, new)|
|
45
|
+
attrs[new] = attrs.delete(old) if attrs.key?(old)
|
46
|
+
attrs
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
@@ -49,16 +54,15 @@ module Chop
|
|
49
54
|
attribute = attribute.values.first
|
50
55
|
end
|
51
56
|
transformation do |attributes|
|
52
|
-
attributes
|
57
|
+
attributes.merge attribute => yield(attributes.fetch(attribute, default))
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
61
|
def underscore_keys
|
57
62
|
transformation do |attributes|
|
58
|
-
|
63
|
+
attributes.reduce(HashWithIndifferentAccess.new) do |hash, (key, value)|
|
59
64
|
hash.merge key.parameterize.underscore => value
|
60
65
|
end
|
61
|
-
attributes.replace new_attributes
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
data/lib/chop/definition_list.rb
CHANGED
data/lib/chop/diff.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "active_support/core_ext/string/inflections"
|
2
2
|
require "active_support/core_ext/object/blank"
|
3
3
|
require "active_support/core_ext/class/attribute"
|
4
|
+
require "active_support/hash_with_indifferent_access"
|
4
5
|
|
5
6
|
module Chop
|
6
7
|
class Diff < Struct.new(:selector, :table, :session, :block)
|
@@ -49,13 +50,14 @@ module Chop
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
row[index] = yield(row[index])
|
53
|
+
row
|
52
54
|
end
|
53
55
|
else
|
54
56
|
if block.arity.zero?
|
55
57
|
@new_header = yield
|
56
58
|
else
|
57
59
|
header_transformation do |row|
|
58
|
-
|
60
|
+
yield(row)
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
@@ -68,11 +70,11 @@ module Chop
|
|
68
70
|
def hash_transformation &block
|
69
71
|
transformation do |rows|
|
70
72
|
header = rows[0]
|
71
|
-
keys = header.to_a.map { |cell| cell.text.parameterize.underscore
|
73
|
+
keys = header.to_a.map { |cell| cell.text.parameterize.underscore }
|
72
74
|
body = rows[1..-1]
|
73
|
-
hashes = body.map { |row|
|
75
|
+
hashes = body.map { |row| HashWithIndifferentAccess[keys.zip(row)] }
|
74
76
|
yield hashes
|
75
|
-
|
77
|
+
[header] + hashes.map(&:values)
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
@@ -117,9 +119,9 @@ module Chop
|
|
117
119
|
rows = normalize(rows)
|
118
120
|
|
119
121
|
header = @new_header ? normalize([@new_header]).first : rows.shift || []
|
120
|
-
header_transformations.
|
121
|
-
transformation.call(header)
|
122
|
-
|
122
|
+
header = header_transformations.reduce(header) do |header, transformation|
|
123
|
+
header = transformation.call(header)
|
124
|
+
normalize([header]).first
|
123
125
|
end
|
124
126
|
|
125
127
|
if header
|
@@ -127,9 +129,9 @@ module Chop
|
|
127
129
|
rows = normalize(rows)
|
128
130
|
end
|
129
131
|
|
130
|
-
transformations.
|
131
|
-
transformation.call(rows)
|
132
|
-
|
132
|
+
rows = transformations.reduce(rows) do |rows, transformation|
|
133
|
+
rows = transformation.call(rows)
|
134
|
+
normalize(rows)
|
133
135
|
end
|
134
136
|
|
135
137
|
rows.map do |row|
|
data/lib/chop/dsl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Chop
|
2
2
|
module DSL
|
3
|
-
def create!
|
4
|
-
Create.create!
|
3
|
+
def create! klass, table, &block
|
4
|
+
Create.create! klass, table, &block
|
5
5
|
end
|
6
6
|
|
7
7
|
def diff! selector, table, session: Capybara.current_session, &block
|
@@ -19,10 +19,10 @@ end
|
|
19
19
|
if defined?(Cucumber::MultilineArgument::DataTable)
|
20
20
|
Cucumber::MultilineArgument::DataTable.prepend Module.new {
|
21
21
|
def create! klass, &block
|
22
|
-
Chop.create!
|
22
|
+
Chop.create! klass, self, &block
|
23
23
|
end
|
24
24
|
|
25
|
-
def diff! other_table, options={}, &block
|
25
|
+
def diff! other_table="table", options={}, &block
|
26
26
|
if other_table.is_a?(String) && !other_table.include?("|")
|
27
27
|
Chop.diff! other_table, self, &block
|
28
28
|
else
|
data/lib/chop/form.rb
CHANGED
@@ -16,7 +16,10 @@ module Chop
|
|
16
16
|
class Field < Struct.new(:session, :label, :value, :path, :field)
|
17
17
|
def self.for session, label, value, path
|
18
18
|
field = session.find_field(label)
|
19
|
-
descendants.
|
19
|
+
candidates = descendants.sort_by do |a|
|
20
|
+
a == Chop::Form::Default ? 1 : -1 # ensure Default comes last
|
21
|
+
end
|
22
|
+
candidates.map do |klass|
|
20
23
|
klass.new(session, label, value, path, field)
|
21
24
|
end.find(&:matches?)
|
22
25
|
end
|
data/lib/chop/version.rb
CHANGED