capybara_active_admin 0.3.2 → 1.0.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.
@@ -7,36 +7,68 @@ module Capybara
7
7
  module Layout
8
8
  def have_action_item(text, options = {})
9
9
  opts = Util.options_with_text(text, options)
10
- have_selector(action_item_selector, opts)
10
+ have_selector(action_item_selector, **opts)
11
11
  end
12
12
 
13
13
  def have_page_title(text, options = {})
14
14
  opts = Util.options_with_text(text, options)
15
- have_selector(page_title_selector, opts)
15
+ have_selector(page_title_selector, **opts)
16
16
  end
17
17
 
18
18
  def have_flash_message(text, options = {})
19
19
  type = options.delete(:type)
20
20
  opts = Util.options_with_text(text, options)
21
21
  selector = flash_message_selector(type)
22
- have_selector(selector, opts)
22
+ have_selector(selector, **opts)
23
23
  end
24
24
 
25
25
  def have_footer(options = {})
26
26
  selector = footer_selector
27
- have_selector(selector, options)
27
+ have_selector(selector, **options)
28
28
  end
29
29
 
30
30
  def have_panel(title, options = {})
31
31
  title_selector = "#{panel_selector} > #{panel_title_selector}"
32
32
  opts = Util.options_with_text(title, options)
33
- have_selector(title_selector, opts)
33
+ have_selector(title_selector, **opts)
34
34
  end
35
35
 
36
36
  def have_sidebar(title, options = {})
37
37
  title_selector = "#{sidebar_selector} #{panel_selector} > #{panel_title_selector}"
38
38
  opts = Util.options_with_text(title, options)
39
- have_selector(title_selector, opts)
39
+ have_selector(title_selector, **opts)
40
+ end
41
+
42
+ def have_batch_action(title, exact: true)
43
+ selector = "#{dropdown_list_selector} #{batch_action_selector}"
44
+ opts = Util.options_with_text(title, exact: exact)
45
+ have_selector(selector, **opts)
46
+ end
47
+
48
+ # @param title [String] action item link text.
49
+ # @param exact [Boolean] whether to match the title exactly (default true).
50
+ # @param href [String, nil] expected href attribute of the link.
51
+ # @param options [Hash] additional options passed to have_selector.
52
+ # @example
53
+ # expect(page).to have_action_item_link('New User')
54
+ # expect(page).to have_action_item_link('New User', href: new_admin_user_path)
55
+ #
56
+ def have_action_item_link(title, exact: true, href: nil, **options)
57
+ opts = exact ? { exact_text: title } : { text: title }
58
+ opts.merge!(options)
59
+ selector = "#{action_item_selector} > a"
60
+ selector += "[href=\"#{href}\"]" if href.present?
61
+ have_selector(selector, **opts)
62
+ end
63
+
64
+ # @param type [String, Symbol] status tag type (e.g. :yes, :no, :warning).
65
+ # @param options [Hash] additional options passed to have_selector (e.g. exact_text:).
66
+ # @example
67
+ # expect(page).to have_status_tag(:yes)
68
+ # expect(page).to have_status_tag(:error, exact_text: 'DOWN')
69
+ #
70
+ def have_status_tag(type, **options)
71
+ have_selector("span.status_tag.#{type}", **options)
40
72
  end
41
73
  end
42
74
  end
@@ -14,7 +14,7 @@ module Capybara
14
14
  def have_table(options = {})
15
15
  resource_name = options.delete(:resource_name)
16
16
  selector = table_selector(resource_name)
17
- have_selector(selector, options)
17
+ have_selector(selector, **options)
18
18
  end
19
19
 
20
20
  # @param options [Hash]
@@ -30,7 +30,7 @@ module Capybara
30
30
  def have_table_row(options = {})
31
31
  row_id = options.delete(:id)
32
32
  selector = table_row_selector(row_id)
33
- have_selector(selector, options)
33
+ have_selector(selector, **options)
34
34
  end
35
35
 
36
36
  # @param options [Hash]
@@ -51,7 +51,43 @@ module Capybara
51
51
  column = options.delete(:column)
52
52
  selector = table_cell_selector(column)
53
53
 
54
- have_selector(selector, options)
54
+ have_selector(selector, **options)
55
+ end
56
+
57
+ # @param options [Hash]
58
+ # @option count [Integer] qty of nodes
59
+ def have_table_scopes(options = {})
60
+ have_selector("#{table_scopes_container_selector} > #{table_scope_selector}", **options)
61
+ end
62
+
63
+ # @param title [String, nil] exact title of scope to match.
64
+ # @param selected [Boolean] whether to match selected (active) scope only (default false).
65
+ # @param options [Hash] additional options passed to have_selector.
66
+ def have_table_scope(title = nil, selected: false, **options)
67
+ selector = "#{table_scopes_container_selector} > #{table_scope_selector}"
68
+ if title.nil?
69
+ selector = selected ? "#{selector}.selected" : "#{selector}:not(.selected)"
70
+ have_selector(selector, **options)
71
+ else
72
+ selector = selected ? "#{selector}.selected" : selector
73
+ have_selector(selector, exact_text: title.to_s, **options)
74
+ end
75
+ end
76
+
77
+ # @param text [String] column header text.
78
+ # @param options [Hash]
79
+ # @option column [String, nil] column name override (defaults to text).
80
+ # @option sortable [Boolean] whether the column is sortable.
81
+ # @option sort_direction [String, nil] sort direction ('asc' or 'desc').
82
+ # @example
83
+ # expect(page).to have_table_header('Full Name')
84
+ # expect(page).to have_table_header('Full Name', sortable: true)
85
+ # expect(page).to have_table_header('Full Name', sort_direction: :asc)
86
+ #
87
+ def have_table_header(text, options = {})
88
+ selector = table_header_selector(text, options)
89
+ opts = options.except(:column, :sortable, :sort_direction).merge(exact_text: text)
90
+ have_selector(selector, **opts)
55
91
  end
56
92
  end
57
93
  end
@@ -18,7 +18,7 @@ module Capybara
18
18
  def attributes_row_selector(label = nil)
19
19
  return 'tr.row > td' if label.nil?
20
20
 
21
- label = label.to_s.gsub(' ', '_').downcase
21
+ label = label.to_s.gsub(/[\s\/]/, '_').downcase
22
22
  "tr.row.row-#{label} > td"
23
23
  end
24
24
  end
@@ -35,6 +35,12 @@ module Capybara
35
35
  "div.has_many_container.#{association_name} > fieldset.inputs.has_many_fields"
36
36
  end
37
37
 
38
+ # @param association_name [String]
39
+ # @return [String] .has_many_container selector.
40
+ def has_many_container_selector(association_name)
41
+ ".has_many_container.#{association_name}"
42
+ end
43
+
38
44
  # @param text [String, nil] submit button text.
39
45
  # @return [String] selector.
40
46
  def form_submit_selector(text = nil)
@@ -50,7 +56,7 @@ module Capybara
50
56
  return 'li' if label.nil?
51
57
 
52
58
  label_opts = Util.options_with_text(label, exact: exact)
53
- label_node = find(label_selector, label_opts)
59
+ label_node = find(label_selector, **label_opts)
54
60
  li_id = label_node.ancestor('li')[:id]
55
61
  "li##{li_id}"
56
62
  end
@@ -73,8 +73,8 @@ module Capybara
73
73
  end
74
74
 
75
75
  # @return [String] selector.
76
- def batch_action_selector(title)
77
- "li a[data-action='#{title}']"
76
+ def batch_action_selector
77
+ 'li a[data-action]'
78
78
  end
79
79
 
80
80
  # @return [String] selector.
@@ -22,9 +22,20 @@ module Capybara
22
22
  %(tbody > tr[id$="_#{record_id}"])
23
23
  end
24
24
 
25
+ # @param text [String] column header text.
26
+ # @param options [Hash]
27
+ # @option column [String, nil] column name override (defaults to text).
28
+ # @option sortable [Boolean] whether column is sortable.
29
+ # @option sort_direction [String, nil] sort direction ('asc' or 'desc').
25
30
  # @return selector.
26
- def table_header_selector
27
- 'thead > tr > th.col'
31
+ def table_header_selector(text = nil, options = {})
32
+ return 'thead > tr > th.col' if text.nil?
33
+
34
+ column = (options[:column] || text).to_s.tr(' ', '_').downcase
35
+ selector = "th.col.col-#{column}"
36
+ selector += '.sortable' if options[:sortable]
37
+ selector += ".sorted-#{options[:sort_direction].to_s.downcase}" if options[:sort_direction].present?
38
+ "thead > tr > #{selector}"
28
39
  end
29
40
 
30
41
  # @param column [String, nil] column name.
@@ -32,9 +43,18 @@ module Capybara
32
43
  def table_cell_selector(column = nil)
33
44
  return 'td.col' if column.nil?
34
45
 
35
- column = column.to_s.gsub(' ', '_').downcase
46
+ # Downcase, strip non-alphanumeric chars (e.g. '/'), convert spaces to '_', deduplicate '_'
47
+ column = column.to_s.downcase.gsub(/[^a-z0-9\s]/, '').gsub(/\s+/, '_').squeeze('_')
36
48
  "td.col.col-#{column}"
37
49
  end
50
+
51
+ def table_scopes_container_selector
52
+ '.scopes > ul.table_tools_segmented_control'
53
+ end
54
+
55
+ def table_scope_selector
56
+ 'li.scope'
57
+ end
38
58
  end
39
59
  end
40
60
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module ActiveAdmin
5
- VERSION = '0.3.2'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara_active_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2020-04-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activeadmin
@@ -16,14 +15,20 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: '3.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: '0'
28
+ version: '3.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '4.0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: rspec
29
34
  requirement: !ruby/object:Gem::Requirement
@@ -45,10 +50,11 @@ executables: []
45
50
  extensions: []
46
51
  extra_rdoc_files: []
47
52
  files:
53
+ - ".github/workflows/ci.yml"
54
+ - ".github/workflows/codeql.yml"
48
55
  - ".gitignore"
49
56
  - ".rspec"
50
57
  - ".rubocop.yml"
51
- - ".travis.yml"
52
58
  - CHANGELOG.md
53
59
  - CODE_OF_CONDUCT.md
54
60
  - Gemfile
@@ -58,8 +64,8 @@ files:
58
64
  - bin/console
59
65
  - bin/setup
60
66
  - capybara_active_admin.gemspec
61
- - deploy.sh
62
67
  - docs/.vuepress/config.js
68
+ - docs/.vuepress/public/.keep
63
69
  - docs/.vuepress/styles/index.styl
64
70
  - docs/README.md
65
71
  - docs/guide/README.md
@@ -90,7 +96,6 @@ files:
90
96
  - lib/capybara/active_admin/version.rb
91
97
  - lib/capybara_active_admin.rb
92
98
  - package.json
93
- - yarn.lock
94
99
  homepage: https://github.com/active_admin_plugins/capybara_active_admin
95
100
  licenses:
96
101
  - MIT
@@ -98,7 +103,6 @@ metadata:
98
103
  homepage_uri: https://github.com/active_admin_plugins/capybara_active_admin
99
104
  source_code_uri: https://github.com/active_admin_plugins/capybara_active_admin
100
105
  changelog_uri: https://github.com/active_admin_plugins/capybara_active_admin/blob/master/CHANGELOG.md
101
- post_install_message:
102
106
  rdoc_options: []
103
107
  require_paths:
104
108
  - lib
@@ -106,15 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
110
  requirements:
107
111
  - - ">="
108
112
  - !ruby/object:Gem::Version
109
- version: 2.3.0
113
+ version: 3.3.0
110
114
  required_rubygems_version: !ruby/object:Gem::Requirement
111
115
  requirements:
112
116
  - - ">="
113
117
  - !ruby/object:Gem::Version
114
118
  version: '0'
115
119
  requirements: []
116
- rubygems_version: 3.1.2
117
- signing_key:
120
+ rubygems_version: 3.6.9
118
121
  specification_version: 4
119
122
  summary: Capybara DSL for fast and easy testing Active Admin applications.
120
123
  test_files: []
data/.travis.yml DELETED
@@ -1,44 +0,0 @@
1
- ---
2
- # test config on https://config.travis-ci.com/explore
3
- language: ruby
4
- cache: bundler
5
- before_install:
6
- - gem install bundler -v 2.1.4
7
- stages:
8
- - test
9
- - deploy
10
- jobs:
11
- include:
12
- - name: "Test Ruby-2.5.7 Rails-6.0"
13
- stage: test
14
- rvm: 2.5.7
15
- env: RAILS_VERSION="~> 6.0"
16
- before_script: bundle install
17
- script: bundle exec rake default
18
- - name: "Test Ruby-2.5.7 Rails-5.2"
19
- stage: test
20
- rvm: 2.5.7
21
- env: RAILS_VERSION="~> 5.2"
22
- before_script: bundle install
23
- script: bundle exec rake default
24
- - name: "Test Ruby-2.3.8 Rails-5.2"
25
- stage: test
26
- rvm: 2.3.8
27
- env: RAILS_VERSION="~> 5.2"
28
- before_script: bundle install
29
- script: bundle exec rake default
30
- - name: "Deploy documentation"
31
- stage: deploy
32
- install: skip
33
- before_script: yarn install
34
- script: yarn docs:build
35
- deploy:
36
- provider: pages
37
- edge: true
38
- verbose: true
39
- cleanup: false
40
- local_dir: docs/.vuepress/dist
41
- token: $GITHUB_TOKEN
42
- keep_history: true
43
- on:
44
- branch: master
data/deploy.sh DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env sh
2
-
3
- # abort on errors
4
- set -e
5
-
6
- # build
7
- npm run docs:build
8
-
9
- # navigate into the build output directory
10
- cd docs/.vuepress/dist
11
-
12
- git init
13
- git add -A
14
- git commit -m 'deploy'
15
-
16
- # deploying to https://activeadmin-plugins.github.io/capybara_active_admin
17
- git push -f git@github.com:activeadmin-plugins/capybara_active_admin.git master:gh-pages
18
-
19
- cd -