-
-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ignoring case sensitivity to uniqueness validation matcher #840
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -726,6 +726,51 @@ | |
end | ||
end | ||
|
||
context 'when the writer method for the attribute changes incoming values' do | ||
context 'and ignoring_case_sensitivity is not specified' do | ||
it 'raises a CouldNotSetAttributeError' do | ||
model = define_model_validating_uniqueness( | ||
attribute_name: :name, | ||
validation_options: { case_sensitive: false }, | ||
) | ||
|
||
model.class_eval do | ||
def name=(name) | ||
super(name.upcase) | ||
end | ||
end | ||
|
||
assertion = lambda do | ||
expect(model.new). | ||
to validate_uniqueness_of(:name). | ||
case_insensitive | ||
end | ||
|
||
expect(&assertion).to raise_error( | ||
Shoulda::Matchers::ActiveModel::AllowValueMatcher::CouldNotSetAttributeError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [86/80] |
||
) | ||
end | ||
end | ||
|
||
context 'and ignoring_case_sensitivity is specified' do | ||
it 'accepts (and not raise an error)' do | ||
model = define_model_validating_uniqueness( | ||
attribute_name: :name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm noticing that in the first test, you have the validation qualified with I'm kind of forgetting what the original bug was here. Is that something we need to have here, you think? Or, should we have two sets of tests, one where the validation is |
||
) | ||
|
||
model.class_eval do | ||
def name=(name) | ||
super(name.upcase) | ||
end | ||
end | ||
|
||
expect(model.new). | ||
to validate_uniqueness_of(:name). | ||
ignoring_case_sensitivity | ||
end | ||
end | ||
end | ||
|
||
let(:model_attributes) { {} } | ||
|
||
def default_attribute | ||
|
@@ -846,6 +891,7 @@ def determine_scope_attribute_names_from(scope_attributes) | |
end | ||
|
||
def define_model_validating_uniqueness(options = {}, &block) | ||
attribute_name = options.fetch(:attribute_name) { self.attribute_name } | ||
attribute_type = options.fetch(:attribute_type, :string) | ||
attribute_options = options.fetch(:attribute_options, {}) | ||
attribute = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [82/80]