chop 0.20.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e79910191410ddc45d44ca8198e96be315b3706f
4
- data.tar.gz: 0e919573c294fada4231b742b8245c0762e3b0bf
3
+ metadata.gz: ee08121005f0c0e0dc0c87490bd7e3dc5437aa25
4
+ data.tar.gz: 88f4109163927c7f3ded4aed309e2129ef8fbd35
5
5
  SHA512:
6
- metadata.gz: 3bfb0082be34fdea29550652f8f5dee5e07c7d2a637e4ef53d45713a74497c46cb8bd5cff0c167b9865f00dcaa9918adb39d33591b60badd90b694246bb299a0
7
- data.tar.gz: 947aa02f4654d87317ead72b289528002c0dfe520d749d5c6c294b4bab566835e41f101a54b25b9285557be5381bfdb854519f9a2b17d7f963bd8572b22c8529
6
+ metadata.gz: 5c090fba6c2c4f5c5033690955dbffb5cc391c7ba1ab0c1f1af10089178ed40d9da7b5af6e8fbb54d2edc3f518b96fa080d0180bff4834e5bd0cd216f5812b50
7
+ data.tar.gz: 2139c72e05d46285b0c1279951c62831f1fae90395a9d0a1d68d08c05699cd7e597b67ecb021a896a9cd5f6a62933a17af73d68bafc6b63a32e2f3c878a20ce1
@@ -70,7 +70,12 @@ module Chop
70
70
  def hash_transformation &block
71
71
  transformation do |rows|
72
72
  header = rows[0]
73
- keys = header.to_a.map { |cell| cell.text.parameterize.underscore }
73
+ keys = header.to_a.map.with_index do |cell, index|
74
+ key = cell.text.parameterize.underscore
75
+ next key if key.present?
76
+ next cell.text if cell.text.present?
77
+ index + 1
78
+ end
74
79
  body = rows[1..-1]
75
80
  hashes = body.map { |row| HashWithIndifferentAccess[keys.zip(row)] }
76
81
  yield hashes
@@ -8,12 +8,27 @@ module Chop
8
8
  end
9
9
 
10
10
  def self.diff! selector, table, session: Capybara.current_session, &block
11
- actual = session.find("form").all("input, textarea, select").map do |field|
12
- [field.label, field.value]
11
+ all_fields = session.find("form").all("input, textarea, select")
12
+ deduplicated_fields = all_fields.inject([]) do |fields, field|
13
+ next fields if fields.map { |field| field[:name] }.include?(field[:name])
14
+ fields + [field]
15
+ end
16
+ actual = deduplicated_fields.inject([]) do |fields, field|
17
+ next fields unless label = find_label_for(field)
18
+ field = Field.from(session, field)
19
+ fields + [[label.text, field.get_value]]
13
20
  end
14
21
  table.diff! actual, surplus_row: false
15
22
  end
16
23
 
24
+ def self.find_label_for field, session: Capybara.current_session
25
+ if field[:id]
26
+ session.first("label[for='#{field[:id]}']")
27
+ else
28
+ raise "cannot find label without id... yet"
29
+ end
30
+ end
31
+
17
32
  def fill_in!
18
33
  table.rows_hash.each do |label, value|
19
34
  Field.for(session, label, value, path).fill_in!
@@ -23,13 +38,26 @@ module Chop
23
38
  class Field < Struct.new(:session, :label, :value, :path, :field)
24
39
  def self.for session, label, value, path
25
40
  field = session.find_field(label)
26
- candidates = descendants.sort_by do |a|
27
- a == Chop::Form::Default ? 1 : -1 # ensure Default comes last
28
- end
29
41
  candidates.map do |klass|
30
42
  klass.new(session, label, value, path, field)
31
43
  end.find(&:matches?)
32
44
  end
45
+
46
+ def self.from session, field
47
+ candidates.map do |klass|
48
+ klass.new(session, nil, nil, nil, field)
49
+ end.find(&:matches?)
50
+ end
51
+
52
+ def self.candidates
53
+ descendants.sort_by do |a|
54
+ a == Chop::Form::Default ? 1 : -1 # ensure Default comes last
55
+ end
56
+ end
57
+
58
+ def get_value
59
+ field.value
60
+ end
33
61
  end
34
62
 
35
63
  class MultipleSelect < Field
@@ -89,6 +117,10 @@ module Chop
89
117
  def fill_in!
90
118
  field.set value.present?
91
119
  end
120
+
121
+ def get_value
122
+ field.checked? ? "✓" : ""
123
+ end
92
124
  end
93
125
 
94
126
  class Radio < Field
@@ -104,6 +136,10 @@ module Chop
104
136
  end
105
137
  end
106
138
 
139
+ def get_value
140
+ session.all("[name='#{field[:name]}']").find(&:checked?).try(:value)
141
+ end
142
+
107
143
  private
108
144
 
109
145
  def nonstandard_labelling?
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.20.0"
2
+ VERSION = "0.20.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord