Skip to content

Commit cacd3ae

Browse files
committed
remove model_name from table related DSL arguments, improve API
1 parent fcace1a commit cacd3ae

File tree

16 files changed

+100
-55
lines changed

16 files changed

+100
-55
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- remove model_name from table related DSL arguments
10+
- improve API
811

912
## [0.3.1] - 2020-04-15
1013
### Added

lib/capybara/active_admin/actions/layout.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Capybara
44
module ActiveAdmin
55
module Actions
6+
# Actions for common Active Admin components.
67
module Layout
78
def click_action_item(title, options = {})
89
within(action_items_container_selector) do

lib/capybara/active_admin/finders.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
module Capybara
99
module ActiveAdmin
10+
# Finders are methods that find DOM element(s) or change current scope to node element.
11+
#
12+
# Find element(s) method names should start with *find_*.
13+
#
14+
# Change current scope method names should start with *within_*.
1015
module Finders
11-
# Finders are methods that find node element(s) or change current scope to node element.
12-
1316
include Finders::Layout
1417
include Finders::Table
1518
include Finders::AttributesTable

lib/capybara/active_admin/finders/attributes_table.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
module Capybara
44
module ActiveAdmin
55
module Finders
6+
# Finder methods for ActiveAdmin attributes_table_for can be found here.
7+
# @see Capybara::ActiveAdmin::Finders base finders module.
68
module AttributesTable
7-
# @param model_name [Class<Object>, nil] model name or class.
8-
# @param record_id [String, Numeric, nil]
9-
# @yield within attributes table
10-
def within_attributes_table_for(model_name, record_id = nil)
11-
selector = attributes_table_selector(model_name, record_id)
9+
# Calls block within attributes table.
10+
# @param model [Class<Object>, nil] model name or class.
11+
# @param id [String, Numeric, nil] record ID.
12+
# @yield within attributes table.
13+
def within_attributes_table_for(model: nil, id: nil)
14+
selector = attributes_table_selector(model: model, id: id)
1215
within(selector) { yield }
1316
end
1417

18+
# Calls block within attributes table row.
19+
# @param label [String] row label.
20+
# @yield within attributes table.
1521
def within_attribute_row(label)
1622
selector = attributes_row_selector(label)
1723
within(selector) { yield }

lib/capybara/active_admin/finders/form.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
module Capybara
44
module ActiveAdmin
55
module Finders
6+
# Finders for *active_admin_form_for* and related form components.
67
module Form
7-
# @param name [Class<Object>, String] form record class or model name
8+
# @param model_name [Class<Object>, String, nil] form record class or model name (default nil).
89
# @yield within form
9-
def within_form_for(name)
10-
name = name.model_name.singular if name.is_a?(Class)
11-
selector = form_selector(name)
10+
def within_form_for(model_name = nil)
11+
selector = form_selector(model_name)
1212
within(selector) { yield }
1313
end
1414

1515
# @param association_name [String]
16-
# @param index [String] index of fieldset, starts with 0.
16+
# @param index [String] index of fieldset, starts with 0 (default 0).
1717
# @yield within fieldset>ol
1818
def within_form_has_many(association_name, index: 0)
1919
selector = has_many_fields_selector(association_name)
@@ -22,6 +22,7 @@ def within_form_has_many(association_name, index: 0)
2222
within(fieldset) { yield }
2323
end
2424

25+
# @yield within filters container.
2526
def within_filters
2627
selector = filter_form_selector
2728
within(selector) { yield }

lib/capybara/active_admin/finders/layout.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Capybara
44
module ActiveAdmin
55
module Finders
6+
# Finders for common Active Admin components.
67
module Layout
78
def find_footer(options = {})
89
selector = footer_selector

lib/capybara/active_admin/finders/table.rb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@
33
module Capybara
44
module ActiveAdmin
55
module Finders
6+
# Finders for *table_for*, it's rows and cells.
67
module Table
7-
def current_table_model_name
8-
@__current_table_model_name
9-
end
10-
11-
# @param model_name [Class<#model_name>, String] records class or model name to match rows.
128
# @param resource_name [String, nil] resource name of index page.
139
# @yield within table
14-
def within_table_for(model_name, resource_name = nil)
10+
def within_table_for(resource_name = nil)
1511
selector = table_selector(resource_name)
1612

17-
within(selector) do
18-
old = @__current_table_model_name
19-
@__current_table_model_name = model_name
20-
begin
21-
yield
22-
ensure
23-
@__current_table_model_name = old
24-
end
25-
end
13+
within(selector) { yield }
2614
end
2715

2816
# id [String, Integer, nil] record ID.
@@ -38,11 +26,11 @@ def find_table_row(id: nil, index: nil)
3826
raise ArgumentError, 'must provide :id or :index' if id.nil? && index.nil?
3927

4028
if id
41-
selector = table_row_selector(current_table_model_name, id)
29+
selector = table_row_selector(id)
4230
return find(selector)
4331
end
4432

45-
selector = table_row_selector(nil, nil)
33+
selector = table_row_selector(nil)
4634
find_all(selector, minimum: index + 1)[index]
4735
end
4836

lib/capybara/active_admin/matchers/attributes_table.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module ActiveAdmin
55
module Matchers
66
module AttributesTable
77
def have_attributes_table(options = {})
8-
model_name = options.delete(:model)
9-
record_id = options.delete(:id)
10-
selector = attributes_table_selector(model_name, record_id)
8+
model = options.delete(:model)
9+
id = options.delete(:id)
10+
selector = attributes_table_selector(model: model, id: id)
1111
have_selector(selector, options)
1212
end
1313

lib/capybara/active_admin/matchers/layout.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Capybara
44
module ActiveAdmin
55
module Matchers
6+
# Matchers for common Active Admin components.
67
module Layout
78
def have_action_item(text, options = {})
89
opts = Util.options_with_text(text, options)

lib/capybara/active_admin/matchers/table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def have_table(options = {})
2929
#
3030
def have_table_row(options = {})
3131
row_id = options.delete(:id)
32-
selector = table_row_selector(current_table_model_name, row_id)
32+
selector = table_row_selector(row_id)
3333
have_selector(selector, options)
3434
end
3535

0 commit comments

Comments
 (0)