Module: Capybara::ActiveAdmin::Matchers::Table

Defined in:
lib/capybara/active_admin/matchers/table.rb

Instance Method Summary collapse

Instance Method Details

#have_table(options = {}) ⇒ Object

Examples:

expect(page).to have_table
expect(page).to have_table(resource_name: 'users')

Parameters:

  • options (Hash) (defaults to: {})

    :resource_name [String, nil] active admin page resource name for other options @see Capybara::RSpecMatchers#have_selector



14
15
16
17
18
# File 'lib/capybara/active_admin/matchers/table.rb', line 14

def have_table(options = {})
  resource_name = options.delete(:resource_name)
  selector = table_selector(resource_name)
  have_selector(selector, **options)
end

#have_table_cell(options = {}) ⇒ Object

Examples:

within_table_for('users') do
  within_table_row(id: user.id) do
    expect(page).to have_table_cell(count: 5)
    expect(page).to have_table_cell(text: user.id.to_s)
    expect(page).to have_table_cell(text: 'John Doe', column: 'Full name')
  end
end

Parameters:

  • options (Hash) (defaults to: {})

    :text [String, nil] cell content include matching :exact_text [String, nil] cell content exact matching :column [String, nil] cell header name for other options @see Capybara::RSpecMatchers#have_selector



50
51
52
53
54
55
# File 'lib/capybara/active_admin/matchers/table.rb', line 50

def have_table_cell(options = {})
  column = options.delete(:column)
  selector = table_cell_selector(column)

  have_selector(selector, **options)
end

#have_table_header(text, options = {}) ⇒ Object

Examples:

expect(page).to have_table_header('Full Name')
expect(page).to have_table_header('Full Name', sortable: true)
expect(page).to have_table_header('Full Name', sort_direction: :asc)

Parameters:

  • text (String)

    column header text.

  • options (Hash) (defaults to: {})
  • column (Hash)

    a customizable set of options

  • sortable (Hash)

    a customizable set of options

  • sort_direction (Hash)

    a customizable set of options



87
88
89
90
91
# File 'lib/capybara/active_admin/matchers/table.rb', line 87

def have_table_header(text, options = {})
  selector = table_header_selector(text, options)
  opts = options.except(:column, :sortable, :sort_direction).merge(exact_text: text)
  have_selector(selector, **opts)
end

#have_table_row(options = {}) ⇒ Object

Examples:

within_table_for('users') do
  expect(page).to have_table_row(id: user.id)
end

Parameters:

  • options (Hash) (defaults to: {})

    :text [String, nil] cell content :exact_text [String, nil] cell content exact matching :id [String, Number, nil] record ID for other options @see Capybara::RSpecMatchers#have_selector



30
31
32
33
34
# File 'lib/capybara/active_admin/matchers/table.rb', line 30

def have_table_row(options = {})
  row_id = options.delete(:id)
  selector = table_row_selector(row_id)
  have_selector(selector, **options)
end

#have_table_scope(title = nil, selected: false, **options) ⇒ Object

Parameters:

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

    exact title of scope to match.

  • selected (Boolean) (defaults to: false)

    whether to match selected (active) scope only (default false).

  • options (Hash)

    additional options passed to have_selector.



66
67
68
69
70
71
72
73
74
75
# File 'lib/capybara/active_admin/matchers/table.rb', line 66

def have_table_scope(title = nil, selected: false, **options)
  selector = "#{table_scopes_container_selector} > #{table_scope_selector}"
  if title.nil?
    selector = selected ? "#{selector}.selected" : "#{selector}:not(.selected)"
    have_selector(selector, **options)
  else
    selector = selected ? "#{selector}.selected" : selector
    have_selector(selector, exact_text: title.to_s, **options)
  end
end

#have_table_scopes(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})
  • count (Hash)

    a customizable set of options



59
60
61
# File 'lib/capybara/active_admin/matchers/table.rb', line 59

def have_table_scopes(options = {})
  have_selector("#{table_scopes_container_selector} > #{table_scope_selector}", **options)
end