capybara_active_admin 0.1.0 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +27 -0
- data/README.md +23 -10
- data/capybara_active_admin.gemspec +1 -1
- data/lib/capybara/active_admin.rb +4 -0
- data/lib/capybara/active_admin/actions.rb +20 -0
- data/lib/capybara/active_admin/actions/attributes_table.rb +11 -0
- data/lib/capybara/active_admin/actions/form.rb +19 -0
- data/lib/capybara/active_admin/actions/layout.rb +15 -0
- data/lib/capybara/active_admin/actions/table.rb +10 -0
- data/lib/capybara/active_admin/finders.rb +19 -0
- data/lib/capybara/active_admin/finders/attributes_table.rb +11 -0
- data/lib/capybara/active_admin/finders/form.rb +26 -0
- data/lib/capybara/active_admin/finders/layout.rb +11 -0
- data/lib/capybara/active_admin/finders/table.rb +56 -0
- data/lib/capybara/active_admin/matchers.rb +19 -0
- data/lib/capybara/active_admin/matchers/attributes_table.rb +11 -0
- data/lib/capybara/active_admin/matchers/form.rb +53 -0
- data/lib/capybara/active_admin/matchers/layout.rb +26 -0
- data/lib/capybara/active_admin/matchers/table.rb +44 -0
- data/lib/capybara/active_admin/selectors.rb +20 -0
- data/lib/capybara/active_admin/selectors/attributes_table.rb +11 -0
- data/lib/capybara/active_admin/selectors/form.rb +50 -0
- data/lib/capybara/active_admin/selectors/layout.rb +27 -0
- data/lib/capybara/active_admin/selectors/table.rb +32 -0
- data/lib/capybara/active_admin/test_helpers.rb +4 -83
- data/lib/capybara/active_admin/version.rb +1 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa80eda0b75b26f75d6b7a1a0df8355c8ef0bdb622687ecbd020bdc0cec6688
|
4
|
+
data.tar.gz: a9d73931be3341bca9fc81399009ae7f7c1045d72976ab24603d5818a408ed65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a5c5af2f5bf9bdfb9ceb7f8dfdbf416ecd02b8a51df91e8a310dcfb9ff4ec7f40556059edf4070a352999c7c67129c2c97eaf6ff6ef5a44110e85523f4af553
|
7
|
+
data.tar.gz: 653677e018c186b840985382f29a1735595d3a0a4a193b4c7472edae0065decac190663a794a917d323b9d24701a0d9f9035927ffa43ff26e8f7da8babd07ead
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.2.0] - 2020-04-14
|
10
|
+
### Breaking change
|
11
|
+
- rename #have_table_col to #have_table_cell
|
12
|
+
- change options of #have_table_cell
|
13
|
+
- change options of #have_table_row
|
14
|
+
|
15
|
+
### Change
|
16
|
+
- refactor modules hierarchy: split DSL into selectors, finders, matchers and actions
|
17
|
+
|
18
|
+
### Added
|
19
|
+
- form DSL
|
20
|
+
- changelog
|
21
|
+
- follow semver
|
22
|
+
|
23
|
+
## [0.1.0] - 2020-04-14
|
24
|
+
### Added
|
25
|
+
- travic CI
|
26
|
+
- rubocop
|
27
|
+
- capybara DSL to check page title, action items, table columns/rows
|
data/README.md
CHANGED
@@ -45,15 +45,20 @@ RSpec.describe 'Users', js: true do
|
|
45
45
|
expect(page).to have_action_item('New User')
|
46
46
|
expect(page).to_not have_action_item('Edit User')
|
47
47
|
|
48
|
-
|
48
|
+
within_table_for('users') do
|
49
49
|
expect(page).to have_table_row(count: 2)
|
50
|
-
expect(page).to
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
expect(page).to have_table_cell('John Doe')
|
51
|
+
|
52
|
+
within_table_row(id: john.id) do
|
53
|
+
expect(page).to have_table_cell('John Doe', row_id: john.id)
|
54
|
+
expect(page).to have_table_cell('John Doe', row_id: john.id, col_name: 'Full Name')
|
55
|
+
expect(page).to_not have_table_cell('John Doe', row_id: john.id, col_name: 'Id')
|
56
|
+
end
|
57
|
+
|
58
|
+
within_table_row(id: jane.id) do
|
59
|
+
expect(page).to_not have_table_cell('John Doe')
|
60
|
+
expect(page).to_not have_table_cell('John Doe', col_name: 'Full Name')
|
61
|
+
end
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
@@ -63,8 +68,11 @@ RSpec.describe 'Users', js: true do
|
|
63
68
|
click_action_item('New User')
|
64
69
|
expect(page).to have_current_path(new_admin_user_path)
|
65
70
|
|
66
|
-
|
67
|
-
|
71
|
+
within_form_for(User) do
|
72
|
+
fill_in 'Full name', with: 'Johny Cage'
|
73
|
+
click_submit 'Create User'
|
74
|
+
end
|
75
|
+
|
68
76
|
expect(page).to have_flash_message('User was successfully created.', type: :notice)
|
69
77
|
user = User.last!
|
70
78
|
expect(page).to have_current_path admin_user_path(user.id)
|
@@ -95,3 +103,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
95
103
|
## Code of Conduct
|
96
104
|
|
97
105
|
Everyone interacting in the Capybara::ActiveAdmin project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/activeadmin-plugins/capybara_active_admin/blob/master/CODE_OF_CONDUCT.md).
|
106
|
+
|
107
|
+
## Notes
|
108
|
+
|
109
|
+
Project uses [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
|
110
|
+
Project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
-
spec.metadata['changelog_uri'] = spec.homepage
|
19
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'capybara/active_admin/version'
|
4
|
+
require 'capybara/active_admin/selectors'
|
5
|
+
require 'capybara/active_admin/finders'
|
6
|
+
require 'capybara/active_admin/matchers'
|
7
|
+
require 'capybara/active_admin/actions'
|
4
8
|
require 'capybara/active_admin/test_helpers'
|
5
9
|
|
6
10
|
module Capybara
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'capybara/active_admin/actions/layout'
|
4
|
+
require 'capybara/active_admin/actions/table'
|
5
|
+
require 'capybara/active_admin/actions/attributes_table'
|
6
|
+
require 'capybara/active_admin/actions/form'
|
7
|
+
|
8
|
+
module Capybara
|
9
|
+
module ActiveAdmin
|
10
|
+
module Actions
|
11
|
+
# Actions are interactions with page that change something.
|
12
|
+
# Click, scroll, fill, clear, switch - all these are interactions.
|
13
|
+
|
14
|
+
include Actions::Layout
|
15
|
+
include Actions::Table
|
16
|
+
include Actions::AttributesTable
|
17
|
+
include Actions::Form
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Actions
|
6
|
+
module Form
|
7
|
+
def click_submit(value, options = {})
|
8
|
+
selector = form_submit_selector(value)
|
9
|
+
find(selector, options).click
|
10
|
+
end
|
11
|
+
|
12
|
+
def fill_in_file(label, options = {})
|
13
|
+
path = options.delete(:with)
|
14
|
+
attach_file(label, path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Actions
|
6
|
+
module Layout
|
7
|
+
def click_action_item(title, options = {})
|
8
|
+
within(action_items_container_selector) do
|
9
|
+
click_link(title, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'capybara/active_admin/finders/layout'
|
4
|
+
require 'capybara/active_admin/finders/table'
|
5
|
+
require 'capybara/active_admin/finders/attributes_table'
|
6
|
+
require 'capybara/active_admin/finders/form'
|
7
|
+
|
8
|
+
module Capybara
|
9
|
+
module ActiveAdmin
|
10
|
+
module Finders
|
11
|
+
# Finders are methods that find node element(s) or change current scope to node element.
|
12
|
+
|
13
|
+
include Finders::Layout
|
14
|
+
include Finders::Table
|
15
|
+
include Finders::AttributesTable
|
16
|
+
include Finders::Form
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Finders
|
6
|
+
module Form
|
7
|
+
# @param name [Class<Object>, String] form record class or model name
|
8
|
+
def within_form_for(name)
|
9
|
+
name = name.model_name.singular if name.is_a?(Class)
|
10
|
+
selector = form_selector(name)
|
11
|
+
within(selector) { yield }
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param association_name [String]
|
15
|
+
# @param index [String] index of fieldset, starts with 0.
|
16
|
+
# @yield within fieldset>ol
|
17
|
+
def within_form_has_many(association_name, index: 0)
|
18
|
+
selector = has_many_fields_selector(association_name)
|
19
|
+
fieldset = find_all(selector, minimum: index + 1)[index]
|
20
|
+
|
21
|
+
within(fieldset) { yield }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Finders
|
6
|
+
module Table
|
7
|
+
def current_table_name
|
8
|
+
@__current_table_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def within_table_for(name)
|
12
|
+
name = name.model_name.plural if name.is_a?(Class)
|
13
|
+
selector = table_selector(name)
|
14
|
+
|
15
|
+
within(selector) do
|
16
|
+
old = @__current_table_name
|
17
|
+
@__current_table_name = name
|
18
|
+
begin
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
@__current_table_name = old
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def within_table_row(id: nil, index: nil)
|
27
|
+
row = find_table_row(id: id, index: index)
|
28
|
+
within(row) { yield }
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_table_row(id: nil, index: nil)
|
32
|
+
raise ArgumentError, "can't use both :id and :index" if id && index
|
33
|
+
raise ArgumentError, 'must provide :id or :index' if id.nil? && index.nil?
|
34
|
+
|
35
|
+
if id
|
36
|
+
model = @__current_table_name
|
37
|
+
selector = table_row_selector(model, id)
|
38
|
+
return find(selector)
|
39
|
+
end
|
40
|
+
|
41
|
+
find_all(table_row_selector(nil, nil), minimum: index + 1)[index]
|
42
|
+
end
|
43
|
+
|
44
|
+
def within_table_cell(name)
|
45
|
+
cell = find_table_cell(name)
|
46
|
+
within(cell) { yield }
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_table_cell(column)
|
50
|
+
selector = table_cell_selector(column)
|
51
|
+
find(selector)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'capybara/active_admin/matchers/layout'
|
4
|
+
require 'capybara/active_admin/matchers/table'
|
5
|
+
require 'capybara/active_admin/matchers/attributes_table'
|
6
|
+
require 'capybara/active_admin/matchers/form'
|
7
|
+
|
8
|
+
module Capybara
|
9
|
+
module ActiveAdmin
|
10
|
+
module Matchers
|
11
|
+
# RSpec matchers should be putted here.
|
12
|
+
|
13
|
+
include Matchers::Layout
|
14
|
+
include Matchers::Table
|
15
|
+
include Matchers::AttributesTable
|
16
|
+
include Matchers::Form
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Matchers
|
6
|
+
module Form
|
7
|
+
def have_form_error(error, options = {})
|
8
|
+
field = options.delete(:field)
|
9
|
+
opts = options.merge(text: error)
|
10
|
+
return have_selector("li #{inline_error_selector}", opts) if field.nil?
|
11
|
+
|
12
|
+
label = find(label_selector, text: field)
|
13
|
+
li_id = label.ancestor('li')[:id]
|
14
|
+
have_selector("li##{li_id} #{inline_error_selector}", opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def have_no_form_errors(options = {})
|
18
|
+
field = options.delete(:field)
|
19
|
+
return have_none_of_selectors(:css, "li #{inline_error_selector}", options) if field.nil?
|
20
|
+
|
21
|
+
label = find(label_selector, text: field)
|
22
|
+
li_id = label.ancestor('li')[:id]
|
23
|
+
have_none_of_selectors(:css, "li##{li_id} #{inline_error_selector}", options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def have_semantic_error(error, options = {})
|
27
|
+
opts = options.merge(text: error)
|
28
|
+
have_selector(semantic_error_selector, opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
def have_semantic_errors(options = {})
|
32
|
+
have_selector(semantic_error_selector, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def have_no_input(label, options = {})
|
36
|
+
opts = options.merge(text: label)
|
37
|
+
have_none_of_selectors(:css, label_selector, opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
def have_has_many_fields_for(association_name, options = {})
|
41
|
+
selector = has_many_fields_selector(association_name)
|
42
|
+
have_selector(selector, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def have_input(label, options = {})
|
46
|
+
selector = input_selector label, options.slice(:type, :text)
|
47
|
+
opts = options.except(:type, :text)
|
48
|
+
have_selector(selector, opts)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Matchers
|
6
|
+
module Layout
|
7
|
+
def have_action_item(text, options = {})
|
8
|
+
opts = options.merge(text: text)
|
9
|
+
have_selector(action_item_selector, opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def have_page_title(text, options = {})
|
13
|
+
opts = options.merge(text: text)
|
14
|
+
have_selector(page_title_selector, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def have_flash_message(text, options = {})
|
18
|
+
type = options.delete(:type)
|
19
|
+
opts = options.merge(text: text)
|
20
|
+
selector = flash_message_selector(type)
|
21
|
+
have_selector(selector, opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Matchers
|
6
|
+
module Table
|
7
|
+
# @param options [Hash]
|
8
|
+
# :text [String, nil] cell content
|
9
|
+
# :id [String, Number, nil] record ID
|
10
|
+
# for other options @see Capybara::RSpecMatchers#have_selector
|
11
|
+
# @example
|
12
|
+
# within_table_for('users') do
|
13
|
+
# expect(page).to have_table_row(id: user.id)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
def have_table_row(options = {})
|
17
|
+
row_id = options.delete(:id)
|
18
|
+
selector = table_row_selector(current_table_name, row_id)
|
19
|
+
have_selector(selector, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param options [Hash]
|
23
|
+
# :text [String, nil] cell content
|
24
|
+
# :column [String, nil] cell header name
|
25
|
+
# for other options @see Capybara::RSpecMatchers#have_selector
|
26
|
+
# @example
|
27
|
+
# within_table_for('users') do
|
28
|
+
# within_table_row(id: user.id) do
|
29
|
+
# expect(page).to have_table_cell(count: 5)
|
30
|
+
# expect(page).to have_table_cell(text: user.id.to_s)
|
31
|
+
# expect(page).to have_table_cell(text: 'John Doe', column: 'Full name')
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
def have_table_cell(options = {})
|
36
|
+
column = options.delete(:column)
|
37
|
+
selector = table_cell_selector(column)
|
38
|
+
|
39
|
+
have_selector(selector, options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
require 'capybara/active_admin/selectors/layout'
|
5
|
+
require 'capybara/active_admin/selectors/table'
|
6
|
+
require 'capybara/active_admin/selectors/attributes_table'
|
7
|
+
require 'capybara/active_admin/selectors/form'
|
8
|
+
|
9
|
+
module Capybara
|
10
|
+
module ActiveAdmin
|
11
|
+
module Selectors
|
12
|
+
# Methods that return css/xpath selectors should be placed here.
|
13
|
+
|
14
|
+
include Selectors::Layout
|
15
|
+
include Selectors::Table
|
16
|
+
include Selectors::AttributesTable
|
17
|
+
include Selectors::Form
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Selectors
|
6
|
+
module Form
|
7
|
+
# @param name [String] form model name
|
8
|
+
def form_selector(name)
|
9
|
+
"form.formtastic.#{name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def label_selector
|
13
|
+
'label.label'
|
14
|
+
end
|
15
|
+
|
16
|
+
def inline_error_selector
|
17
|
+
'p.inline-errors'
|
18
|
+
end
|
19
|
+
|
20
|
+
def semantic_error_selector
|
21
|
+
'ul.errors > li'
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_many_fields_selector(association_name)
|
25
|
+
"div.has_many_container.#{association_name} > fieldset.inputs.has_many_fields"
|
26
|
+
end
|
27
|
+
|
28
|
+
def form_submit_selector(value = nil)
|
29
|
+
selector = %(input[type="submit"])
|
30
|
+
selector += %([value="#{value}"]) unless value.nil?
|
31
|
+
selector
|
32
|
+
end
|
33
|
+
|
34
|
+
def input_selector(label, options)
|
35
|
+
text = options.delete(:text)
|
36
|
+
type = options.delete(:type) || :text
|
37
|
+
|
38
|
+
label_opts = options.merge(text: label)
|
39
|
+
label = find(label_selector, label_opts)
|
40
|
+
|
41
|
+
input_id = label[:for]
|
42
|
+
tag_name = type.to_sym == :select ? 'select' : 'input'
|
43
|
+
selector = "#{tag_name}##{input_id}"
|
44
|
+
selector = %(#{selector}[value="#{text}"]) unless text.nil?
|
45
|
+
selector
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Selectors
|
6
|
+
module Layout
|
7
|
+
def action_items_container_selector
|
8
|
+
'#titlebar_right .action_items'
|
9
|
+
end
|
10
|
+
|
11
|
+
def action_item_selector
|
12
|
+
"#{action_items_container_selector} .action_item"
|
13
|
+
end
|
14
|
+
|
15
|
+
def page_title_selector
|
16
|
+
'#page_title'
|
17
|
+
end
|
18
|
+
|
19
|
+
def flash_message_selector(type = nil)
|
20
|
+
return ".flashes .flash.flash_#{type}" if type
|
21
|
+
|
22
|
+
'.flashes .flash'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module ActiveAdmin
|
5
|
+
module Selectors
|
6
|
+
module Table
|
7
|
+
def table_selector(model)
|
8
|
+
return 'table.index_table' if model.nil?
|
9
|
+
|
10
|
+
"table.index_table#index_table_#{model.to_s.pluralize}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def table_row_selector(model, record_id)
|
14
|
+
return 'tbody > tr' if record_id.nil?
|
15
|
+
|
16
|
+
"tbody > tr##{model.to_s.singularize}_#{record_id}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def table_header_selector
|
20
|
+
'thead > tr > th.col'
|
21
|
+
end
|
22
|
+
|
23
|
+
def table_cell_selector(column)
|
24
|
+
column = column.to_s.gsub(' ', '_').downcase unless column.nil?
|
25
|
+
return 'td.col' if column.nil?
|
26
|
+
|
27
|
+
"td.col.col-#{column}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -3,89 +3,10 @@
|
|
3
3
|
module Capybara
|
4
4
|
module ActiveAdmin
|
5
5
|
module TestHelpers
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def click_action_item(title, options = {})
|
12
|
-
within '#titlebar_right .action_items' do
|
13
|
-
click_link(title, options)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def have_page_title(text, options = {})
|
18
|
-
opts = options.merge(text: text)
|
19
|
-
have_selector('#page_title', opts)
|
20
|
-
end
|
21
|
-
|
22
|
-
def have_flash_message(text, options = {})
|
23
|
-
type = options.delete(:type)
|
24
|
-
opts = options.merge(text: text)
|
25
|
-
selector = if type
|
26
|
-
".flashes .flash.flash_#{type}"
|
27
|
-
else
|
28
|
-
'.flashes .flash'
|
29
|
-
end
|
30
|
-
have_selector(selector, opts)
|
31
|
-
end
|
32
|
-
|
33
|
-
def have_table_row(options = {})
|
34
|
-
model = options.delete(:model)
|
35
|
-
row_id = options.delete(:row_id)
|
36
|
-
selector = table_row_selector(model, row_id: row_id)
|
37
|
-
have_selector(selector, options)
|
38
|
-
end
|
39
|
-
|
40
|
-
def have_table_col(text, options = {})
|
41
|
-
model = options.delete(:model)
|
42
|
-
row_id = options.delete(:row_id)
|
43
|
-
col_name = options.delete(:col_name)
|
44
|
-
selector = table_col_selector(model, row_id: row_id, col_name: col_name)
|
45
|
-
opts = options.merge(text: text)
|
46
|
-
have_selector(selector, opts)
|
47
|
-
end
|
48
|
-
|
49
|
-
def table_selector(model)
|
50
|
-
model ||= current_table_model
|
51
|
-
return 'table.index_table' if model.nil?
|
52
|
-
|
53
|
-
"table.index_table#index_table_#{model.to_s.pluralize}"
|
54
|
-
end
|
55
|
-
|
56
|
-
def table_row_selector(model, row_id: nil)
|
57
|
-
model ||= current_table_model
|
58
|
-
raise ArgumentError, 'model required when row_id is passed' if row_id && model.nil?
|
59
|
-
|
60
|
-
selector = table_selector(model)
|
61
|
-
|
62
|
-
row_selector = row_id ? "tr##{model.to_s.singularize}_#{row_id}" : 'tr'
|
63
|
-
"#{selector} > tbody > #{row_selector}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def table_col_selector(model, row_id: nil, col_name: nil)
|
67
|
-
model ||= current_table_model
|
68
|
-
col_name = col_name.to_s.gsub(' ', '_').downcase if col_name
|
69
|
-
selector = table_row_selector(model, row_id: row_id)
|
70
|
-
col_selector = col_name ? "td.col.col-#{col_name}" : 'td.col'
|
71
|
-
"#{selector} > #{col_selector}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def with_table_for(model)
|
75
|
-
old = @_capybara_active_admin_table_model
|
76
|
-
@_capybara_active_admin_table_model = model
|
77
|
-
yield
|
78
|
-
ensure
|
79
|
-
@_capybara_active_admin_table_model = old
|
80
|
-
end
|
81
|
-
|
82
|
-
def current_table_model
|
83
|
-
@_capybara_active_admin_table_model
|
84
|
-
end
|
85
|
-
|
86
|
-
# extend RSpec::Matchers::DSL
|
87
|
-
# matcher :have_action_item do |expected|
|
88
|
-
# end
|
6
|
+
include Selectors
|
7
|
+
include Finders
|
8
|
+
include Matchers
|
9
|
+
include Actions
|
89
10
|
end
|
90
11
|
end
|
91
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara_active_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Talakevich
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- ".rspec"
|
50
50
|
- ".rubocop.yml"
|
51
51
|
- ".travis.yml"
|
52
|
+
- CHANGELOG.md
|
52
53
|
- CODE_OF_CONDUCT.md
|
53
54
|
- Gemfile
|
54
55
|
- LICENSE.txt
|
@@ -58,7 +59,27 @@ files:
|
|
58
59
|
- bin/setup
|
59
60
|
- capybara_active_admin.gemspec
|
60
61
|
- lib/capybara/active_admin.rb
|
62
|
+
- lib/capybara/active_admin/actions.rb
|
63
|
+
- lib/capybara/active_admin/actions/attributes_table.rb
|
64
|
+
- lib/capybara/active_admin/actions/form.rb
|
65
|
+
- lib/capybara/active_admin/actions/layout.rb
|
66
|
+
- lib/capybara/active_admin/actions/table.rb
|
67
|
+
- lib/capybara/active_admin/finders.rb
|
68
|
+
- lib/capybara/active_admin/finders/attributes_table.rb
|
69
|
+
- lib/capybara/active_admin/finders/form.rb
|
70
|
+
- lib/capybara/active_admin/finders/layout.rb
|
71
|
+
- lib/capybara/active_admin/finders/table.rb
|
72
|
+
- lib/capybara/active_admin/matchers.rb
|
73
|
+
- lib/capybara/active_admin/matchers/attributes_table.rb
|
74
|
+
- lib/capybara/active_admin/matchers/form.rb
|
75
|
+
- lib/capybara/active_admin/matchers/layout.rb
|
76
|
+
- lib/capybara/active_admin/matchers/table.rb
|
61
77
|
- lib/capybara/active_admin/rspec.rb
|
78
|
+
- lib/capybara/active_admin/selectors.rb
|
79
|
+
- lib/capybara/active_admin/selectors/attributes_table.rb
|
80
|
+
- lib/capybara/active_admin/selectors/form.rb
|
81
|
+
- lib/capybara/active_admin/selectors/layout.rb
|
82
|
+
- lib/capybara/active_admin/selectors/table.rb
|
62
83
|
- lib/capybara/active_admin/test_helpers.rb
|
63
84
|
- lib/capybara/active_admin/version.rb
|
64
85
|
- lib/capybara_active_admin.rb
|
@@ -68,7 +89,7 @@ licenses:
|
|
68
89
|
metadata:
|
69
90
|
homepage_uri: https://github.com/active_admin_plugins/capybara_active_admin
|
70
91
|
source_code_uri: https://github.com/active_admin_plugins/capybara_active_admin
|
71
|
-
changelog_uri: https://github.com/active_admin_plugins/capybara_active_admin
|
92
|
+
changelog_uri: https://github.com/active_admin_plugins/capybara_active_admin/blob/master/CHANGELOG.md
|
72
93
|
post_install_message:
|
73
94
|
rdoc_options: []
|
74
95
|
require_paths:
|