capybara_active_admin 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16668060b6810df687cbcfd8757396b2ff13c9f98519090928308f872609017f
|
4
|
+
data.tar.gz: 6f005ee3bcf21792abf5246d284802aa1ae52544c1547cd9f1ca0ece36ef6e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9488c08a71f94b535a4723fce444cb5a4bbf804c34c3e9593e10849925476e7294a47db30420669fbe87aa38bc2e8bfb249f0b7312e67c6c9057678eea82eea8
|
7
|
+
data.tar.gz: 3bdf50dc809f1515e64bc73a46d622cb540342ef8da2e587ff9627f9018eee75565b5402c692eb23ad97030f07c7e47249535b961de2e0f3173e85627a003f8a
|
data/CHANGELOG.md
CHANGED
@@ -6,13 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [0.2.
|
10
|
-
###
|
11
|
-
-
|
12
|
-
|
13
|
-
|
9
|
+
## [0.2.1] - 2020-04-14
|
10
|
+
### Fixed
|
11
|
+
- `table_selector`, `within_table_for` incorrect resource name
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- `table_selector` receives 2 arguments
|
15
|
+
- `within_table_for` receives 2 arguments
|
16
|
+
- `current_table_name` renamed to `current_table_model_name`
|
17
|
+
- `table_row_selector` can receive modal class as model name
|
18
|
+
|
19
|
+
# Added
|
20
|
+
- `have_table` matcher
|
21
|
+
- add tests for table with namespaced resource class and multi-word resource name
|
14
22
|
|
15
|
-
|
23
|
+
## [0.2.0] - 2020-04-14
|
24
|
+
### Changed
|
25
|
+
- rename `have_table_col` to `have_table_cell`
|
26
|
+
- change options of `have_table_cell`
|
27
|
+
- change options of `have_table_row`
|
16
28
|
- refactor modules hierarchy: split DSL into selectors, finders, matchers and actions
|
17
29
|
|
18
30
|
### Added
|
@@ -4,21 +4,23 @@ module Capybara
|
|
4
4
|
module ActiveAdmin
|
5
5
|
module Finders
|
6
6
|
module Table
|
7
|
-
def
|
8
|
-
@
|
7
|
+
def current_table_model_name
|
8
|
+
@__current_table_model_name
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# @param model_name [Class<#model_name>, String] records class or model name to match rows.
|
12
|
+
# @param resource_name [String, nil] resource name of index page.
|
13
|
+
# @yield within table.
|
14
|
+
def within_table_for(model_name, resource_name = nil)
|
15
|
+
selector = table_selector(resource_name)
|
14
16
|
|
15
17
|
within(selector) do
|
16
|
-
old = @
|
17
|
-
@
|
18
|
+
old = @__current_table_model_name
|
19
|
+
@__current_table_model_name = model_name
|
18
20
|
begin
|
19
21
|
yield
|
20
22
|
ensure
|
21
|
-
@
|
23
|
+
@__current_table_model_name = old
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -33,12 +35,12 @@ module Capybara
|
|
33
35
|
raise ArgumentError, 'must provide :id or :index' if id.nil? && index.nil?
|
34
36
|
|
35
37
|
if id
|
36
|
-
|
37
|
-
selector = table_row_selector(model, id)
|
38
|
+
selector = table_row_selector(current_table_model_name, id)
|
38
39
|
return find(selector)
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
+
selector = table_row_selector(nil, nil)
|
43
|
+
find_all(selector, minimum: index + 1)[index]
|
42
44
|
end
|
43
45
|
|
44
46
|
def within_table_cell(name)
|
@@ -4,6 +4,19 @@ module Capybara
|
|
4
4
|
module ActiveAdmin
|
5
5
|
module Matchers
|
6
6
|
module Table
|
7
|
+
# @param options [Hash]
|
8
|
+
# :resource_name [String, nil] active admin page resource name
|
9
|
+
# for other options @see Capybara::RSpecMatchers#have_selector
|
10
|
+
# @example
|
11
|
+
# expect(page).to have_table
|
12
|
+
# expect(page).to have_table(resource_name: 'users')
|
13
|
+
#
|
14
|
+
def have_table(options = {})
|
15
|
+
resource_name = options.delete(:resource_name)
|
16
|
+
selector = table_selector(resource_name)
|
17
|
+
have_selector(selector, options)
|
18
|
+
end
|
19
|
+
|
7
20
|
# @param options [Hash]
|
8
21
|
# :text [String, nil] cell content
|
9
22
|
# :id [String, Number, nil] record ID
|
@@ -15,7 +28,7 @@ module Capybara
|
|
15
28
|
#
|
16
29
|
def have_table_row(options = {})
|
17
30
|
row_id = options.delete(:id)
|
18
|
-
selector = table_row_selector(
|
31
|
+
selector = table_row_selector(current_table_model_name, row_id)
|
19
32
|
have_selector(selector, options)
|
20
33
|
end
|
21
34
|
|
@@ -4,16 +4,19 @@ module Capybara
|
|
4
4
|
module ActiveAdmin
|
5
5
|
module Selectors
|
6
6
|
module Table
|
7
|
-
def table_selector(
|
8
|
-
return 'table.index_table' if
|
7
|
+
def table_selector(resource_name)
|
8
|
+
return 'table.index_table' if resource_name.nil?
|
9
9
|
|
10
|
-
|
10
|
+
resource_name = resource_name.to_s.gsub(' ', '_').pluralize.downcase
|
11
|
+
"table#index_table_#{resource_name}"
|
11
12
|
end
|
12
13
|
|
13
|
-
def table_row_selector(
|
14
|
+
def table_row_selector(model_name, record_id)
|
14
15
|
return 'tbody > tr' if record_id.nil?
|
15
16
|
|
16
|
-
|
17
|
+
model_name = model_name.model_name.singular if model_name.is_a?(Class)
|
18
|
+
model_name = model_name.to_s.gsub(' ', '_').singularize.downcase
|
19
|
+
"tbody > tr##{model_name}_#{record_id}"
|
17
20
|
end
|
18
21
|
|
19
22
|
def table_header_selector
|
@@ -21,9 +24,9 @@ module Capybara
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def table_cell_selector(column)
|
24
|
-
column = column.to_s.gsub(' ', '_').downcase unless column.nil?
|
25
27
|
return 'td.col' if column.nil?
|
26
28
|
|
29
|
+
column = column.to_s.gsub(' ', '_').downcase
|
27
30
|
"td.col.col-#{column}"
|
28
31
|
end
|
29
32
|
end
|