Class: Chop::Form
- Inherits:
-
Struct
- Object
- Struct
- Chop::Form
- Defined in:
- lib/chop/form.rb
Defined Under Namespace
Classes: Checkbox, Default, Field, MultipleCheckbox, MultipleFile, MultipleSelect, Radio, Select, SingleFile, ViaJavascript
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#session ⇒ Object
Returns the value of attribute session.
-
#table ⇒ Object
Returns the value of attribute table.
Class Method Summary collapse
- .diff!(selector, table, session: Capybara.current_session, &block) ⇒ Object
- .fill_in!(table, session: Capybara.current_session, path: "features/support/fixtures") ⇒ Object
- .find_label_for(field, session: Capybara.current_session) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path
5 6 7 |
# File 'lib/chop/form.rb', line 5 def path @path end |
#session ⇒ Object
Returns the value of attribute session
5 6 7 |
# File 'lib/chop/form.rb', line 5 def session @session end |
#table ⇒ Object
Returns the value of attribute table
5 6 7 |
# File 'lib/chop/form.rb', line 5 def table @table end |
Class Method Details
.diff!(selector, table, session: Capybara.current_session, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chop/form.rb', line 10 def self.diff! selector, table, session: Capybara.current_session, &block root = begin if selector.is_a?(Capybara::Node::Element) selector else session.find(selector) end rescue Capybara::ElementNotFound raise unless @allow_not_found Node("") end all_fields = root.all("input, textarea, select") relevant_fields = all_fields.inject([]) do |fields, field| next fields if field[:name].blank? next fields if field[:type] == "submit" next fields if field[:type] == "hidden" fields + [field] end deduplicated_fields = relevant_fields.inject([]) do |fields, field| next fields if fields.map { |field| field[:name] }.include?(field[:name]) fields + [field] end actual = deduplicated_fields.inject([]) do |fields, field| next fields unless label = find_label_for(field) field = Field.from(session, field) fields + [[label.text(:all), field.get_value.to_s]] end table.diff! actual, surplus_row: false, misplaced_col: false end |
.fill_in!(table, session: Capybara.current_session, path: "features/support/fixtures") ⇒ Object
6 7 8 |
# File 'lib/chop/form.rb', line 6 def self.fill_in! table, session: Capybara.current_session, path: "features/support/fixtures" new(table, session, path).fill_in! end |
.find_label_for(field, session: Capybara.current_session) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/chop/form.rb', line 41 def self.find_label_for field, session: Capybara.current_session if field[:id].present? session.first("label[for='#{field[:id]}']", visible: :all, minimum: 0, wait: 0.1) else puts "cannot find label without id for #{field[:name]}" end end |