chop 0.10.0 → 0.11.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 +88 -7
  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: 8dae29be1ed5e8747e2a7ccee7504b65968d7b0a
4
- data.tar.gz: f0647eff2fd3aae0039af3079ccc977224d7d53f
3
+ metadata.gz: 506a6d9485634400abf38169575801480055ae9f
4
+ data.tar.gz: a9e56fe4eeed83bc267a2b08ccec30c2b240e549
5
5
  SHA512:
6
- metadata.gz: 89883bd7d309b914d545c591ba51119061d66cfb01b9227e39b0fa5ddd333108647f3aad4c396e5b7f173bc9b51ac521bc0dbf3533c9e2e612ce3dd1bbe5de5c
7
- data.tar.gz: 89691d599ef482ae8563bf730200b16168fa8f14a3d4ce15c84c45bc22dc4933d210bde4fa7fc94f9bac0ba837827aa764b5076acf226535bc04593104df6a4a
6
+ metadata.gz: ab7a0531633fb89e60ce912afb4e5f01e964a6c23e6b3bedae0d51cff1525cb153c91746c170c7ab2e8ccd743c0c87b87d2440f682c153014e74b2fe8cb46592
7
+ data.tar.gz: 5c21efe835d3ad547fc27dd5c9aba6b308172a2556494796bcbce3387b3c899e1ce0b56f76f55dbbd7d8e11f20b1421164e12b9e827c9d388e19f127a77a7c9e
@@ -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
- field = session.find_field(label)
10
- if field[:type] == "file"
11
- session.attach_file label, "features/support/fixtures/#{value}"
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.fill_in label, with: value
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
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.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.10.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-02-28 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord