domino 0.9.0 → 0.10.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 +21 -0
- data/domino.gemspec +1 -1
- data/lib/domino/attribute.rb +8 -0
- data/lib/domino/form/field.rb +1 -2
- data/lib/domino/form/select_field.rb +1 -1
- data/lib/domino/form.rb +6 -2
- data/lib/domino.rb +6 -2
- data/test/domino_form_test.rb +14 -2
- data/test/domino_test.rb +17 -0
- data/test/test_application.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: ef317e23fa5c56cda925292542b5c21a9427da0f
|
4
|
+
data.tar.gz: 8569c3441566aa337bbf547f21e51f6b426c9fd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 221ce20550753d6e51b23785aa9bda36ff4ccb7cc6a6f800bdec24a021e0f820bcdc0cfeb4ab632722306c5fc75806d68e3cc115d0891b14ed0be56db9b9059c
|
7
|
+
data.tar.gz: 63ab29831e4b94ab7c8cf94356de7f4ff2ab58dde5e15fe2406a08eb853ef089c0cd7a2833609c8ae9fd1ca18dcf3b63310f4acfc761c15f21be1141daa2a6f0
|
data/README.md
CHANGED
@@ -168,6 +168,27 @@ end
|
|
168
168
|
Provide your custom class using the `:as` option when defining your field,
|
169
169
|
as shown in the example above.
|
170
170
|
|
171
|
+
### Accessing the Attribute/Field Node
|
172
|
+
|
173
|
+
The named accessor method for any field or attribute will yield the Capybara
|
174
|
+
node of the attribute if you pass a block. You can use this to check
|
175
|
+
certain properties of the node without having to break out of your Dominos.
|
176
|
+
|
177
|
+
**Example:** Checking available options in a select field
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
person = Dom::PersonForm.find!
|
181
|
+
expected_options = ["- Select a Color -", "Red", "Blue", "Green"]
|
182
|
+
assert_equal expected_options, person.favorite_color { |n| n.all('option').map(&:text) }
|
183
|
+
```
|
184
|
+
|
185
|
+
**Example:** Checking the tag of the node containing the attribute value
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
person = Dom::Person.find_by!(uuid: "e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f")
|
189
|
+
assert_equal "h2", person.name { |n| n.tag_name }
|
190
|
+
```
|
191
|
+
|
171
192
|
## Integration with capybara
|
172
193
|
|
173
194
|
Domino uses capybara internally to search html for nodes and
|
data/domino.gemspec
CHANGED
data/lib/domino/attribute.rb
CHANGED
data/lib/domino/form/field.rb
CHANGED
@@ -12,8 +12,7 @@ class Domino::Form::Field
|
|
12
12
|
# Delete any options for your field type that shouldn't be passed to
|
13
13
|
# the field locator.
|
14
14
|
# Default: noop
|
15
|
-
def extract_field_options
|
16
|
-
end
|
15
|
+
def extract_field_options; end
|
17
16
|
|
18
17
|
# Convert the value from `#read` via callback if provided.
|
19
18
|
def value(node)
|
@@ -2,7 +2,7 @@ class Domino::Form::SelectField < Domino::Form::Field
|
|
2
2
|
# Returns the set of selected options that can be processed in the callback.
|
3
3
|
def read(node)
|
4
4
|
s = field(node)
|
5
|
-
selected = s.all(
|
5
|
+
selected = s.all('option[selected]')
|
6
6
|
s.multiple? ? selected : selected.first
|
7
7
|
end
|
8
8
|
|
data/lib/domino/form.rb
CHANGED
@@ -39,8 +39,12 @@ class Domino::Form < Domino
|
|
39
39
|
|
40
40
|
field_definitions[attribute] = field_class.new(attribute, locator, options, &callback)
|
41
41
|
|
42
|
-
define_method :"#{attribute}" do
|
43
|
-
|
42
|
+
define_method :"#{attribute}" do |&block|
|
43
|
+
if block.is_a?(Proc)
|
44
|
+
block.call(self.class.field_definitions[attribute].field(node))
|
45
|
+
else
|
46
|
+
self.class.field_definitions[attribute].value(node)
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
define_method :"#{attribute}=" do |value|
|
data/lib/domino.rb
CHANGED
@@ -138,8 +138,12 @@ class Domino
|
|
138
138
|
|
139
139
|
attribute_definitions[attribute] = Attribute.new(attribute, selector, &callback)
|
140
140
|
|
141
|
-
define_method :"#{attribute}" do
|
142
|
-
|
141
|
+
define_method :"#{attribute}" do |&block|
|
142
|
+
if block.is_a?(Proc)
|
143
|
+
block.call(self.class.attribute_definitions[attribute].element(node))
|
144
|
+
else
|
145
|
+
self.class.attribute_definitions[attribute].value(node)
|
146
|
+
end
|
143
147
|
end
|
144
148
|
|
145
149
|
define_singleton_method :"find_by_#{attribute}" do |value|
|
data/test/domino_form_test.rb
CHANGED
@@ -187,14 +187,14 @@ class DominoFormTest < Minitest::Test
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def test_static_create_with_no_matches
|
190
|
-
visit
|
190
|
+
visit '/'
|
191
191
|
assert_raises Capybara::ElementNotFound do
|
192
192
|
Dom::PersonForm.create name: 'Marie', last_name: 'Curie'
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
196
|
def test_static_update_with_no_matches
|
197
|
-
visit
|
197
|
+
visit '/'
|
198
198
|
assert_raises Capybara::ElementNotFound do
|
199
199
|
Dom::PersonForm.update name: 'Marie', last_name: 'Curie'
|
200
200
|
end
|
@@ -203,4 +203,16 @@ class DominoFormTest < Minitest::Test
|
|
203
203
|
def test_supports_normal_attributes
|
204
204
|
assert_equal({ action: '/people/23', submit_method: 'post' }, Dom::PersonForm.find!.attributes)
|
205
205
|
end
|
206
|
+
|
207
|
+
def test_named_field_method_yields_node
|
208
|
+
person = Dom::PersonForm.find!
|
209
|
+
name_field_node = page.find_field('First Name')
|
210
|
+
assert_equal(name_field_node, person.name { |node| node })
|
211
|
+
person.name { |node| node }
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_named_field_yield_usefulness
|
215
|
+
person = Dom::PersonForm.find!
|
216
|
+
assert_equal ['- Select a Color -', 'Red', 'Blue', 'Green'], person.favorite_color { |n| n.all('option').map(&:text) }
|
217
|
+
end
|
206
218
|
end
|
data/test/domino_test.rb
CHANGED
@@ -188,4 +188,21 @@ class DominoTest < Minitest::Test
|
|
188
188
|
Dom::NoSelector.where(foo: 'bar')
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
def test_named_field_method_yields_node
|
193
|
+
person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
|
194
|
+
name_node = page.find(".person[data-uuid='e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f'] .name")
|
195
|
+
assert_equal(name_node, person.name { |node| node })
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_named_field_method_yields_node_when_combinator
|
199
|
+
person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
|
200
|
+
uuid_node = page.find(".person[data-uuid='e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f']")
|
201
|
+
assert_equal(uuid_node, person.uuid { |node| node })
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_named_field_yield_usefulness
|
205
|
+
person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
|
206
|
+
assert_equal 'h2', person.name(&:tag_name)
|
207
|
+
end
|
191
208
|
end
|
data/test/test_application.rb
CHANGED
@@ -22,7 +22,7 @@ class TestApplication
|
|
22
22
|
edit params
|
23
23
|
when '/people/23'
|
24
24
|
params = Rack::Utils.parse_nested_query(env.fetch('rack.input').read)
|
25
|
-
edit params.merge(flash:
|
25
|
+
edit params.merge(flash: 'Person updated successfully.')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|