Module: Capybara::ActiveAdmin::Finders::Table

Included in:
Capybara::ActiveAdmin::Finders
Defined in:
lib/capybara/active_admin/finders/table.rb

Overview

Finders for table_for, it’s rows and cells.

Instance Method Summary collapse

Instance Method Details

#find_table_cell(column) ⇒ Object



43
44
45
46
# File 'lib/capybara/active_admin/finders/table.rb', line 43

def find_table_cell(column)
  selector = table_cell_selector(column)
  find(selector)
end

#find_table_row(id: nil, index: nil) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/capybara/active_admin/finders/table.rb', line 24

def find_table_row(id: nil, index: nil)
  raise ArgumentError, "can't use both :id and :index" if id && index
  raise ArgumentError, 'must provide :id or :index' if id.nil? && index.nil?

  if id
    selector = table_row_selector(id)
    return find(selector)
  end

  selector = table_row_selector(nil)
  find_all(selector, minimum: index + 1)[index]
end

#within_table_cell(name) { ... } ⇒ Object

Yields:

  • within table>tbody>tr>td



38
39
40
41
# File 'lib/capybara/active_admin/finders/table.rb', line 38

def within_table_cell(name)
  cell = find_table_cell(name)
  within(cell) { yield }
end

#within_table_for(resource_name = nil) { ... } ⇒ Object

Parameters:

  • resource_name (String, nil) (defaults to: nil)

    resource name of index page.

Yields:

  • within table



10
11
12
13
14
# File 'lib/capybara/active_admin/finders/table.rb', line 10

def within_table_for(resource_name = nil)
  selector = table_selector(resource_name)

  within(selector) { yield }
end

#within_table_row(id: nil, index: nil) { ... } ⇒ Object

id [String, Integer, nil] record ID. index [Integer] row index in table (starts with 0).

Yields:

  • within table>tbody>tr



19
20
21
22
# File 'lib/capybara/active_admin/finders/table.rb', line 19

def within_table_row(id: nil, index: nil)
  row = find_table_row(id: id, index: index)
  within(row) { yield }
end