potassium 6.1.0 → 6.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +103 -38
- data/.circleci/setup-rubygems.sh +3 -0
- data/.gitignore +2 -1
- data/.node-version +1 -1
- data/.rubocop.yml +530 -0
- data/CHANGELOG.md +50 -1
- data/README.md +11 -3
- data/lib/potassium/assets/.circleci/config.yml.erb +107 -40
- data/lib/potassium/assets/.pryrc +0 -6
- data/lib/potassium/assets/.rubocop.yml +13 -0
- data/lib/potassium/assets/README.yml +45 -8
- data/lib/potassium/assets/active_admin/policies/admin_user_policy.rb +2 -0
- data/lib/potassium/assets/active_admin/policies/comment_policy.rb +2 -0
- data/lib/potassium/assets/active_admin/policies/default_policy.rb +49 -0
- data/lib/potassium/assets/active_admin/policies/page_policy.rb +2 -0
- data/lib/potassium/assets/app/javascript/app.spec.js +1 -1
- data/lib/potassium/assets/app/views/shared/_gtm_body.html.erb +4 -0
- data/lib/potassium/assets/app/views/shared/_gtm_head.html.erb +7 -0
- data/lib/potassium/assets/testing/.rspec +1 -0
- data/lib/potassium/assets/testing/devise_config.rb +6 -0
- data/lib/potassium/assets/testing/factory_bot_config.rb +3 -0
- data/lib/potassium/assets/testing/faker_config.rb +1 -0
- data/lib/potassium/assets/testing/power_types_config.rb +1 -0
- data/lib/potassium/assets/testing/rails_helper.rb +130 -49
- data/lib/potassium/assets/testing/shoulda_matchers_config.rb +8 -0
- data/lib/potassium/assets/testing/simplecov_config.rb +64 -0
- data/lib/potassium/assets/testing/system_tests_config.rb +6 -0
- data/lib/potassium/cli_options.rb +19 -3
- data/lib/potassium/helpers/template-helpers.rb +4 -0
- data/lib/potassium/recipes/admin.rb +27 -17
- data/lib/potassium/recipes/api.rb +2 -0
- data/lib/potassium/recipes/background_processor.rb +43 -32
- data/lib/potassium/recipes/ci.rb +9 -39
- data/lib/potassium/recipes/coverage.rb +35 -0
- data/lib/potassium/recipes/file_storage.rb +1 -1
- data/lib/potassium/recipes/front_end.rb +26 -13
- data/lib/potassium/recipes/google_tag_manager.rb +94 -0
- data/lib/potassium/recipes/heroku.rb +43 -31
- data/lib/potassium/recipes/mailer.rb +18 -5
- data/lib/potassium/recipes/monitoring.rb +5 -0
- data/lib/potassium/recipes/pundit.rb +29 -10
- data/lib/potassium/recipes/rails.rb +0 -4
- data/lib/potassium/recipes/schedule.rb +16 -1
- data/lib/potassium/recipes/spring.rb +9 -0
- data/lib/potassium/recipes/style.rb +2 -2
- data/lib/potassium/recipes/testing.rb +75 -18
- data/lib/potassium/templates/application.rb +7 -2
- data/lib/potassium/version.rb +7 -4
- data/potassium.gemspec +3 -1
- data/spec/features/background_processor_spec.rb +7 -5
- data/spec/features/ci_spec.rb +7 -4
- data/spec/features/coverage_spec.rb +26 -0
- data/spec/features/front_end_spec.rb +18 -1
- data/spec/features/google_tag_manager_spec.rb +36 -0
- data/spec/features/heroku_spec.rb +0 -4
- data/spec/features/mailer_spec.rb +16 -0
- data/spec/features/node_spec.rb +1 -1
- data/spec/features/pundit_spec.rb +34 -0
- data/spec/features/schedule_spec.rb +11 -4
- data/spec/features/testing_spec.rb +56 -0
- data/spec/support/potassium_test_helpers.rb +2 -3
- data/tmp/.keep +0 -0
- metadata +64 -15
- data/lib/potassium/assets/Dockerfile.ci +0 -6
- data/lib/potassium/assets/active_admin/admin_user_policy.rb +0 -2
- data/lib/potassium/assets/active_admin/comment_policy.rb +0 -2
- data/lib/potassium/assets/active_admin/pundit_page_policy.rb +0 -5
- data/lib/potassium/assets/bin/cibuild.erb +0 -117
- data/lib/potassium/assets/docker-compose.ci.yml +0 -12
- data/lib/potassium/assets/sidekiq_scheduler.yml +0 -9
@@ -1,47 +1,58 @@
|
|
1
|
-
version: 2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
ruby-image: &ruby-image cimg/ruby:<%= ruby_version %>
|
4
|
+
<%- if selected?(:database, :postgresql) -%>
|
5
|
+
postgres-image: &postgres-image postgres:<%= Potassium::POSTGRES_VERSION %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- if selected?(:background_processor) -%>
|
8
|
+
redis-image: &redis-image redis
|
9
|
+
<%- end -%>
|
10
|
+
env-vars: &env-vars
|
11
|
+
BUNDLE_JOBS: 4
|
12
|
+
BUNDLE_PATH: vendor/bundle
|
13
|
+
RAILS_ENV: test
|
14
|
+
|
15
|
+
orbs:
|
16
|
+
browser-tools: circleci/browser-tools@1.1
|
17
|
+
|
18
|
+
executors:
|
19
|
+
test-executor:
|
6
20
|
docker:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
- run: bin/cibuild deps
|
18
|
-
|
19
|
-
- run: bin/cibuild db
|
20
|
-
- run: bin/cibuild tests
|
21
|
-
<% if selected?(:front_end, :vue) %>
|
22
|
-
- run: bin/cibuild js_tests
|
23
|
-
<% end %>
|
24
|
-
|
25
|
-
lint:
|
21
|
+
- image: *ruby-image
|
22
|
+
environment: *env-vars
|
23
|
+
<%- if selected?(:database, :postgresql) -%>
|
24
|
+
- image: *postgres-image
|
25
|
+
<%- end -%>
|
26
|
+
<%- if selected?(:background_processor) -%>
|
27
|
+
- image: *redis-image
|
28
|
+
<%- end -%>
|
29
|
+
|
30
|
+
lint-executor:
|
26
31
|
docker:
|
27
|
-
- image:
|
28
|
-
environment:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
- image: *ruby-image
|
33
|
+
environment: *env-vars
|
34
|
+
|
35
|
+
commands:
|
36
|
+
setup:
|
37
|
+
description: checkout code, restore cache, install dependencies, save cache
|
32
38
|
steps:
|
33
39
|
- checkout
|
34
40
|
|
35
41
|
- restore_cache:
|
36
42
|
keys:
|
37
|
-
- bundle-dependencies-{{ checksum "Gemfile.lock" }}
|
43
|
+
- bundle-dependencies-{{ .Environment.BUNDLE_CACHE_VERSION }}-{{ checksum "Gemfile.lock" }}
|
38
44
|
- bundle-dependencies-
|
39
45
|
|
40
46
|
- restore_cache:
|
41
47
|
keys:
|
42
|
-
- yarn-dependencies-{{ checksum "yarn.lock" }}
|
48
|
+
- yarn-dependencies-{{ .Environment.YARN_CACHE_VERSION }}-{{ checksum "yarn.lock" }}
|
43
49
|
- yarn-dependencies-
|
44
50
|
|
51
|
+
- run:
|
52
|
+
name: Install reviewdog
|
53
|
+
command: |
|
54
|
+
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b ./bin
|
55
|
+
|
45
56
|
- run:
|
46
57
|
name: Install bundle dependencies
|
47
58
|
command: |
|
@@ -49,24 +60,81 @@ jobs:
|
|
49
60
|
gem install bundler:$BUNDLER_VERSION
|
50
61
|
bundle _$(echo $BUNDLER_VERSION)_ install
|
51
62
|
|
63
|
+
- run:
|
64
|
+
name: Install yarn dependencies
|
65
|
+
command: |
|
66
|
+
curl -sL https://deb.nodesource.com/setup_$(cat .node-version).x | sudo -E bash -
|
67
|
+
sudo apt-get install -y nodejs
|
68
|
+
curl -o- -sL https://yarnpkg.com/install.sh | bash
|
69
|
+
sudo ln -s $HOME/.yarn/bin/yarn /usr/local/bin/yarn
|
70
|
+
yarn install --frozen-lockfile
|
71
|
+
|
52
72
|
- save_cache:
|
53
|
-
key: bundle-dependencies-{{ checksum "Gemfile.lock" }}
|
73
|
+
key: bundle-dependencies-{{ .Environment.BUNDLE_CACHE_VERSION }}-{{ checksum "Gemfile.lock" }}
|
54
74
|
paths:
|
55
75
|
- vendor/bundle
|
56
76
|
|
57
|
-
- run:
|
58
|
-
name: Install yarn dependencies
|
59
|
-
command: yarn install --frozen-lockfile
|
60
|
-
|
61
77
|
- save_cache:
|
62
|
-
key: yarn-dependencies-{{ checksum "yarn.lock" }}
|
78
|
+
key: yarn-dependencies-{{ .Environment.YARN_CACHE_VERSION }}-{{ checksum "yarn.lock" }}
|
63
79
|
paths:
|
64
80
|
- node_modules
|
65
81
|
|
82
|
+
jobs:
|
83
|
+
test:
|
84
|
+
executor: test-executor
|
85
|
+
steps:
|
86
|
+
- setup
|
87
|
+
- browser-tools/install-chrome
|
88
|
+
- browser-tools/install-chromedriver
|
89
|
+
|
90
|
+
<%- if selected?(:background_processor) -%>
|
66
91
|
- run:
|
67
|
-
name:
|
92
|
+
name: Wait for redis service
|
93
|
+
command: dockerize -wait tcp://localhost:6379 -timeout 1m
|
94
|
+
<%- end -%>
|
95
|
+
<%- if selected?(:database, :postgresql) -%>
|
96
|
+
- run:
|
97
|
+
name: Wait for postgres service
|
98
|
+
command: dockerize -wait tcp://localhost:5432 -timeout 1m
|
99
|
+
|
100
|
+
- run:
|
101
|
+
name: Setup database
|
102
|
+
command: bundle exec rails db:create db:schema:load
|
103
|
+
<%- end -%>
|
104
|
+
|
105
|
+
- run:
|
106
|
+
name: Run RSpec unit tests
|
68
107
|
command: |
|
69
|
-
|
108
|
+
RSPEC_JUNIT_ARGS="-r rspec_junit_formatter -f RspecJunitFormatter -o test_results/rspec.xml"
|
109
|
+
RSPEC_FORMAT_ARGS="-f progress --no-color -p 10"
|
110
|
+
bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS
|
111
|
+
|
112
|
+
- run:
|
113
|
+
name: Run RSpec system tests
|
114
|
+
command: |
|
115
|
+
RSPEC_JUNIT_ARGS="-r rspec_junit_formatter -f RspecJunitFormatter -o test_results/rspec-system.xml"
|
116
|
+
RSPEC_FORMAT_ARGS="--tag type:system -f progress --no-color -p 10"
|
117
|
+
bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS
|
118
|
+
|
119
|
+
- run:
|
120
|
+
name: Run simplecov
|
121
|
+
shell: /bin/bash
|
122
|
+
command: |
|
123
|
+
cat coverage/coverage.txt | ./bin/reviewdog -reporter=github-pr-review -efm="%f:%l:%c: %m"
|
124
|
+
|
125
|
+
<%- if selected?(:front_end, :vue) -%>
|
126
|
+
- run:
|
127
|
+
name: Run jest
|
128
|
+
command: yarn run test
|
129
|
+
<%- end -%>
|
130
|
+
|
131
|
+
- store_test_results:
|
132
|
+
path: test_results
|
133
|
+
|
134
|
+
lint:
|
135
|
+
executor: lint-executor
|
136
|
+
steps:
|
137
|
+
- setup
|
70
138
|
|
71
139
|
- run:
|
72
140
|
name: Get files to lint
|
@@ -94,7 +162,6 @@ jobs:
|
|
94
162
|
| ./bin/reviewdog -reporter=github-pr-review -f=stylelint
|
95
163
|
|
96
164
|
workflows:
|
97
|
-
version: 2
|
98
165
|
test_and_lint:
|
99
166
|
jobs:
|
100
167
|
- test
|
data/lib/potassium/assets/.pryrc
CHANGED
@@ -4,9 +4,3 @@ if defined?(PryByebug)
|
|
4
4
|
Pry.commands.alias_command 'n', 'next'
|
5
5
|
Pry.commands.alias_command 'f', 'finish'
|
6
6
|
end
|
7
|
-
|
8
|
-
if defined?(Rails)
|
9
|
-
require 'rails/console/app'
|
10
|
-
require 'rails/console/helpers'
|
11
|
-
include Rails::ConsoleMethods # rubocop:disable Style/MixinUsage
|
12
|
-
end
|
@@ -502,6 +502,19 @@ Performance/RedundantBlockCall:
|
|
502
502
|
Description: Use `yield` instead of `block.call`.
|
503
503
|
Reference: https://github.com/JuanitoFatas/fast-ruby#proccall-vs-yield-code
|
504
504
|
Enabled: false
|
505
|
+
Style/OptionalBooleanParameter:
|
506
|
+
Description: 'Use keyword arguments when defining method with boolean argument.'
|
507
|
+
Enabled: false
|
508
|
+
Lint/MissingSuper:
|
509
|
+
Description: >-
|
510
|
+
This cop checks for the presence of constructors and lifecycle callbacks
|
511
|
+
without calls to `super`'.
|
512
|
+
Enabled: false
|
513
|
+
Style/RedundantFileExtensionInRequire:
|
514
|
+
Description: >-
|
515
|
+
Checks for the presence of superfluous `.rb` extension in
|
516
|
+
the filename provided to `require` and `require_relative`.
|
517
|
+
Enabled: false
|
505
518
|
RSpec/MultipleExpectations:
|
506
519
|
Max: 5
|
507
520
|
RSpec/NestedGroups:
|
@@ -42,10 +42,7 @@ readme:
|
|
42
42
|
The project is setup to run tests
|
43
43
|
in [CircleCI](https://circleci.com/gh/platanus/<%= get(:dasherized_app_name) %>/tree/master)
|
44
44
|
|
45
|
-
You can also run the test locally simulating the production environment using
|
46
|
-
Just make sure you have docker installed and run:
|
47
|
-
|
48
|
-
bin/cibuild
|
45
|
+
You can also run the test locally simulating the production environment using [CircleCI's method](https://circleci.com/docs/2.0/local-cli/).
|
49
46
|
deployment:
|
50
47
|
title: "Deployment"
|
51
48
|
body: |
|
@@ -112,9 +109,6 @@ readme:
|
|
112
109
|
pundit:
|
113
110
|
title: "Authorization"
|
114
111
|
body: "For defining which parts of the system each user has access to, we have chosen to include the [Pundit](https://github.com/elabs/pundit) gem, by [Elabs](http://elabs.se/)."
|
115
|
-
delayed_job:
|
116
|
-
title: "Queue System"
|
117
|
-
body: "For managing tasks in the background, this project uses [DelayedJob](https://github.com/collectiveidea/delayed_job)"
|
118
112
|
sidekiq:
|
119
113
|
title: "Queue System"
|
120
114
|
body: "For managing tasks in the background, this project uses [Sidekiq](https://github.com/mperham/sidekiq)"
|
@@ -129,7 +123,7 @@ readme:
|
|
129
123
|
body: "This project uses [Draper](https://github.com/drapergem/draper) to add an object-oriented layer of presentation logic"
|
130
124
|
power_types:
|
131
125
|
title: "Rails pattern enforcing types"
|
132
|
-
body: "This
|
126
|
+
body: "This project uses [Power-Types](https://github.com/platanus/power-types) to generate Services, Commands, Utils and Values."
|
133
127
|
power_api:
|
134
128
|
title: "API Support"
|
135
129
|
body: "This projects uses [Power API](https://github.com/platanus/power_api). It's a Rails engine that gathers a set of gems and configurations designed to build incredible REST APIs."
|
@@ -159,8 +153,51 @@ readme:
|
|
159
153
|
```
|
160
154
|
- You can also use **any** vue bindings such as `v-for` , `:key` etc.
|
161
155
|
<% end %>
|
156
|
+
<% if get(:authorization) %>
|
157
|
+
It uses the [ActiveAdmin's Pundit adapter](https://activeadmin.info/13-authorization-adapter.html).
|
158
|
+
- Policies for admin resources must inherit from `BackOffice::DefaultPolicy` and be placed inside the `app/policies/back_office` directory.
|
159
|
+
- For example:
|
160
|
+
|
161
|
+
`app/admin/clients.rb`:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
ActiveAdmin.register Client do
|
165
|
+
# ...
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
`app/policies/back_office/client_policy.rb`:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
class BackOffice::ClientPolicy < BackOffice::DefaultPolicy
|
173
|
+
end
|
174
|
+
```
|
175
|
+
<% end %>
|
162
176
|
seeds:
|
163
177
|
title: "Seeds"
|
164
178
|
body: |
|
165
179
|
To populate your database with initial data you can add, inside the `/db/seeds.rb` file, the code to generate **only the necessary data** to run the application.
|
166
180
|
If you need to generate data with **development purposes**, you can customize the `lib/fake_data_loader.rb` module and then to run the `rake load_fake_data` task from your terminal.
|
181
|
+
testing:
|
182
|
+
title: "Testing"
|
183
|
+
body: |
|
184
|
+
We use:
|
185
|
+
- [RSpec](https://github.com/rspec/rspec-rails): the testing framework.
|
186
|
+
- [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers): one-liners to test common Rails functionality that, if written by hand, would be much longer, more complex, and error-prone.
|
187
|
+
- [Factory Bot](https://github.com/thoughtbot/factory_bot_rails): a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
|
188
|
+
- [Faker](https://github.com/faker-ruby/faker): a port of Perl's Data::Faker library that generates fake data.
|
189
|
+
- [Guard](https://github.com/guard/guard): automates various tasks by running custom rules whenever file or directories are modified. We use it to run RSpec when files change.
|
190
|
+
|
191
|
+
Place your unit tests inside the `spec` directory.
|
192
|
+
|
193
|
+
To run unit tests: `bin/guard`
|
194
|
+
|
195
|
+
#### System tests
|
196
|
+
|
197
|
+
We use, in addition to the previous gems:
|
198
|
+
- [Capybara](https://github.com/teamcapybara/capybara): helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in. WebKit is supported through an external gem.
|
199
|
+
- [Webdrivers](https://github.com/titusfortner/webdrivers): run Selenium tests more easily with automatic installation and updates for all supported webdrivers.
|
200
|
+
|
201
|
+
Place your system tests inside the `spec/system` directory.
|
202
|
+
|
203
|
+
To run system tests: `bin/rspec --tag type:system`
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class BackOffice::DefaultPolicy
|
2
|
+
attr_reader :admin_user, :record
|
3
|
+
|
4
|
+
def initialize(admin_user, record)
|
5
|
+
@admin_user = admin_user
|
6
|
+
@record = record
|
7
|
+
end
|
8
|
+
|
9
|
+
def index?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def show?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def create?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def new?
|
22
|
+
create?
|
23
|
+
end
|
24
|
+
|
25
|
+
def update?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit?
|
30
|
+
update?
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
class Scope
|
38
|
+
attr_reader :admin_user, :scope
|
39
|
+
|
40
|
+
def initialize(admin_user, scope)
|
41
|
+
@admin_user = admin_user
|
42
|
+
@scope = scope
|
43
|
+
end
|
44
|
+
|
45
|
+
def resolve
|
46
|
+
scope.all
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<!-- Google Tag Manager -->
|
2
|
+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
3
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
4
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
5
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
6
|
+
})(window,document,'script','dataLayer','<%=ENV['GTM_CONTAINER_ID']%>');</script>
|
7
|
+
<!-- End Google Tag Manager -->
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'faker'
|
@@ -0,0 +1 @@
|
|
1
|
+
PowerTypes::Observable.observable_disabled = true
|
@@ -1,60 +1,141 @@
|
|
1
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
1
|
ENV['RACK_ENV'] ||= 'test'
|
3
2
|
require File.expand_path('../config/environment', __dir__)
|
4
3
|
require 'rspec/rails'
|
5
4
|
require 'spec_helper'
|
6
|
-
require 'shoulda/matchers'
|
7
|
-
require 'faker'
|
8
|
-
# Add additional requires below this line. Rails is not loaded until this point!
|
9
|
-
|
10
|
-
# Requires supporting ruby files with custom matchers and macros, etc, in
|
11
|
-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
12
|
-
# run as spec files by default. This means that files in spec/support that end
|
13
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
14
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
15
|
-
# end with _spec.rb. You can configure this pattern with the --pattern
|
16
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
17
|
-
#
|
18
|
-
# The following line is provided for convenience purposes. It has the downside
|
19
|
-
# of increasing the boot-up time by auto-requiring all files in the support
|
20
|
-
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
|
-
# require only the support files necessary.
|
22
|
-
#
|
23
|
-
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
|
24
|
-
|
25
|
-
# Checks for pending migrations before tests are run.
|
26
|
-
# If you are not using ActiveRecord, you can remove this line.
|
27
|
-
ActiveRecord::Migration.maintain_test_schema!
|
28
5
|
|
29
|
-
|
6
|
+
=begin
|
30
7
|
|
31
|
-
|
32
|
-
|
33
|
-
# examples within a transaction, remove the following line or assign false
|
34
|
-
# instead of true.
|
35
|
-
config.use_transactional_fixtures = true
|
8
|
+
General
|
9
|
+
=======
|
36
10
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# You can disable this behaviour by removing the line below, and instead
|
42
|
-
# explicitly tag your specs with their type, e.g.:
|
43
|
-
#
|
44
|
-
# RSpec.describe UsersController, :type => :controller do
|
45
|
-
# # ...
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# The different available types are documented in the features, such as in
|
49
|
-
# https://relishapp.com/rspec/rspec-rails/docs
|
50
|
-
config.infer_spec_type_from_file_location!
|
11
|
+
1) Place your unit tests inside the "spec" directory.
|
12
|
+
2) Run unit tests executing `bin/guard`.
|
13
|
+
3) Use support directories to add helpers and settings.
|
14
|
+
You can only put RSpec configuration on this file.
|
51
15
|
|
52
|
-
|
53
|
-
|
16
|
+
Support
|
17
|
+
-------
|
18
|
+
|
19
|
+
* spec/support/configurations: put testing related gem settings here.
|
20
|
+
|
21
|
+
For example: spec/support/configurations/shoulda_matchers_config.rb
|
22
|
+
|
23
|
+
----------------------------------------
|
24
|
+
require 'shoulda/matchers'
|
25
|
+
|
26
|
+
Shoulda::Matchers.configure do |config|
|
27
|
+
config.integrate do |with|
|
28
|
+
with.test_framework :rspec
|
29
|
+
with.library :rails
|
30
|
+
end
|
31
|
+
end
|
32
|
+
----------------------------------------
|
33
|
+
|
34
|
+
* spec/support/helpers: place here helpers created by you to use in your unit tests.
|
35
|
+
|
36
|
+
For example: spec/support/helpers/attachments_helpers.rb
|
37
|
+
|
38
|
+
----------------------------------------------------------------------------------
|
39
|
+
module AttachmentsHelpers
|
40
|
+
extend ActiveSupport::Concern
|
41
|
+
|
42
|
+
included do
|
43
|
+
def create_attachment_file(filename: "pikachu.png", content_type: "image/png")
|
44
|
+
Rack::Test::UploadedFile.new(file_fixture(filename), content_type)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
RSpec.configure do |config|
|
50
|
+
config.fixture_path = "#{::Rails.root}/spec/assets"
|
51
|
+
config.file_fixture_path = "#{::Rails.root}/spec/assets"
|
52
|
+
|
53
|
+
config.include AttachmentsHelpers
|
54
|
+
end
|
55
|
+
----------------------------------------------------------------------------------
|
56
|
+
|
57
|
+
* spec/support/custom_matchers: place here your custom matchers
|
58
|
+
(https://relishapp.com/rspec/rspec-expectations/v/3-10/docs/custom-matchers)
|
59
|
+
|
60
|
+
* spec/support/shared_examples: place here your shared examples
|
61
|
+
(https://relishapp.com/rspec/rspec-core/v/3-10/docs/example-groups/shared-examples)
|
62
|
+
|
63
|
+
System Tests
|
64
|
+
============
|
65
|
+
|
66
|
+
1) Place your system tests inside the "spec/system" directory.
|
67
|
+
2) Run system tests executing `bin/rspec --tag type:system`.
|
68
|
+
|
69
|
+
Support
|
70
|
+
-------
|
71
|
+
|
72
|
+
* spec/support/configurations/system_tests_config.rb: on this file you will find the
|
73
|
+
general configuration of the system tests. Keep in mind that this type of test will
|
74
|
+
run with the `selenium_chrome_headless` driver unless you put the `no_js` tag.
|
54
75
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
76
|
+
For example: spec/system/login_spec.rb
|
77
|
+
|
78
|
+
----------------------------------------------------------------------------
|
79
|
+
require "rails_helper"
|
80
|
+
|
81
|
+
RSpec.describe "Login" do
|
82
|
+
let!(:user) { create(:user, email: "lean@platan.us") }
|
83
|
+
|
84
|
+
context "without logged user", :no_js do # will use :rack_test driver
|
85
|
+
before { visit("/") }
|
86
|
+
|
87
|
+
it { expect(page).to have_text("Ingresa") }
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with logged user" do # will use :selenium_chrome_headless driver
|
91
|
+
before { sign_in(user) }
|
92
|
+
|
93
|
+
it { expect(page).to have_text("Hola!") }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
----------------------------------------------------------------------------
|
97
|
+
|
98
|
+
* spec/support/helpers/system: place here helpers created by you
|
99
|
+
to use in your system tests.
|
100
|
+
|
101
|
+
For example: spec/support/helpers/login_helpers.rb
|
102
|
+
|
103
|
+
------------------------------------------------
|
104
|
+
module LoginHelpers
|
105
|
+
extend ActiveSupport::Concern
|
106
|
+
|
107
|
+
included do
|
108
|
+
def sign_in(email, password)
|
109
|
+
visit('/users/sign_in')
|
110
|
+
|
111
|
+
within(:xpath, '//*[@id="new_user"]') do
|
112
|
+
fill_in('Email', with: email)
|
113
|
+
fill_in('Contraseña', with: password)
|
114
|
+
end
|
115
|
+
|
116
|
+
click_button('Ingresar')
|
117
|
+
end
|
118
|
+
|
119
|
+
def logout
|
120
|
+
visit('/users/sign_out')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
RSpec.configure do |config|
|
126
|
+
config.include LoginHelpers, type: :system
|
59
127
|
end
|
128
|
+
------------------------------------------------
|
129
|
+
|
130
|
+
Remember to include the system helpers with the tag `type: :system`
|
131
|
+
=end
|
132
|
+
|
133
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
|
134
|
+
|
135
|
+
ActiveRecord::Migration.maintain_test_schema!
|
136
|
+
|
137
|
+
RSpec.configure do |config|
|
138
|
+
config.use_transactional_fixtures = true
|
139
|
+
config.infer_spec_type_from_file_location!
|
140
|
+
config.filter_run_when_matching :focus unless Rails.env.production?
|
60
141
|
end
|