chop 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chop/form.rb +46 -2
  3. data/lib/chop/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 506a6d9485634400abf38169575801480055ae9f
4
- data.tar.gz: a9e56fe4eeed83bc267a2b08ccec30c2b240e549
3
+ metadata.gz: fc848f74bcfa21d1caf3f92ba4dbadb50ef7e997
4
+ data.tar.gz: 4fcee119a37213af484023b70ee200af27e25251
5
5
  SHA512:
6
- metadata.gz: ab7a0531633fb89e60ce912afb4e5f01e964a6c23e6b3bedae0d51cff1525cb153c91746c170c7ab2e8ccd743c0c87b87d2440f682c153014e74b2fe8cb46592
7
- data.tar.gz: 5c21efe835d3ad547fc27dd5c9aba6b308172a2556494796bcbce3387b3c899e1ce0b56f76f55dbbd7d8e11f20b1421164e12b9e827c9d388e19f127a77a7c9e
6
+ metadata.gz: a917cfb02a2d1cdd17c7385d9efb73ff6fef248a91e101073c6a1ea52e4e55d2d17123503ce5076047945eb33ea4ad2766a227f683169c7188c2cb00389ce3f0
7
+ data.tar.gz: 13b5f38fab386835e0993949d9f906ce19de928abaa9c8885cae3e344afa6554d36fdc8cbf8acc4b7937522ad541d58e0c41515d0a04adb3e249b684e326fc02
@@ -52,9 +52,37 @@ module Chop
52
52
  end
53
53
  end
54
54
 
55
+ class MultipleCheckbox < Field
56
+ def matches?
57
+ field[:type] == "checkbox" && field[:name].to_s.end_with?("[]")
58
+ end
59
+
60
+ def fill_in!
61
+ checkboxes.each do |checkbox|
62
+ if checkbox_label_in_values? checkbox
63
+ session.check(checkbox[:id])
64
+ else
65
+ session.uncheck(checkbox[:id])
66
+ end
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def checkboxes
73
+ session.all("[name='#{field[:name]}']")
74
+ end
75
+
76
+ def checkbox_label_in_values? checkbox
77
+ values = value.split(", ")
78
+ labels = session.all("label[for='#{checkbox[:id]}']").map(&:text)
79
+ (values & labels).any?
80
+ end
81
+ end
82
+
55
83
  class Checkbox < Field
56
84
  def matches?
57
- field[:type] == "checkbox"
85
+ field[:type] == "checkbox" && !field[:name].to_s.end_with?("[]")
58
86
  end
59
87
 
60
88
  def fill_in!
@@ -72,7 +100,23 @@ module Chop
72
100
  end
73
101
 
74
102
  def fill_in!
75
- session.choose label
103
+ if nonstandard_labelling?
104
+ session.choose value
105
+ else
106
+ session.choose label
107
+ end
108
+ end
109
+
110
+ private
111
+
112
+ def nonstandard_labelling?
113
+ value_field[:name] == field[:name]
114
+ end
115
+
116
+ def value_field
117
+ session.find_field(value)
118
+ rescue Capybara::ElementNotFound
119
+ {}
76
120
  end
77
121
  end
78
122
 
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
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.11.0
4
+ version: 0.12.0
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-03-08 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord