diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-23 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-23 18:09:37 +0300 |
commit | 7e1e45d40a2312e20893ccfc6e7e5dfad6cf7b1c (patch) | |
tree | 7e0754c6a37ed9f3c13d15747cf8a5a5bce13387 /spec/rubocop | |
parent | ecf1ffc19875a94c9de675b0559adc408b202515 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb b/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb new file mode 100644 index 00000000000..37fcdb38907 --- /dev/null +++ b/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../rubocop/cop/active_model_errors_direct_manipulation' + +RSpec.describe RuboCop::Cop::ActiveModelErrorsDirectManipulation do + subject(:cop) { described_class.new } + + context 'when modifying errors' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + user.errors[:name] << 'msg' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...] + PATTERN + end + + context 'when assigning' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + user.errors[:name] = [] + ^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...] + PATTERN + end + end + end + + context 'when modifying errors.messages' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + user.errors.messages[:name] << 'msg' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...] + PATTERN + end + + context 'when assigning' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + user.errors.messages[:name] = [] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...] + PATTERN + end + end + end + + context 'when modifying errors.details' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + user.errors.details[:name] << {} + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...] + PATTERN + end + + context 'when assigning' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + user.errors.details[:name] = [] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...] + PATTERN + end + end + end +end |