chop 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chop/form.rb +88 -7
- data/lib/chop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 506a6d9485634400abf38169575801480055ae9f
|
4
|
+
data.tar.gz: a9e56fe4eeed83bc267a2b08ccec30c2b240e549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7a0531633fb89e60ce912afb4e5f01e964a6c23e6b3bedae0d51cff1525cb153c91746c170c7ab2e8ccd743c0c87b87d2440f682c153014e74b2fe8cb46592
|
7
|
+
data.tar.gz: 5c21efe835d3ad547fc27dd5c9aba6b308172a2556494796bcbce3387b3c899e1ce0b56f76f55dbbd7d8e11f20b1421164e12b9e827c9d388e19f127a77a7c9e
|
data/lib/chop/form.rb
CHANGED
@@ -1,18 +1,99 @@
|
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
require "active_support/core_ext/class/subclasses"
|
3
|
+
|
1
4
|
module Chop
|
2
|
-
class Form < Struct.new(:table, :session)
|
3
|
-
def self.fill_in! table, session: Capybara.current_session
|
4
|
-
new(table, session).fill_in!
|
5
|
+
class Form < Struct.new(:table, :session, :path)
|
6
|
+
def self.fill_in! table, session: Capybara.current_session, path: "features/support/fixtures"
|
7
|
+
new(table, session, path).fill_in!
|
5
8
|
end
|
6
9
|
|
7
10
|
def fill_in!
|
8
11
|
table.rows_hash.each do |label, value|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
Field.for(session, label, value, path).fill_in!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Field < Struct.new(:session, :label, :value, :path)
|
17
|
+
def self.for *args
|
18
|
+
descendants.map do |klass|
|
19
|
+
klass.new(*args)
|
20
|
+
end.find(&:matches?)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def field
|
26
|
+
@field ||= session.find_field(label)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class MultipleSelect < Field
|
31
|
+
def matches?
|
32
|
+
field.tag_name == "select" && field[:multiple]
|
33
|
+
end
|
34
|
+
|
35
|
+
def fill_in!
|
36
|
+
field.all("option").map(&:text).each do |value|
|
37
|
+
session.unselect value, from: label
|
38
|
+
end
|
39
|
+
value.split(", ").each do |value|
|
40
|
+
session.select value, from: label
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Select < Field
|
46
|
+
def matches?
|
47
|
+
field.tag_name == "select" && !field[:multiple]
|
48
|
+
end
|
49
|
+
|
50
|
+
def fill_in!
|
51
|
+
session.select value, from: label
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Checkbox < Field
|
56
|
+
def matches?
|
57
|
+
field[:type] == "checkbox"
|
58
|
+
end
|
59
|
+
|
60
|
+
def fill_in!
|
61
|
+
if value.present?
|
62
|
+
session.check label
|
12
63
|
else
|
13
|
-
session.
|
64
|
+
session.uncheck label
|
14
65
|
end
|
15
66
|
end
|
16
67
|
end
|
68
|
+
|
69
|
+
class Radio < Field
|
70
|
+
def matches?
|
71
|
+
field[:type] == "radio"
|
72
|
+
end
|
73
|
+
|
74
|
+
def fill_in!
|
75
|
+
session.choose label
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class File < Field
|
80
|
+
def matches?
|
81
|
+
field[:type] == "file"
|
82
|
+
end
|
83
|
+
|
84
|
+
def fill_in!
|
85
|
+
session.attach_file label, ::File.join(path, value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class Default < Field
|
90
|
+
def matches?
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
def fill_in!
|
95
|
+
session.fill_in label, with: value
|
96
|
+
end
|
97
|
+
end
|
17
98
|
end
|
18
99
|
end
|
data/lib/chop/version.rb
CHANGED
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.
|
4
|
+
version: 0.11.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-
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|