1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Add minimal support for Rails 6

* Add Rails 6 appraisal to start testing against it.
* Fix usage of Module#parent as this is deprecated in Rails 6 in favor
  of Module#module_parent.
* Ensure that we're using the correct version of `sqlite3` and `pg` at
  all times
* When creating classes within tests, ensure that they are removed
  correctly
* Fix detection of has_secure_password in models: Check that
  InstanceMethodsOnActivation is specifically defined, as Rails 6 no
  longer has such a module.

Co-authored-by: Lee Machin <me@mrl.ee>
This commit is contained in:
Elliot Winkler 2019-03-20 22:24:02 -07:00
parent 9a47fa3add
commit ae9bf4a735
21 changed files with 553 additions and 77 deletions

View file

@ -1,8 +1,17 @@
language: ruby
sudo: false
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
- DATABASE_ADAPTER=sqlite3
- DATABASE_ADAPTER=postgresql
global:
- PGPORT=5433
matrix:
- DATABASE_ADAPTER=sqlite3
- DATABASE_ADAPTER=postgresql
rvm:
- 2.4.4
- 2.5.4
@ -12,8 +21,13 @@ gemfile:
- gemfiles/rails_5_0.gemfile
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_6_0.gemfile
matrix:
exclude:
- rvm: 2.3.7
gemfile: gemfiles/rails_6_0.gemfile
- rvm: 2.4.4
gemfile: gemfiles/rails_6_0.gemfile
- rvm: 2.6.2
gemfile: gemfiles/rails_4_2.gemfile
cache: bundler

View file

@ -12,8 +12,7 @@ shared_jruby_dependencies = proc do
end
shared_rails_dependencies = proc do
gem 'sqlite3', platform: :ruby
gem 'pg', platform: :ruby
gem 'sqlite3', '~> 1.3.6', platform: :ruby
end
shared_spring_dependencies = proc do
@ -23,7 +22,6 @@ end
shared_test_dependencies = proc do
gem 'minitest-reporters'
# gem 'nokogiri', '~> 1.8'
gem 'rspec-rails', '~> 3.6'
gem 'shoulda-context', '~> 1.2.0'
end
@ -48,10 +46,11 @@ appraise 'rails_4_2' do
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bcrypt', '~> 3.1.7'
# Other dependencies we use
# Other dependencies
gem 'activeresource', '4.0.0'
gem 'json', '~> 1.4'
gem 'protected_attributes', '~> 1.0.6'
gem 'pg', '~> 0.15', platform: :ruby
end
appraise 'rails_5_0' do
@ -67,6 +66,9 @@ appraise 'rails_5_0' do
gem 'bcrypt', '~> 3.1.7'
gem 'listen', '~> 3.0.5'
gem 'spring-watcher-listen', '~> 2.0.0'
# Other dependencies
gem 'pg', '~> 1.1', platform: :ruby
end
appraise 'rails_5_1' do
@ -83,6 +85,9 @@ appraise 'rails_5_1' do
gem 'selenium-webdriver'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring-watcher-listen', '~> 2.0.0'
# Other dependencies
gem 'pg', '~> 1.1', platform: :ruby
end
appraise 'rails_5_2' do
@ -101,4 +106,29 @@ appraise 'rails_5_2' do
gem 'chromedriver-helper'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring-watcher-listen', '~> 2.0.0'
# Other dependencies
gem 'pg', '~> 1.1', platform: :ruby
end
appraise 'rails_6_0' do
instance_eval(&shared_dependencies)
gem 'rails', '~> 6.0.0.beta3'
gem 'puma', '~> 3.11'
gem 'bootsnap', '>= 1.4.1', require: false
gem 'sass-rails', '~> 5.0'
gem 'webpacker', '>= 4.0.0.rc3'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bcrypt', '~> 3.1.7'
gem 'capybara', '>= 2.15'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
# Other dependencies
gem 'rails-controller-testing', '>= 1.0.1'
gem 'pg', '~> 1.1', platform: :ruby
end

View file

@ -19,8 +19,7 @@ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "jruby-openssl", platform: :jruby
gem "therubyrhino", platform: :jruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "sqlite3", "~> 1.3.6", platform: :ruby
gem "spring"
gem "spring-commands-rspec"
gem "minitest-reporters"
@ -38,3 +37,4 @@ gem "bcrypt", "~> 3.1.7"
gem "activeresource", "4.0.0"
gem "json", "~> 1.4"
gem "protected_attributes", "~> 1.0.6"
gem "pg", "~> 0.15", platform: :ruby

View file

@ -235,7 +235,7 @@ DEPENDENCIES
jruby-openssl
json (~> 1.4)
minitest-reporters
pg
pg (~> 0.15)
protected_attributes (~> 1.0.6)
pry
pry-byebug
@ -251,7 +251,7 @@ DEPENDENCIES
shoulda-context (~> 1.2.0)
spring
spring-commands-rspec
sqlite3
sqlite3 (~> 1.3.6)
therubyrhino
turbolinks
uglifier (>= 1.3.0)

View file

@ -19,8 +19,7 @@ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "jruby-openssl", platform: :jruby
gem "therubyrhino", platform: :jruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "sqlite3", "~> 1.3.6", platform: :ruby
gem "spring"
gem "spring-commands-rspec"
gem "minitest-reporters"
@ -36,3 +35,4 @@ gem "jbuilder", "~> 2.5"
gem "bcrypt", "~> 3.1.7"
gem "listen", "~> 3.0.5"
gem "spring-watcher-listen", "~> 2.0.0"
gem "pg", "~> 1.1", platform: :ruby

View file

@ -91,7 +91,7 @@ GEM
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
pg (0.21.0)
pg (1.1.4)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
@ -227,7 +227,7 @@ DEPENDENCIES
jruby-openssl
listen (~> 3.0.5)
minitest-reporters
pg
pg (~> 1.1)
pry
pry-byebug
puma (~> 3.0)
@ -244,7 +244,7 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
sqlite3
sqlite3 (~> 1.3.6)
therubyrhino
turbolinks (~> 5)
yard

View file

@ -19,8 +19,7 @@ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "jruby-openssl", platform: :jruby
gem "therubyrhino", platform: :jruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "sqlite3", "~> 1.3.6", platform: :ruby
gem "spring"
gem "spring-commands-rspec"
gem "minitest-reporters"
@ -37,3 +36,4 @@ gem "capybara", "~> 2.13"
gem "selenium-webdriver"
gem "listen", ">= 3.0.5", "< 3.2"
gem "spring-watcher-listen", "~> 2.0.0"
gem "pg", "~> 1.1", platform: :ruby

View file

@ -243,7 +243,7 @@ DEPENDENCIES
jruby-openssl
listen (>= 3.0.5, < 3.2)
minitest-reporters
pg
pg (~> 1.1)
pry
pry-byebug
puma (~> 3.7)
@ -261,7 +261,7 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
sqlite3
sqlite3 (~> 1.3.6)
therubyrhino
turbolinks (~> 5)
yard

View file

@ -19,8 +19,7 @@ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "jruby-openssl", platform: :jruby
gem "therubyrhino", platform: :jruby
gem "sqlite3", platform: :ruby
gem "pg", platform: :ruby
gem "sqlite3", "~> 1.3.6", platform: :ruby
gem "spring"
gem "spring-commands-rspec"
gem "minitest-reporters"
@ -39,3 +38,4 @@ gem "selenium-webdriver"
gem "chromedriver-helper"
gem "listen", ">= 3.0.5", "< 3.2"
gem "spring-watcher-listen", "~> 2.0.0"
gem "pg", "~> 1.1", platform: :ruby

View file

@ -262,7 +262,7 @@ DEPENDENCIES
jruby-openssl
listen (>= 3.0.5, < 3.2)
minitest-reporters
pg
pg (~> 1.1)
pry
pry-byebug
puma (~> 3.11)
@ -280,7 +280,7 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
sqlite3
sqlite3 (~> 1.3.6)
therubyrhino
turbolinks (~> 5)
yard

View file

@ -0,0 +1,42 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "appraisal", "2.2.0"
gem "bundler", "~> 1.1"
gem "pry"
gem "pry-byebug"
gem "rake", "12.3.2"
gem "rspec", "~> 3.6"
gem "rubocop", require: false
gem "zeus", require: false
gem "fssm"
gem "pygments.rb"
gem "redcarpet"
gem "yard"
gem "activerecord-jdbc-adapter", platform: :jruby
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "jruby-openssl", platform: :jruby
gem "therubyrhino", platform: :jruby
gem "sqlite3", "~> 1.3.6", platform: :ruby
gem "spring"
gem "spring-commands-rspec"
gem "minitest-reporters"
gem "rspec-rails", "~> 3.6"
gem "shoulda-context", "~> 1.2.0"
gem "rails", "~> 6.0.0.beta3"
gem "puma", "~> 3.11"
gem "bootsnap", ">= 1.4.1", require: false
gem "sass-rails", "~> 5.0"
gem "webpacker", ">= 4.0.0.rc3"
gem "turbolinks", "~> 5"
gem "jbuilder", "~> 2.5"
gem "bcrypt", "~> 3.1.7"
gem "capybara", ">= 2.15"
gem "listen", ">= 3.0.5", "< 3.2"
gem "spring-watcher-listen", "~> 2.0.0"
gem "selenium-webdriver"
gem "chromedriver-helper"
gem "rails-controller-testing", ">= 1.0.1"
gem "pg", "~> 1.1", platform: :ruby

View file

@ -0,0 +1,316 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
activejob (= 6.0.0.beta3)
activerecord (= 6.0.0.beta3)
activestorage (= 6.0.0.beta3)
activesupport (= 6.0.0.beta3)
mail (>= 2.7.1)
actionmailer (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
actionview (= 6.0.0.beta3)
activejob (= 6.0.0.beta3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.0.beta3)
actionview (= 6.0.0.beta3)
activesupport (= 6.0.0.beta3)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actiontext (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
activerecord (= 6.0.0.beta3)
activestorage (= 6.0.0.beta3)
activesupport (= 6.0.0.beta3)
nokogiri (>= 1.8.5)
actionview (6.0.0.beta3)
activesupport (= 6.0.0.beta3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (6.0.0.beta3)
activesupport (= 6.0.0.beta3)
globalid (>= 0.3.6)
activemodel (6.0.0.beta3)
activesupport (= 6.0.0.beta3)
activerecord (6.0.0.beta3)
activemodel (= 6.0.0.beta3)
activesupport (= 6.0.0.beta3)
activestorage (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
activerecord (= 6.0.0.beta3)
marcel (~> 0.3.1)
activesupport (6.0.0.beta3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 1.3, >= 1.3.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
ansi (1.5.0)
appraisal (2.2.0)
bundler
rake
thor (>= 0.14.0)
archive-zip (0.12.0)
io-like (~> 0.3.0)
ast (2.4.0)
bcrypt (3.1.12)
bootsnap (1.4.1)
msgpack (~> 1.0)
builder (3.2.3)
byebug (11.0.0)
capybara (3.14.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
xpath (~> 3.2)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (2.1.0)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
diff-lcs (1.3)
erubi (1.8.0)
ffi (1.10.0)
fssm (0.2.10)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jaro_winkler (1.5.2)
jbuilder (2.8.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
minitest-reporters (1.3.6)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
msgpack (1.2.9)
multi_json (1.13.1)
nio4r (2.3.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
parallel (1.14.0)
parser (2.6.0.0)
ast (~> 2.4.0)
pg (1.1.4)
powerpack (0.1.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.7.0)
byebug (~> 11.0)
pry (~> 0.10)
psych (3.1.0)
public_suffix (3.0.3)
puma (3.12.0)
pygments.rb (1.2.1)
multi_json (>= 1.0.0)
rack (2.0.6)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.0.beta3)
actioncable (= 6.0.0.beta3)
actionmailbox (= 6.0.0.beta3)
actionmailer (= 6.0.0.beta3)
actionpack (= 6.0.0.beta3)
actiontext (= 6.0.0.beta3)
actionview (= 6.0.0.beta3)
activejob (= 6.0.0.beta3)
activemodel (= 6.0.0.beta3)
activerecord (= 6.0.0.beta3)
activestorage (= 6.0.0.beta3)
activesupport (= 6.0.0.beta3)
bundler (>= 1.3.0)
railties (= 6.0.0.beta3)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
activesupport (= 6.0.0.beta3)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
redcarpet (3.4.0)
regexp_parser (1.3.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.65.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
sass (3.7.3)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
shoulda-context (1.2.2)
spring (2.0.2)
activesupport (>= 4.2)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
turbolinks (5.2.0)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.1)
webpacker (4.0.2)
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.18)
zeitwerk (1.3.4)
zeus (0.15.14)
method_source (>= 0.6.7)
PLATFORMS
ruby
DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
appraisal (= 2.2.0)
bcrypt (~> 3.1.7)
bootsnap (>= 1.4.1)
bundler (~> 1.1)
capybara (>= 2.15)
chromedriver-helper
fssm
jbuilder (~> 2.5)
jdbc-sqlite3
jruby-openssl
listen (>= 3.0.5, < 3.2)
minitest-reporters
pg (~> 1.1)
pry
pry-byebug
puma (~> 3.11)
pygments.rb
rails (~> 6.0.0.beta3)
rails-controller-testing (>= 1.0.1)
rake (= 12.3.2)
redcarpet
rspec (~> 3.6)
rspec-rails (~> 3.6)
rubocop
sass-rails (~> 5.0)
selenium-webdriver
shoulda-context (~> 1.2.0)
spring
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
sqlite3 (~> 1.3.6)
therubyrhino
turbolinks (~> 5)
webpacker (>= 4.0.0.rc3)
yard
zeus
BUNDLED WITH
1.17.3

View file

@ -562,7 +562,8 @@ module Shoulda
def has_been_qualified?
@submatchers.any? do |submatcher|
submatcher.class.parent == NumericalityMatchers
Shoulda::Matchers::RailsShim.parent_of(submatcher.class) ==
NumericalityMatchers
end
end

View file

@ -147,9 +147,8 @@ module Shoulda
private
def secure_password_being_validated?
defined?(::ActiveModel::SecurePassword) &&
@subject.class.ancestors.include?(::ActiveModel::SecurePassword::InstanceMethodsOnActivation) &&
@attribute == :password
Shoulda::Matchers::RailsShim.digestible_attributes_in(@subject).
include?(@attribute)
end
def possibly_ignore_interference_by_writer

View file

@ -1362,13 +1362,11 @@ module Shoulda
def class_has_foreign_key?(klass)
if options.key?(:foreign_key)
option_verifier.correct_for_string?(:foreign_key, options[:foreign_key])
elsif column_names_for(klass).include?(foreign_key)
true
else
if klass.column_names.include?(foreign_key)
true
else
@missing = "#{klass} does not have a #{foreign_key} foreign key."
false
end
@missing = "#{klass} does not have a #{foreign_key} foreign key."
false
end
end
@ -1407,6 +1405,12 @@ module Shoulda
failing_submatchers.empty?
end
def column_names_for(klass)
klass.column_names
rescue ::ActiveRecord::StatementInvalid
[]
end
def belongs_to_required_by_default?
::ActiveRecord::Base.belongs_to_required_by_default
end

View file

@ -546,10 +546,11 @@ module Shoulda
end
def ensure_secure_password_set(instance)
if has_secure_password?
instance.password = "password"
instance.password_confirmation = "password"
end
Shoulda::Matchers::RailsShim.digestible_attributes_in(instance).
each do |attribute|
instance.send("#{attribute}=", 'password')
instance.send("#{attribute}_confirmation=", 'password')
end
end
def update_existing_record!(value)
@ -576,9 +577,7 @@ module Shoulda
end
def has_secure_password?
model.ancestors.map(&:to_s).include?(
'ActiveModel::SecurePassword::InstanceMethodsOnActivation'
)
Shoulda::Matchers::RailsShim.has_secure_password?(subject, @attribute)
end
def build_new_record

View file

@ -119,6 +119,43 @@ module Shoulda
end
end
def parent_of(mod)
if mod.respond_to?(:module_parent)
mod.module_parent
else
mod.parent
end
end
def has_secure_password?(record, attribute_name)
if secure_password_module
attribute_name == :password &&
record.class.ancestors.include?(secure_password_module)
else
record.respond_to?("authenticate_#{attribute_name}")
end
end
def digestible_attributes_in(record)
record.methods.inject([]) do |array, method_name|
match = method_name.to_s.match(
/\A(\w+)_(?:confirmation|digest)=\Z/,
)
if match
array.concat([match[1].to_sym])
else
array
end
end
end
def secure_password_module
::ActiveModel::SecurePassword::InstanceMethodsOnActivation
rescue NameError
nil
end
private
def simply_generate_validation_message(

View file

@ -78,6 +78,8 @@ module AcceptanceTests
bundle.remove_gem 'byebug'
bundle.remove_gem 'web-console'
bundle.add_gem 'pg'
bundle.remove_gem 'sqlite3'
bundle.add_gem 'sqlite3', '~> 1.3.6'
end
fs.open('config/database.yml', 'w') do |file|

View file

@ -18,18 +18,15 @@ module UnitTests
end
def reset
remove_defined_classes
remove_defined_modules
defined_modules.clear
end
def define_module(module_name, &block)
module_name = module_name.to_s.camelize
namespace, name_without_namespace = parse_constant_name(module_name)
namespace, name_without_namespace =
ClassBuilder.parse_constant_name(module_name)
if namespace.const_defined?(name_without_namespace, false)
namespace.__send__(:remove_const, name_without_namespace)
end
remove_defined_module(module_name)
eval <<-RUBY
module #{namespace}::#{name_without_namespace}
@ -38,6 +35,7 @@ module UnitTests
namespace.const_get(name_without_namespace).tap do |constant|
constant.unloadable
@_defined_modules = defined_modules | [constant]
if block
constant.module_eval(&block)
@ -47,13 +45,9 @@ module UnitTests
def define_class(class_name, parent_class = Object, &block)
class_name = class_name.to_s.camelize
namespace, name_without_namespace = parse_constant_name(class_name)
namespace, name_without_namespace =
ClassBuilder.parse_constant_name(class_name)
if namespace.const_defined?(name_without_namespace, false)
namespace.__send__(:remove_const, name_without_namespace)
end
remove_defined_module(class_name)
eval <<-RUBY
class #{namespace}::#{name_without_namespace} < ::#{parent_class}
@ -62,6 +56,7 @@ module UnitTests
namespace.const_get(name_without_namespace).tap do |constant|
constant.unloadable
@_defined_modules = defined_modules | [constant]
if block
if block.arity == 0
@ -82,8 +77,21 @@ module UnitTests
private
def remove_defined_classes
::ActiveSupport::Dependencies.clear
def remove_defined_modules
defined_modules.reverse_each { |mod| remove_defined_module(mod.name) }
ActiveSupport::Dependencies.clear
end
def remove_defined_module(module_name)
namespace, name_without_namespace = parse_constant_name(module_name)
if namespace.const_defined?(name_without_namespace, false)
namespace.__send__(:remove_const, name_without_namespace)
end
end
def defined_modules
@_defined_modules ||= []
end
end
end

View file

@ -19,8 +19,7 @@ module UnitTests
generate
fs.within_project do
install_gems
remove_unwanted_gems
update_gems
end
end
@ -78,13 +77,34 @@ module UnitTests
remove_bootsnap
write_database_configuration
if bundle.version_of("rails") >= 5
if rails_version >= 5
add_initializer_for_time_zone_aware_types
end
end
def rails_new
run_command! %W(rails new #{fs.project_directory} --skip-bundle --no-rc)
run_command!(*rails_new_command)
end
def rails_new_command
if rails_version > 5
[
'rails',
'new',
fs.project_directory.to_s,
'--skip-bundle',
'--no-rc',
'--skip-webpack-install',
]
else
[
'rails',
'new',
fs.project_directory.to_s,
'--skip-bundle',
'--no-rc',
]
end
end
def fix_available_locales_warning
@ -132,20 +152,26 @@ end
end
end
def install_gems
bundle.install_gems
end
def remove_unwanted_gems
def update_gems
bundle.updating do
bundle.remove_gem 'turn'
bundle.remove_gem 'coffee-rails'
bundle.remove_gem 'uglifier'
bundle.remove_gem 'debugger'
bundle.remove_gem 'byebug'
bundle.remove_gem 'web-console'
bundle.add_gem 'pg'
bundle.remove_gem 'sqlite3'
bundle.add_gem 'sqlite3', '~> 1.3.6'
end
end
def run_command!(*args)
Tests::CommandRunner.run!(*args)
end
def rails_version
bundle.version_of('rails')
end
end
end

View file

@ -1,20 +1,18 @@
require 'unit_spec_helper'
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher, type: :model do
if active_model_3_1?
it 'matches when the subject configures has_secure_password with default options' do
working_model = define_model(:example, password_digest: :string) { has_secure_password }
expect(working_model.new).to have_secure_password
end
it 'matches when the subject configures has_secure_password with default options' do
working_model = define_model(:example, password_digest: :string) { has_secure_password }
expect(working_model.new).to have_secure_password
end
it 'does not match when the subject does not authenticate a password' do
no_secure_password = define_model(:example)
expect(no_secure_password.new).not_to have_secure_password
end
it 'does not match when the subject does not authenticate a password' do
no_secure_password = define_model(:example)
expect(no_secure_password.new).not_to have_secure_password
end
it 'does not match when the subject is missing the password_digest attribute' do
no_digest_column = define_model(:example) { has_secure_password }
expect(no_digest_column.new).not_to have_secure_password
end
it 'does not match when the subject is missing the password_digest attribute' do
no_digest_column = define_model(:example) { has_secure_password }
expect(no_digest_column.new).not_to have_secure_password
end
end