capybara_active_admin 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +37 -5
- data/CHANGELOG.md +5 -0
- data/README.md +3 -1
- data/deploy.sh +19 -0
- data/docs/.vuepress/config.js +11 -0
- data/docs/.vuepress/styles/index.styl +3 -0
- data/docs/README.md +41 -0
- data/docs/guide/README.md +113 -0
- data/lib/capybara/active_admin/actions/layout.rb +1 -0
- data/lib/capybara/active_admin/finders.rb +5 -2
- data/lib/capybara/active_admin/finders/attributes_table.rb +11 -5
- data/lib/capybara/active_admin/finders/form.rb +6 -5
- data/lib/capybara/active_admin/finders/layout.rb +1 -0
- data/lib/capybara/active_admin/finders/table.rb +5 -17
- data/lib/capybara/active_admin/matchers/attributes_table.rb +3 -3
- data/lib/capybara/active_admin/matchers/layout.rb +1 -0
- data/lib/capybara/active_admin/matchers/table.rb +1 -1
- data/lib/capybara/active_admin/selectors/attributes_table.rb +8 -6
- data/lib/capybara/active_admin/selectors/form.rb +24 -8
- data/lib/capybara/active_admin/selectors/layout.rb +16 -0
- data/lib/capybara/active_admin/selectors/table.rb +12 -5
- data/lib/capybara/active_admin/version.rb +1 -1
- data/package.json +9 -0
- data/yarn.lock +7947 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4c255bc74004f32015b353e3e06e0915d8bbc40b3109ad02cbe831eebb8b31f
|
4
|
+
data.tar.gz: c20f9d6fc40394244c59a00ee41db8836286eb96bf766c14a8ac4042d6db868b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bcf06a3023243b731c03b26643e6007ab679830af7cf27db6962b5513ac11125f9a6573f78fa296e2eeced96ea9ebd3f7af20a55de35090e6611e9e91a3a6e1
|
7
|
+
data.tar.gz: e307113050bcee41a41c1d1d4742b3fb5c904ae351977b3964d7c05897837b4a354d12453acacdb5edb29c5895d00f69a9d163f1b2e72248cf1dd81dd2d8a072
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,44 @@
|
|
1
1
|
---
|
2
|
+
# test config on https://config.travis-ci.com/explore
|
2
3
|
language: ruby
|
3
4
|
cache: bundler
|
5
|
+
before_install:
|
6
|
+
- gem install bundler -v 2.1.4
|
7
|
+
stages:
|
8
|
+
- test
|
9
|
+
- deploy
|
4
10
|
jobs:
|
5
11
|
include:
|
6
|
-
-
|
12
|
+
- name: "Test Ruby-2.5.7 Rails-6.0"
|
13
|
+
stage: test
|
14
|
+
rvm: 2.5.7
|
7
15
|
env: RAILS_VERSION="~> 6.0"
|
8
|
-
|
9
|
-
|
10
|
-
-
|
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
|
11
21
|
env: RAILS_VERSION="~> 5.2"
|
12
|
-
|
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/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.3.2] - 2020-04-16
|
10
|
+
### Changed
|
11
|
+
- remove model_name from table related DSL arguments
|
12
|
+
- improve API
|
13
|
+
|
9
14
|
## [0.3.1] - 2020-04-15
|
10
15
|
### Added
|
11
16
|
- `within_attribute_row` finder
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# Capybara Active Admin
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.com/activeadmin-plugins/capybara_active_admin.svg?branch=master)](https://travis-ci.com/activeadmin-plugins/capybara_active_admin)
|
3
|
+
[![Build Status](https://travis-ci.com/activeadmin-plugins/capybara_active_admin.svg?branch=master)](https://travis-ci.com/activeadmin-plugins/capybara_active_admin) [![Gem Version](https://badge.fury.io/rb/capybara_active_admin.svg)](https://badge.fury.io/rb/capybara_active_admin) [![Downloads](https://img.shields.io/gem/dt/capybara_active_admin)](https://rubygems.org/gems/capybara_active_admin) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
|
4
4
|
|
5
5
|
Capybara DSL for fast and easy testing Active Admin applications.
|
6
6
|
|
7
|
+
Check out our docs at [activeadmin-plugins.github.io/capybara_active_admin](https://activeadmin-plugins.github.io/capybara_active_admin)
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
data/deploy.sh
ADDED
@@ -0,0 +1,19 @@
|
|
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 -
|
@@ -0,0 +1,11 @@
|
|
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: 'GitHub', link: 'https://github.com/activeadmin-plugins/capybara_active_admin' }
|
9
|
+
]
|
10
|
+
}
|
11
|
+
}
|
data/docs/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
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
|
+
:::
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
<Bit/>
|
4
|
+
|
5
|
+
`Capybara::ActiveAdmin` created to write tests as fast as `ActiveAdmin` resource which they are test.
|
6
|
+
|
7
|
+
## Getting Started
|
8
|
+
|
9
|
+
### Installation
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# Gemfile
|
13
|
+
|
14
|
+
gem 'capybara_active_admin', group: :test, require: false
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# spec/rails_helper.rb
|
19
|
+
|
20
|
+
# after require 'rspec' or 'rspec/rails'
|
21
|
+
require 'capybara/active_admin/rspec'
|
22
|
+
```
|
23
|
+
|
24
|
+
### Usage
|
25
|
+
|
26
|
+
For example we have such database table
|
27
|
+
```ruby
|
28
|
+
create_table :users do |t|
|
29
|
+
t.string :full_name
|
30
|
+
t.timestamps
|
31
|
+
end
|
32
|
+
```
|
33
|
+
And such `ActiveRecord` model
|
34
|
+
```ruby
|
35
|
+
class User < ActiveRecord::Base
|
36
|
+
validates :full_name, presence: true
|
37
|
+
end
|
38
|
+
```
|
39
|
+
And there is our `ActiveAdmin` resource
|
40
|
+
```ruby
|
41
|
+
ActiveAdmin.register User do
|
42
|
+
permit_params :full_name
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Our test can look like below
|
47
|
+
```ruby
|
48
|
+
# spec/system/users_spec.rb
|
49
|
+
|
50
|
+
RSpec.describe 'Users' do
|
51
|
+
|
52
|
+
describe 'index page' do
|
53
|
+
subject do
|
54
|
+
visit admin_users_path
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'have no table' do
|
58
|
+
subject
|
59
|
+
|
60
|
+
expect(page).to have_text('There are no Users yet.')
|
61
|
+
expect(page).to have_action_item('New User')
|
62
|
+
expect(page).to_not have_action_item('Edit User')
|
63
|
+
expect(page).to_not have_table
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with users' do
|
67
|
+
let!(:users) do
|
68
|
+
[
|
69
|
+
User.create!(full_name: 'John Doe'),
|
70
|
+
User.create!(full_name: 'Jane Air')
|
71
|
+
]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'have correct table rows' do
|
75
|
+
subject
|
76
|
+
|
77
|
+
# you can check that table is visible on page
|
78
|
+
expect(page).to have_table
|
79
|
+
|
80
|
+
# checkout data within table,
|
81
|
+
# same as `within(table_selector) do`
|
82
|
+
within_table_for do
|
83
|
+
# check how many rows in table (tr)
|
84
|
+
expect(page).to have_table_row(count: 2)
|
85
|
+
# or cells (td)
|
86
|
+
expect(page).to have_table_cell(count: 10)
|
87
|
+
# or check cell of specific column contain specific value,
|
88
|
+
# accepts same options as `have_selector`, such as :text, :exact_text, :count, etc.
|
89
|
+
expect(page).to have_table_cell(text: 'John Doe', column: 'Full Name')
|
90
|
+
|
91
|
+
# we can check data inside specific row by record id,
|
92
|
+
# or we can find it by index in table `within_table_row(index: 0) do`.
|
93
|
+
within_table_row(id: users.first.id) do
|
94
|
+
# default columns for users table are id, full_name, created_at, updated_at, actions.
|
95
|
+
expect(page).to have_table_cell(count: 5)
|
96
|
+
expect(page).to have_table_cell(text: 'John Doe')
|
97
|
+
# or you can write
|
98
|
+
expect(page).to have_table_cell(text: 'John Doe', column: 'Full Name')
|
99
|
+
# negate matcher
|
100
|
+
expect(page).to_not have_table_cell(text: 'John Doe', column: 'Id')
|
101
|
+
end
|
102
|
+
|
103
|
+
within_table_row(id: users.second.id) do
|
104
|
+
expect(page).to have_table_cell(text: users.second.id, column: 'Id')
|
105
|
+
expect(page).to have_table_cell(text: 'Jane Air', column: 'Full Name')
|
106
|
+
expect(page).to_not have_table_cell(text: 'John Doe')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
@@ -7,9 +7,12 @@ require 'capybara/active_admin/finders/form'
|
|
7
7
|
|
8
8
|
module Capybara
|
9
9
|
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_*.
|
10
15
|
module Finders
|
11
|
-
# Finders are methods that find node element(s) or change current scope to node element.
|
12
|
-
|
13
16
|
include Finders::Layout
|
14
17
|
include Finders::Table
|
15
18
|
include Finders::AttributesTable
|
@@ -3,15 +3,21 @@
|
|
3
3
|
module Capybara
|
4
4
|
module ActiveAdmin
|
5
5
|
module Finders
|
6
|
+
# Finder methods for ActiveAdmin attributes_table_for can be found here.
|
7
|
+
# @see Capybara::ActiveAdmin::Finders base finders module.
|
6
8
|
module AttributesTable
|
7
|
-
#
|
8
|
-
# @param
|
9
|
-
# @
|
10
|
-
|
11
|
-
|
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)
|
12
15
|
within(selector) { yield }
|
13
16
|
end
|
14
17
|
|
18
|
+
# Calls block within attributes table row.
|
19
|
+
# @param label [String] row label.
|
20
|
+
# @yield within attributes table.
|
15
21
|
def within_attribute_row(label)
|
16
22
|
selector = attributes_row_selector(label)
|
17
23
|
within(selector) { yield }
|
@@ -3,17 +3,17 @@
|
|
3
3
|
module Capybara
|
4
4
|
module ActiveAdmin
|
5
5
|
module Finders
|
6
|
+
# Finders for *active_admin_form_for* and related form components.
|
6
7
|
module Form
|
7
|
-
# @param
|
8
|
+
# @param model_name [Class<Object>, String, nil] form record class or model name (default nil).
|
8
9
|
# @yield within form
|
9
|
-
def within_form_for(
|
10
|
-
|
11
|
-
selector = form_selector(name)
|
10
|
+
def within_form_for(model_name = nil)
|
11
|
+
selector = form_selector(model_name)
|
12
12
|
within(selector) { yield }
|
13
13
|
end
|
14
14
|
|
15
15
|
# @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).
|
17
17
|
# @yield within fieldset>ol
|
18
18
|
def within_form_has_many(association_name, index: 0)
|
19
19
|
selector = has_many_fields_selector(association_name)
|
@@ -22,6 +22,7 @@ module Capybara
|
|
22
22
|
within(fieldset) { yield }
|
23
23
|
end
|
24
24
|
|
25
|
+
# @yield within filters container.
|
25
26
|
def within_filters
|
26
27
|
selector = filter_form_selector
|
27
28
|
within(selector) { yield }
|
@@ -3,26 +3,14 @@
|
|
3
3
|
module Capybara
|
4
4
|
module ActiveAdmin
|
5
5
|
module Finders
|
6
|
+
# Finders for *table_for*, it's rows and cells.
|
6
7
|
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.
|
12
8
|
# @param resource_name [String, nil] resource name of index page.
|
13
9
|
# @yield within table
|
14
|
-
def within_table_for(
|
10
|
+
def within_table_for(resource_name = nil)
|
15
11
|
selector = table_selector(resource_name)
|
16
12
|
|
17
|
-
within(selector)
|
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 }
|
26
14
|
end
|
27
15
|
|
28
16
|
# id [String, Integer, nil] record ID.
|
@@ -38,11 +26,11 @@ module Capybara
|
|
38
26
|
raise ArgumentError, 'must provide :id or :index' if id.nil? && index.nil?
|
39
27
|
|
40
28
|
if id
|
41
|
-
selector = table_row_selector(
|
29
|
+
selector = table_row_selector(id)
|
42
30
|
return find(selector)
|
43
31
|
end
|
44
32
|
|
45
|
-
selector = table_row_selector(nil
|
33
|
+
selector = table_row_selector(nil)
|
46
34
|
find_all(selector, minimum: index + 1)[index]
|
47
35
|
end
|
48
36
|
|
@@ -5,9 +5,9 @@ module Capybara
|
|
5
5
|
module Matchers
|
6
6
|
module AttributesTable
|
7
7
|
def have_attributes_table(options = {})
|
8
|
-
|
9
|
-
|
10
|
-
selector = attributes_table_selector(
|
8
|
+
model = options.delete(:model)
|
9
|
+
id = options.delete(:id)
|
10
|
+
selector = attributes_table_selector(model: model, id: id)
|
11
11
|
have_selector(selector, options)
|
12
12
|
end
|
13
13
|
|