mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
parent
21e984cd28
commit
f5f8e0aad3
3 changed files with 24 additions and 0 deletions
4
NEWS.md
4
NEWS.md
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
* Add ability to test `:autosave` option on associations.
|
* Add ability to test `:autosave` option on associations.
|
||||||
|
|
||||||
|
* Fix `validate_uniqueness_of(...).allow_nil` so that it can be used against an
|
||||||
|
non-password attribute which is in a model that `has_secure_password`. Doing
|
||||||
|
so previously would result in a "Password digest missing on new record" error.
|
||||||
|
|
||||||
# v 2.5.0
|
# v 2.5.0
|
||||||
|
|
||||||
* Fix Rails/Test::Unit integration to ensure that the test case classes we are
|
* Fix Rails/Test::Unit integration to ensure that the test case classes we are
|
||||||
|
|
|
@ -115,10 +115,18 @@ module Shoulda # :nodoc:
|
||||||
|
|
||||||
@subject.class.new.tap do |instance|
|
@subject.class.new.tap do |instance|
|
||||||
instance.send("#{@attribute}=", value)
|
instance.send("#{@attribute}=", value)
|
||||||
|
if has_secure_password?
|
||||||
|
instance.password = 'password'
|
||||||
|
instance.password_confirmation = 'password'
|
||||||
|
end
|
||||||
instance.save(validate: false)
|
instance.save(validate: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_secure_password?
|
||||||
|
@subject.class.ancestors.map(&:to_s).include?('ActiveModel::SecurePassword::InstanceMethodsOnActivation')
|
||||||
|
end
|
||||||
|
|
||||||
def set_scoped_attributes
|
def set_scoped_attributes
|
||||||
if @options[:scopes].present?
|
if @options[:scopes].present?
|
||||||
@options[:scopes].all? do |scope|
|
@options[:scopes].all? do |scope|
|
||||||
|
|
|
@ -293,6 +293,18 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if active_model_3_1?
|
||||||
|
context 'when the subject has a secure password' do
|
||||||
|
it 'allows nil on the attribute' do
|
||||||
|
model = define_model(:example, attr: :string, password_digest: :string) do |m|
|
||||||
|
validates_uniqueness_of :attr, allow_nil: true
|
||||||
|
has_secure_password
|
||||||
|
end.new
|
||||||
|
expect(model).to matcher.allow_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should create a nil and verify that it is allowed" do
|
it "should create a nil and verify that it is allowed" do
|
||||||
model = define_model_with_allow_nil
|
model = define_model_with_allow_nil
|
||||||
expect(model).to matcher.allow_nil
|
expect(model).to matcher.allow_nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue