devise-specs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +18 -0
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/README.md +109 -0
- data/Rakefile +5 -0
- data/devise-specs.gemspec +15 -0
- data/lib/devise/specs/railtie.rb +11 -0
- data/lib/devise-specs.rb +1 -0
- data/lib/generators/specs/devise_generator.rb +71 -0
- data/lib/generators/specs/templates/factory_girl.rb.tt +3 -0
- data/lib/generators/specs/templates/helpers.rb.tt +13 -0
- data/lib/generators/specs/templates/resource_resets_password_spec.rb.tt +53 -0
- data/lib/generators/specs/templates/resource_signs_in_spec.rb.tt +27 -0
- data/lib/generators/specs/templates/resource_signs_out_spec.rb.tt +17 -0
- data/lib/generators/specs/templates/resource_signs_up_spec.rb.tt +23 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6effecf1c766dc1b0a188e9f18bdb48f8767e553
|
4
|
+
data.tar.gz: feb9ba88290c49452a30ced186dee6d3b93a0ac0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c44eeab458aa434a7487a668aaa9e1ce86f475a57ef982a7e24a99a2705067b21c8adcfa014dba39a64eb6e54f9a381ec755b66a5042b3040ab5627b0d7ef928
|
7
|
+
data.tar.gz: e8785b973c23cdb527d3d3713a4eccae2c0b0ad0cc34d6454ed4309b99e3bd9668753898ff2f779edba225d49fe1dcd4c350da1f5c573e92ea6895a510d45fb6
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby
|
8
|
+
exclude_fingerprints:
|
9
|
+
- 9f7a179915ee4a7f1d639e9242aedd01
|
10
|
+
fixme:
|
11
|
+
enabled: true
|
12
|
+
rubocop:
|
13
|
+
enabled: true
|
14
|
+
ratings:
|
15
|
+
paths:
|
16
|
+
- "**.rb"
|
17
|
+
exclude_paths:
|
18
|
+
- features/
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# devise-specs
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/andrii/devise-specs.svg?branch=master)](https://travis-ci.org/andrii/devise-specs)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/andrii/devise-specs/badges/gpa.svg)](https://codeclimate.com/github/andrii/devise-specs)
|
5
|
+
|
6
|
+
devise-specs is a Rails generator that adds the Devise authentication acceptance tests when you run the `devise` generator. The tests are RSpec feature specs containing Factory Girl or Fabricatoin fixture replacement methods and Capybara actions.
|
7
|
+
|
8
|
+
Generated feature specs test the following features:
|
9
|
+
* Registration
|
10
|
+
* Login
|
11
|
+
* Logout
|
12
|
+
* Password reset
|
13
|
+
|
14
|
+
Works with Rails 4 and 5.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Specify the required dependencies in a `Gemfile`:
|
19
|
+
```ruby
|
20
|
+
gem 'devise'
|
21
|
+
|
22
|
+
group :development do
|
23
|
+
gem 'devise-specs'
|
24
|
+
end
|
25
|
+
|
26
|
+
group :test do
|
27
|
+
gem 'capybara'
|
28
|
+
end
|
29
|
+
|
30
|
+
group :development, :test do
|
31
|
+
gem 'rspec-rails'
|
32
|
+
gem 'factory_girl_rails' # or: gem 'fabrication'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
and then run `bundle install`.
|
37
|
+
|
38
|
+
## Setup
|
39
|
+
|
40
|
+
Generate the RSpec configuratoin files:
|
41
|
+
```
|
42
|
+
$ rails generate rspec:install
|
43
|
+
```
|
44
|
+
|
45
|
+
Generate the Devise configuration files and follow the setup instructions:
|
46
|
+
```
|
47
|
+
$ rails generate devise:install
|
48
|
+
```
|
49
|
+
|
50
|
+
Configure the Action Mailer URL options for the test environment using the following line in `config/environments/test.rb`:
|
51
|
+
```ruby
|
52
|
+
config.action_mailer.default_url_options = { host: 'localhost', port: 3001 }
|
53
|
+
```
|
54
|
+
|
55
|
+
Add the authentication links to the layout, `user_signed_in?` should be `admin_signed_in?` if your Devise model is `Admin`:
|
56
|
+
```erb
|
57
|
+
<% if user_signed_in? %>
|
58
|
+
<%= link_to 'Sign Out', destroy_user_session_path, method: :delete %>
|
59
|
+
<% else %>
|
60
|
+
<%= link_to 'Sign In', new_user_session_path %>
|
61
|
+
<%= link_to 'Sign Up', new_user_registration_path %>
|
62
|
+
<% end %>
|
63
|
+
```
|
64
|
+
|
65
|
+
Add the following lines to `config/application.rb` if you are using the Fabrication gem and gem version is less than 2.15.1:
|
66
|
+
```ruby
|
67
|
+
config.generators do |g|
|
68
|
+
g.fixture_replacement :fabrication
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Usage
|
73
|
+
|
74
|
+
Generate a Devise model, e.g. `User`:
|
75
|
+
```
|
76
|
+
$ rails generate devise User
|
77
|
+
...
|
78
|
+
invoke specs
|
79
|
+
gsub spec/rails_helper.rb
|
80
|
+
insert spec/factories/users.rb
|
81
|
+
create spec/support/factory_girl.rb
|
82
|
+
create spec/support/helpers.rb
|
83
|
+
create spec/features/user_signs_up_spec.rb
|
84
|
+
create spec/features/user_signs_in_spec.rb
|
85
|
+
create spec/features/user_signs_out_spec.rb
|
86
|
+
create spec/features/user_resets_password_spec.rb
|
87
|
+
```
|
88
|
+
|
89
|
+
Run the migrations:
|
90
|
+
```
|
91
|
+
$ rake db:migrate RAILS_ENV=test
|
92
|
+
```
|
93
|
+
|
94
|
+
Make sure the specs pass:
|
95
|
+
```
|
96
|
+
$ rspec spec/features
|
97
|
+
.........
|
98
|
+
|
99
|
+
Finished in 1.08 seconds (files took 2.1 seconds to load)
|
100
|
+
9 examples, 0 failures
|
101
|
+
```
|
102
|
+
|
103
|
+
## Documentation
|
104
|
+
|
105
|
+
Visit the [Relish docs](https://relishapp.com/andrii/devise-specs/docs) for all the available features and examples of the generated feature specs.
|
106
|
+
|
107
|
+
## License
|
108
|
+
|
109
|
+
MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'devise-specs'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.authors = ['Andrii Ponomarov']
|
5
|
+
s.email = 'andrii.ponomarov@gmail.com'
|
6
|
+
s.summary = 'Generates the Devise acceptance tests.'
|
7
|
+
s.homepage = 'https://github.com/andrii/devise-specs'
|
8
|
+
s.license = 'MIT'
|
9
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features|fixtures)/}) }
|
10
|
+
|
11
|
+
s.add_runtime_dependency 'devise', '~> 4.1'
|
12
|
+
|
13
|
+
s.add_development_dependency 'rake', '~> 11.1'
|
14
|
+
s.add_development_dependency 'aruba', '~> 0.14.1'
|
15
|
+
end
|
data/lib/devise-specs.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'devise/specs/railtie'
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Specs
|
2
|
+
module Generators
|
3
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
4
|
+
ATTRIBUTES = %(
|
5
|
+
email 'username@example.com'
|
6
|
+
password 'password')
|
7
|
+
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
|
10
|
+
def require_supporting_files
|
11
|
+
uncomment_lines 'spec/rails_helper.rb', /spec.support.*rb.*require/
|
12
|
+
end
|
13
|
+
|
14
|
+
def insert_fixture_replacement_attributes
|
15
|
+
return if behavior == :revoke
|
16
|
+
|
17
|
+
if fixture_replacement == :factory_girl
|
18
|
+
insert_factory_girl_attributes
|
19
|
+
elsif fixture_replacement == :fabrication
|
20
|
+
insert_fabrication_attributes
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_factory_girl_config_file
|
25
|
+
if fixture_replacement == :factory_girl
|
26
|
+
template 'factory_girl.rb', 'spec/support/factory_girl.rb'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_helpers_file
|
31
|
+
template 'helpers.rb', 'spec/support/helpers.rb'
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_specs
|
35
|
+
template 'resource_signs_up_spec.rb',
|
36
|
+
"spec/features/#{singular_name}_signs_up_spec.rb"
|
37
|
+
|
38
|
+
template 'resource_signs_in_spec.rb',
|
39
|
+
"spec/features/#{singular_name}_signs_in_spec.rb"
|
40
|
+
|
41
|
+
template 'resource_signs_out_spec.rb',
|
42
|
+
"spec/features/#{singular_name}_signs_out_spec.rb"
|
43
|
+
|
44
|
+
template 'resource_resets_password_spec.rb',
|
45
|
+
"spec/features/#{singular_name}_resets_password_spec.rb"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def fixture_replacement
|
51
|
+
Rails.application.config.generators.rails[:fixture_replacement]
|
52
|
+
end
|
53
|
+
|
54
|
+
def insert_factory_girl_attributes
|
55
|
+
path = "spec/factories/#{plural_name}.rb"
|
56
|
+
attrs = ATTRIBUTES.gsub(/^ {4}/, '')
|
57
|
+
after = "factory :#{singular_name} do"
|
58
|
+
|
59
|
+
insert_into_file path, attrs, after: after
|
60
|
+
end
|
61
|
+
|
62
|
+
def insert_fabrication_attributes
|
63
|
+
path = "spec/fabricators/#{singular_name}_fabricator.rb"
|
64
|
+
attrs = ATTRIBUTES.gsub(/^ {6}/, '')
|
65
|
+
after = "Fabricator(:#{singular_name}) do"
|
66
|
+
|
67
|
+
insert_into_file path, attrs, after: after
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Helpers
|
2
|
+
def sign_in(resource)
|
3
|
+
visit new_<%= singular_name %>_session_path
|
4
|
+
|
5
|
+
fill_in 'Email', with: resource.email
|
6
|
+
fill_in 'Password', with: resource.password
|
7
|
+
click_button 'Log in'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include Helpers, type: :feature
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
feature '<%= human_name %> resets a password' do
|
4
|
+
scenario '<%= singular_name %> enters a valid email' do
|
5
|
+
<% if fixture_replacement == :factory_girl -%>
|
6
|
+
<%= singular_name %> = create :<%= singular_name %>
|
7
|
+
<% elsif fixture_replacement == :fabrication -%>
|
8
|
+
<%= singular_name %> = Fabricate :<%= singular_name %>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
visit new_<%= singular_name %>_password_path
|
12
|
+
|
13
|
+
fill_in 'Email', with: <%= singular_name %>.email
|
14
|
+
click_button 'Send me reset password instructions'
|
15
|
+
|
16
|
+
expect(page).to have_text 'You will receive an email with instructions'
|
17
|
+
end
|
18
|
+
|
19
|
+
scenario '<%= singular_name %> enters an invalid email' do
|
20
|
+
visit new_<%= singular_name %>_password_path
|
21
|
+
|
22
|
+
fill_in 'Email', with: 'username@example.com'
|
23
|
+
click_button 'Send me reset password instructions'
|
24
|
+
|
25
|
+
expect(page).to have_text 'Email not found'
|
26
|
+
end
|
27
|
+
|
28
|
+
scenario '<%= singular_name %> changes password' do
|
29
|
+
<% if fixture_replacement == :factory_girl -%>
|
30
|
+
token = create(:<%= singular_name %>).send_reset_password_instructions
|
31
|
+
<% elsif fixture_replacement == :fabrication -%>
|
32
|
+
token = Fabricate(:<%= singular_name %>).send_reset_password_instructions
|
33
|
+
<% end -%>
|
34
|
+
|
35
|
+
visit edit_<%= singular_name %>_password_path(reset_password_token: token)
|
36
|
+
|
37
|
+
fill_in 'New password', with: 'p4ssw0rd'
|
38
|
+
fill_in 'Confirm new password', with: 'p4ssw0rd'
|
39
|
+
click_button 'Change my password'
|
40
|
+
|
41
|
+
expect(page).to have_text 'Your password has been changed successfully.'
|
42
|
+
end
|
43
|
+
|
44
|
+
scenario 'password reset token is invalid' do
|
45
|
+
visit edit_<%= singular_name %>_password_path(reset_password_token: 'token')
|
46
|
+
|
47
|
+
fill_in 'New password', with: 'p4ssw0rd'
|
48
|
+
fill_in 'Confirm new password', with: 'p4ssw0rd'
|
49
|
+
click_button 'Change my password'
|
50
|
+
|
51
|
+
expect(page).to have_text 'Reset password token is invalid'
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
feature '<%= human_name %> signs in' do
|
4
|
+
scenario 'with valid credentials' do
|
5
|
+
<% if fixture_replacement == :factory_girl -%>
|
6
|
+
<%= singular_name %> = create :<%= singular_name %>
|
7
|
+
<% elsif fixture_replacement == :fabrication -%>
|
8
|
+
<%= singular_name %> = Fabricate :<%= singular_name %>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
sign_in <%= singular_name %>
|
12
|
+
|
13
|
+
expect(page).to have_text 'Signed in successfully.'
|
14
|
+
end
|
15
|
+
|
16
|
+
scenario 'with invalid credentials' do
|
17
|
+
<% if fixture_replacement == :factory_girl -%>
|
18
|
+
<%= singular_name %> = build :<%= singular_name %>
|
19
|
+
<% elsif fixture_replacement == :fabrication -%>
|
20
|
+
<%= singular_name %> = Fabricate.build :<%= singular_name %>
|
21
|
+
<% end -%>
|
22
|
+
|
23
|
+
sign_in <%= singular_name %>
|
24
|
+
|
25
|
+
expect(page).to have_text 'Invalid Email or password.'
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
feature '<%= human_name %> signs out' do
|
4
|
+
scenario '<%= singular_name %> signed in' do
|
5
|
+
<% if fixture_replacement == :factory_girl -%>
|
6
|
+
<%= singular_name %> = create :<%= singular_name %>
|
7
|
+
<% elsif fixture_replacement == :fabrication -%>
|
8
|
+
<%= singular_name %> = Fabricate :<%= singular_name %>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
sign_in <%= singular_name %>
|
12
|
+
|
13
|
+
click_link 'Sign Out'
|
14
|
+
|
15
|
+
expect(page).to have_text 'Signed out successfully.'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
feature '<%= human_name %> signs up' do
|
4
|
+
scenario 'with valid data' do
|
5
|
+
visit new_<%= singular_name %>_registration_path
|
6
|
+
|
7
|
+
fill_in 'Email', with: 'username@example.com'
|
8
|
+
fill_in 'Password', with: 'password'
|
9
|
+
fill_in 'Password confirmation', with: 'password'
|
10
|
+
click_button 'Sign up'
|
11
|
+
|
12
|
+
expect(page).to have_text 'Welcome! You have signed up successfully.'
|
13
|
+
end
|
14
|
+
|
15
|
+
scenario 'with invalid data' do
|
16
|
+
visit new_<%= singular_name %>_registration_path
|
17
|
+
|
18
|
+
click_button 'Sign up'
|
19
|
+
|
20
|
+
expect(page).to have_text "Email can't be blank"
|
21
|
+
expect(page).to have_text "Password can't be blank"
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise-specs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrii Ponomarov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: devise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aruba
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.14.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.14.1
|
55
|
+
description:
|
56
|
+
email: andrii.ponomarov@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".codeclimate.yml"
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- devise-specs.gemspec
|
68
|
+
- lib/devise-specs.rb
|
69
|
+
- lib/devise/specs/railtie.rb
|
70
|
+
- lib/generators/specs/devise_generator.rb
|
71
|
+
- lib/generators/specs/templates/factory_girl.rb.tt
|
72
|
+
- lib/generators/specs/templates/helpers.rb.tt
|
73
|
+
- lib/generators/specs/templates/resource_resets_password_spec.rb.tt
|
74
|
+
- lib/generators/specs/templates/resource_signs_in_spec.rb.tt
|
75
|
+
- lib/generators/specs/templates/resource_signs_out_spec.rb.tt
|
76
|
+
- lib/generators/specs/templates/resource_signs_up_spec.rb.tt
|
77
|
+
homepage: https://github.com/andrii/devise-specs
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.5.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Generates the Devise acceptance tests.
|
101
|
+
test_files: []
|