Module: PageRecord::Actions::ActionHandler

Defined in:
lib/page_record/actions.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, message = nil) ⇒ Capybara::Element

This is the implementation of the page and record action routine. It has two variants. it has a ? variant and a normal variant.

normal variant: It checks the page for a data-action-for='action' tag somewhere on the page. If it finds it, it clicks it.

? variant: It checks the page for a data-action-for='action' tag somewhere on the page. If it finds it, returns the Capybara result.

Parameters:

  • action (Symbol)

    this is the name of the action

Returns:

  • (Capybara::Element)

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/page_record/actions.rb', line 47

def method_missing(action, message = nil)
  raw_action = /(.*)\?/.match(action)
  begin
    if raw_action
      action_for?(raw_action[1])
    else
      action_for(action)
    end
  rescue Capybara::Ambiguous
    message ||= "Found multiple #{action} tags for #{@type} on page"
    raise MultipleRecords, message
  rescue Capybara::ElementNotFound
    super
  end
end