Module: Dommy::Rails::FormInspector

Defined in:
lib/dommy/rails/form_inspector.rb

Class Method Summary collapse

Class Method Details

.authenticity_token(form) ⇒ Object



22
23
24
25
# File 'lib/dommy/rails/form_inspector.rb', line 22

def authenticity_token(form)
  input = form.query_selector("input[type='hidden'][name='authenticity_token']")
  input ? input.get_attribute("value") : nil
end

.matches?(document, action: nil, method: nil, model: nil) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/dommy/rails/form_inspector.rb', line 11

def matches?(document, action: nil, method: nil, model: nil)
  forms = Internal::ElementMatching.find_forms(document, action: action && UrlMatcher.new(action), method: method)
  forms = forms.select { |form| form_has_model?(form, model_name_for(model)) } if model
  forms.any?
end

.method_override(form) ⇒ Object



17
18
19
20
# File 'lib/dommy/rails/form_inspector.rb', line 17

def method_override(form)
  hidden = form.query_selector("input[type='hidden'][name='_method']")
  hidden ? hidden.get_attribute("value") : nil
end