capybara_active_admin 0.3.3 → 2.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.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'capybara/active_admin/util'
4
+
3
5
  module Capybara
4
6
  module ActiveAdmin
5
7
  module Selectors
@@ -10,8 +12,12 @@ module Capybara
10
12
  def table_selector(resource_name = nil)
11
13
  return 'table.index_table' if resource_name.nil?
12
14
 
13
- resource_name = resource_name.to_s.gsub(' ', '_').pluralize.downcase
14
- "table#index_table_#{resource_name}"
15
+ # NOTE: ActiveAdmin builds this id from the registered resource name
16
+ # (`active_admin_config.resource_name.plural`, index_as_table.rb:240),
17
+ # which `register Model, as: 'Other Name'` detaches from the model.
18
+ # A class can only ever yield the model's own name, so a renamed
19
+ # resource has to be addressed by the name it was registered under.
20
+ "table#index_table_#{Util.parse_model_name(resource_name, singular: false)}"
15
21
  end
16
22
 
17
23
  # @param record_id [String, Integer, nil] record ID.
@@ -22,9 +28,20 @@ module Capybara
22
28
  %(tbody > tr[id$="_#{record_id}"])
23
29
  end
24
30
 
31
+ # @param text [String] column header text.
32
+ # @param options [Hash]
33
+ # @option column [String, nil] column name override (defaults to text).
34
+ # @option sortable [Boolean] whether column is sortable.
35
+ # @option sort_direction [String, nil] sort direction ('asc' or 'desc').
25
36
  # @return selector.
26
- def table_header_selector
27
- 'thead > tr > th.col'
37
+ def table_header_selector(text = nil, options = {})
38
+ return 'thead > tr > th.col' if text.nil? && options[:column].nil?
39
+
40
+ column = Util.css_class_for_label(options[:column] || text)
41
+ selector = "th.col.col-#{column}"
42
+ selector += '.sortable' if options[:sortable]
43
+ selector += ".sorted-#{options[:sort_direction].to_s.downcase}" if options[:sort_direction].present?
44
+ "thead > tr > #{selector}"
28
45
  end
29
46
 
30
47
  # @param column [String, nil] column name.
@@ -32,9 +49,17 @@ module Capybara
32
49
  def table_cell_selector(column = nil)
33
50
  return 'td.col' if column.nil?
34
51
 
35
- column = column.to_s.gsub(' ', '_').downcase
52
+ column = Util.css_class_for_label(column)
36
53
  "td.col.col-#{column}"
37
54
  end
55
+
56
+ def table_scopes_container_selector
57
+ '.scopes > ul.table_tools_segmented_control'
58
+ end
59
+
60
+ def table_scope_selector
61
+ 'li.scope'
62
+ end
38
63
  end
39
64
  end
40
65
  end
@@ -5,12 +5,49 @@ module Capybara
5
5
  module Util
6
6
  # Common pure utility functions
7
7
 
8
+ # Arbre derives a record's DOM name from
9
+ # `record.class.model_name.singular`, falling back to
10
+ # `name.underscore.gsub('/', '_')` (arbre html/tag.rb:164-168). Ask the
11
+ # model the same question instead of approximating it: `gsub(' ', '_')`
12
+ # leaves the `::` of a namespaced name in place, and
13
+ # `div.attributes_table.billing::employee` is not a selector -- Nokogiri
14
+ # raises `SyntaxError` on it with nothing pointing at the cause.
8
15
  def parse_model_name(model_name, singular: true)
9
16
  return if model_name.nil?
10
17
 
11
- model_name = model_name.model_name.singular if model_name.is_a?(Class)
12
- model_name = model_name.to_s.gsub(' ', '_').downcase
13
- singular ? model_name.singularize : model_name.pluralize
18
+ if model_name.is_a?(Class) && model_name.respond_to?(:model_name)
19
+ name = model_name.model_name
20
+ return singular ? name.singular : name.plural
21
+ end
22
+
23
+ dom_model_name(model_name.is_a?(Class) ? model_name.name : model_name, singular: singular)
24
+ end
25
+
26
+ def dom_model_name(name, singular: true)
27
+ name = name.to_s.underscore.tr('/', '_').tr(' ', '_')
28
+ singular ? name.singularize : name.pluralize
29
+ end
30
+
31
+ # ActiveAdmin derives the CSS class of a row or column from the
32
+ # label with `parameterize(separator: '_')` --
33
+ # `AttributesTable#row` and `TableFor::Column#html_class`. Mirror
34
+ # that call rather than approximating it, so every label lands on
35
+ # the class ActiveAdmin actually rendered.
36
+ def css_class_for_label(label)
37
+ css_class = label.to_s.parameterize(separator: '_')
38
+ return css_class if css_class.present?
39
+
40
+ # `parameterize` transliterates to Latin and drops the rest, so any
41
+ # label without Latin-transliterable characters -- 'Имя', '名前', '№',
42
+ # or a blank string -- comes back empty. ActiveAdmin makes the same
43
+ # call, so it renders `class="row row-"` for all of them, and a
44
+ # `.row-` selector would match every one at once: the matcher would
45
+ # pass against the wrong row instead of failing. Refuse to build it.
46
+ raise ArgumentError,
47
+ "cannot derive a CSS class from #{label.inspect}: " \
48
+ 'ActiveAdmin parameterizes it to an empty string, so every such ' \
49
+ 'row or column shares one class and cannot be told apart. ' \
50
+ 'Match on text, or pass the attribute name instead of the label.'
14
51
  end
15
52
 
16
53
  def options_with_text(text, options = {})
@@ -19,7 +56,7 @@ module Capybara
19
56
  options.except(:exact).merge(key => text)
20
57
  end
21
58
 
22
- module_function :parse_model_name, :options_with_text
59
+ module_function :parse_model_name, :dom_model_name, :css_class_for_label, :options_with_text
23
60
  end
24
61
  end
25
62
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module ActiveAdmin
5
- VERSION = '0.3.3'
5
+ VERSION = '2.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.3
4
+ version: 2.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-17 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,24 +50,9 @@ executables: []
45
50
  extensions: []
46
51
  extra_rdoc_files: []
47
52
  files:
48
- - ".gitignore"
49
- - ".rspec"
50
- - ".rubocop.yml"
51
- - ".travis.yml"
52
53
  - CHANGELOG.md
53
- - CODE_OF_CONDUCT.md
54
- - Gemfile
55
54
  - LICENSE.txt
56
55
  - README.md
57
- - Rakefile
58
- - bin/console
59
- - bin/setup
60
- - capybara_active_admin.gemspec
61
- - docs/.vuepress/config.js
62
- - docs/.vuepress/public/.keep
63
- - docs/.vuepress/styles/index.styl
64
- - docs/README.md
65
- - docs/guide/README.md
66
56
  - lib/capybara/active_admin.rb
67
57
  - lib/capybara/active_admin/actions.rb
68
58
  - lib/capybara/active_admin/actions/attributes_table.rb
@@ -89,8 +79,6 @@ files:
89
79
  - lib/capybara/active_admin/util.rb
90
80
  - lib/capybara/active_admin/version.rb
91
81
  - lib/capybara_active_admin.rb
92
- - package.json
93
- - yarn.lock
94
82
  homepage: https://github.com/active_admin_plugins/capybara_active_admin
95
83
  licenses:
96
84
  - MIT
@@ -98,7 +86,6 @@ metadata:
98
86
  homepage_uri: https://github.com/active_admin_plugins/capybara_active_admin
99
87
  source_code_uri: https://github.com/active_admin_plugins/capybara_active_admin
100
88
  changelog_uri: https://github.com/active_admin_plugins/capybara_active_admin/blob/master/CHANGELOG.md
101
- post_install_message:
102
89
  rdoc_options: []
103
90
  require_paths:
104
91
  - lib
@@ -106,15 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
93
  requirements:
107
94
  - - ">="
108
95
  - !ruby/object:Gem::Version
109
- version: 2.3.0
96
+ version: 3.3.0
110
97
  required_rubygems_version: !ruby/object:Gem::Requirement
111
98
  requirements:
112
99
  - - ">="
113
100
  - !ruby/object:Gem::Version
114
101
  version: '0'
115
102
  requirements: []
116
- rubygems_version: 3.1.2
117
- signing_key:
103
+ rubygems_version: 3.6.9
118
104
  specification_version: 4
119
105
  summary: Capybara DSL for fast and easy testing Active Admin applications.
120
106
  test_files: []
data/.gitignore DELETED
@@ -1,20 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /spec/dummy/tmp/
10
- /spec/dummy/log/*.log
11
-
12
- # rspec failure tracking
13
- .rspec_status
14
-
15
- Gemfile.lock
16
-
17
- # docs
18
- /docs/.vuepress/dist/
19
- /docs/.vuepress/public/api/
20
- /node_modules/
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require rails_helper
data/.rubocop.yml DELETED
@@ -1,82 +0,0 @@
1
- AllCops:
2
- DisplayCopNames: true
3
- TargetRubyVersion: 2.3
4
- Exclude:
5
- - vendor/**/*
6
- - tmp/**/*
7
- - docs/**/*
8
-
9
- # Capybara/RSpec uses have_ had_ as name convention for matchers.
10
- Naming/PredicateName:
11
- Enabled: false
12
-
13
- Lint/RaiseException:
14
- Enabled: true
15
-
16
- Lint/StructNewOverride:
17
- Enabled: true
18
-
19
- Layout/LineLength:
20
- Max: 180
21
-
22
- Style/SymbolArray:
23
- EnforcedStyle: brackets
24
-
25
- Style/Lambda:
26
- EnforcedStyle: literal
27
-
28
- Naming/MethodParameterName:
29
- AllowedNames:
30
- - id
31
-
32
- Style/HashEachMethods:
33
- Enabled: true
34
-
35
- Style/HashTransformKeys:
36
- Enabled: true
37
-
38
- Style/HashTransformValues:
39
- Enabled: true
40
-
41
- Style/Documentation:
42
- Enabled: false
43
-
44
- Metrics/PerceivedComplexity:
45
- Enabled: false
46
-
47
- Metrics/MethodLength:
48
- Enabled: false
49
-
50
- Metrics/AbcSize:
51
- Enabled: false
52
-
53
- Metrics/ModuleLength:
54
- Enabled: false
55
-
56
- Metrics/BlockLength:
57
- Enabled: false
58
-
59
- Metrics/ClassLength:
60
- Enabled: false
61
-
62
- Metrics/CyclomaticComplexity:
63
- Enabled: false
64
-
65
- Layout/MultilineOperationIndentation:
66
- Enabled: false
67
-
68
- Layout/FirstHashElementIndentation:
69
- Enabled: false
70
-
71
- Layout/FirstArrayElementIndentation:
72
- Enabled: false
73
-
74
- Layout/FirstArgumentIndentation:
75
- Enabled: false
76
-
77
- Layout/ClosingParenthesisIndentation:
78
- Enabled: false
79
-
80
- Layout/ArgumentAlignment:
81
- Enabled: false
82
-
data/.travis.yml DELETED
@@ -1,45 +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
- before_script: yarn install
33
- script:
34
- - bundle exec rake yard
35
- - yarn docs:build
36
- deploy:
37
- provider: pages
38
- edge: true
39
- verbose: true
40
- cleanup: false
41
- local_dir: docs/.vuepress/dist
42
- token: $GITHUB_TOKEN
43
- keep_history: true
44
- on:
45
- branch: master
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at senid231@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in capybara_active_admin.gemspec
6
- gemspec
7
-
8
- gem 'capybara'
9
- gem 'selenium-webdriver'
10
- # https://github.com/mattheworiordan/capybara-screenshot/issues/225#issuecomment-409407825
11
- gem 'cuprite'
12
- gem 'puma'
13
- gem 'rake', '~> 12.0'
14
- gem 'rspec-rails', '~> 4.0'
15
- gem 'rubocop', '~> 0.81.0', require: false
16
- gem 'system_test_html_screenshots', require: false
17
- gem 'yard', require: false
18
-
19
- gem 'activeadmin', ENV.fetch('ACTIVE_ADMIN_VERSION', '~> 2.0'), require: false
20
- gem 'rails', ENV.fetch('RAILS_VERSION', '6.0.0')
21
- gem 'sassc-rails', '2.1.2'
22
- gem 'sprockets', '3.7.2'
23
- gem 'sqlite3', '1.4.1'
data/Rakefile DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
- require 'rubocop/rake_task'
6
- require 'yard'
7
- require 'yard/rake/yardoc_task'
8
-
9
- RSpec::Core::RakeTask.new(:spec)
10
- RuboCop::RakeTask.new(:rubocop)
11
- YARD::Rake::YardocTask.new(:yard) do |task|
12
- task.options += [
13
- %(--output-dir=./docs/.vuepress/public/api/),
14
- %(--title=Capybara Active Admin API Reference)
15
- ]
16
- end
17
-
18
- task default: [:rubocop, :spec]
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'capybara_active_admin'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/capybara/active_admin/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'capybara_active_admin'
7
- spec.version = Capybara::ActiveAdmin::VERSION
8
- spec.authors = ['Denis Talakevich']
9
- spec.email = ['senid231@gmail.com']
10
-
11
- spec.summary = 'Capybara DSL for fast and easy testing Active Admin applications.'
12
- spec.description = 'Capybara DSL for fast and easy testing Active Admin applications.'
13
- spec.homepage = 'https://github.com/active_admin_plugins/capybara_active_admin'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
-
17
- spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = spec.homepage
19
- spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
26
- spec.bindir = 'exe'
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ['lib']
29
-
30
- spec.add_dependency 'activeadmin'
31
- # spec.add_dependency 'devise'
32
- spec.add_dependency 'rspec', '~> 3.0'
33
- end
@@ -1,12 +0,0 @@
1
- module.exports = {
2
- title: 'Capybara Active Admin',
3
- description: 'Capybara DSL for fast and easy testing Active Admin applications.',
4
- base: '/capybara_active_admin/',
5
- themeConfig: {
6
- nav: [
7
- { text: 'Guide', link: '/guide/' },
8
- { text: 'API Reference', link: '/api/', target: '_blank' },
9
- { text: 'GitHub', link: 'https://github.com/activeadmin-plugins/capybara_active_admin' }
10
- ]
11
- }
12
- }
File without changes
@@ -1,3 +0,0 @@
1
- div.theme-default-content:not(.custom) {
2
- max-width: 75%;
3
- }
data/docs/README.md DELETED
@@ -1,41 +0,0 @@
1
- ---
2
- home: true
3
- actionText: Get Started →
4
- actionLink: /guide/
5
- footer: MIT Licensed | Copyright © 2020-present Denis Talakevich
6
- ---
7
-
8
- <div style="text-align: center">
9
- <Bit/>
10
- </div>
11
-
12
- <div class="features">
13
- <div class="feature">
14
- <h2>Fast Test Writing</h2>
15
- <p>Allow to focus on what you want to test instead of how to do it.</p>
16
- </div>
17
- <div class="feature">
18
- <h2>Simplicity</h2>
19
- <p>Following Ruby an Capybara naming conventions allows easily to read and understand tests code.</p>
20
- </div>
21
- <div class="feature">
22
- <h2>Customizable</h2>
23
- <p>You can easy extend, customize, and mix parts of library to fit your needs.</p>
24
- </div>
25
- </div>
26
-
27
- ### As Easy as 1, 2, 3
28
-
29
- ```bash
30
- # install
31
- gem install capybara_active_admin
32
- # OR echo "gem 'capybara_active_admin', group: :test, require: false" >> Gemfile
33
- ```
34
- ```ruby
35
- # require in in rspec/rails_helper.rb
36
- require 'capybara/active_admin/rspec'
37
- ```
38
-
39
- ::: warning COMPATIBILITY NOTE
40
- requires Ruby >= 2.3.
41
- :::