From 8f0eef8b0023129b2e7848fe9ba62d3aaf717cc9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 24 Jul 2017 14:19:09 +0300 Subject: [PATCH 1/4] Update shoulda-matchers gem to 3.1.2 Signed-off-by: Dmitriy Zaporozhets --- Gemfile | 2 +- Gemfile.lock | 6 +++--- spec/spec_helper.rb | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 1ee44680774..df720c60bab 100644 --- a/Gemfile +++ b/Gemfile @@ -353,7 +353,7 @@ group :development, :test do end group :test do - gem 'shoulda-matchers', '~> 2.8.0', require: false + gem 'shoulda-matchers', '~> 3.1.2', require: false gem 'email_spec', '~> 1.6.0' gem 'json-schema', '~> 2.6.2' gem 'webmock', '~> 2.3.2' diff --git a/Gemfile.lock b/Gemfile.lock index b0b437ae342..6f555c830de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -774,8 +774,8 @@ GEM sexp_processor (4.9.0) sham_rack (1.3.6) rack - shoulda-matchers (2.8.0) - activesupport (>= 3.0.0) + shoulda-matchers (3.1.2) + activesupport (>= 4.0.0) sidekiq (5.0.4) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) @@ -1084,7 +1084,7 @@ DEPENDENCIES sentry-raven (~> 2.5.3) settingslogic (~> 2.0.9) sham_rack (~> 1.3.6) - shoulda-matchers (~> 2.8.0) + shoulda-matchers (~> 3.1.2) sidekiq (~> 5.0) sidekiq-cron (~> 0.6.0) sidekiq-limit_fetch (~> 3.4) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d5715b10ff..e7329210896 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -148,3 +148,10 @@ FactoryGirl::SyntaxRunner.class_eval do end ActiveRecord::Migration.maintain_test_schema! + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end From eafb03cfd5904893c3f05cd6a596997ccee09963 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 24 Jul 2017 15:21:16 +0300 Subject: [PATCH 2/4] Remove unnecessary set_flash.now from controller specs Signed-off-by: Dmitriy Zaporozhets --- spec/controllers/projects/issues_controller_spec.rb | 2 +- spec/controllers/projects/merge_requests_controller_spec.rb | 2 +- spec/controllers/sent_notifications_controller_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 18d0be3c103..13a39b1b260 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -806,7 +806,7 @@ describe Projects::IssuesController do delete :destroy, namespace_id: project.namespace, project_id: project, id: issue.iid expect(response).to have_http_status(302) - expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./).now + expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./) end it 'delegates the update of the todos count cache to TodoService' do diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index c193babead0..2fce4b7a85f 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -439,7 +439,7 @@ describe Projects::MergeRequestsController do delete :destroy, namespace_id: project.namespace, project_id: project, id: merge_request.iid expect(response).to have_http_status(302) - expect(controller).to set_flash[:notice].to(/The merge request was successfully deleted\./).now + expect(controller).to set_flash[:notice].to(/The merge request was successfully deleted\./) end it 'delegates the update of the todos count cache to TodoService' do diff --git a/spec/controllers/sent_notifications_controller_spec.rb b/spec/controllers/sent_notifications_controller_spec.rb index 7340a4e16c0..c8771eda313 100644 --- a/spec/controllers/sent_notifications_controller_spec.rb +++ b/spec/controllers/sent_notifications_controller_spec.rb @@ -23,7 +23,7 @@ describe SentNotificationsController, type: :controller do end it 'sets the flash message' do - expect(controller).to set_flash[:notice].to(/unsubscribed/).now + expect(controller).to set_flash[:notice].to(/unsubscribed/) end it 'redirects to the login page' do @@ -83,7 +83,7 @@ describe SentNotificationsController, type: :controller do end it 'sets the flash message' do - expect(controller).to set_flash[:notice].to(/unsubscribed/).now + expect(controller).to set_flash[:notice].to(/unsubscribed/) end it 'redirects to the issue page' do @@ -109,7 +109,7 @@ describe SentNotificationsController, type: :controller do end it 'sets the flash message' do - expect(controller).to set_flash[:notice].to(/unsubscribed/).now + expect(controller).to set_flash[:notice].to(/unsubscribed/) end it 'redirects to the merge request page' do From cc577b89706686063d4ff0d86a11c63b6570231c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 24 Jul 2017 15:33:14 +0300 Subject: [PATCH 3/4] Update tests for new version of shoulda-matchers Signed-off-by: Dmitriy Zaporozhets --- spec/models/notification_setting_spec.rb | 7 ++++++- spec/models/pages_domain_spec.rb | 2 +- spec/models/redirect_route_spec.rb | 2 +- spec/models/route_spec.rb | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index cc235ad467e..74fa1c1f926 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -11,7 +11,12 @@ RSpec.describe NotificationSetting, type: :model do it { is_expected.to validate_presence_of(:user) } it { is_expected.to validate_presence_of(:level) } - it { is_expected.to validate_uniqueness_of(:user_id).scoped_to([:source_id, :source_type]).with_message(/already exists in source/) } + + describe 'user_id' do + before { subject.user = create(:user) } + + it { is_expected.to validate_uniqueness_of(:user_id).scoped_to([:source_type, :source_id]).with_message(/already exists in source/) } + end context "events" do let(:user) { create(:user) } diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index f9d060d4e0e..d4a777a9bd9 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -11,7 +11,7 @@ describe PagesDomain, models: true do context 'is unique' do let(:domain) { 'my.domain.com' } - it { is_expected.to validate_uniqueness_of(:domain) } + it { is_expected.to validate_uniqueness_of(:domain).case_insensitive } end { diff --git a/spec/models/redirect_route_spec.rb b/spec/models/redirect_route_spec.rb index 71827421dd7..a97af28cb8e 100644 --- a/spec/models/redirect_route_spec.rb +++ b/spec/models/redirect_route_spec.rb @@ -11,7 +11,7 @@ describe RedirectRoute, models: true do describe 'validations' do it { is_expected.to validate_presence_of(:source) } it { is_expected.to validate_presence_of(:path) } - it { is_expected.to validate_uniqueness_of(:path) } + it { is_expected.to validate_uniqueness_of(:path).case_insensitive } end describe '.matching_path_and_descendants' do diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 1754253e0f2..12f7611fb28 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -15,7 +15,7 @@ describe Route, models: true do it { is_expected.to validate_presence_of(:source) } it { is_expected.to validate_presence_of(:path) } - it { is_expected.to validate_uniqueness_of(:path) } + it { is_expected.to validate_uniqueness_of(:path).case_insensitive } end describe 'callbacks' do From 3a0b9e06e1dd5f6141a6f04dd2b39dbb803c07f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 24 Jul 2017 19:26:15 +0300 Subject: [PATCH 4/4] Adjust tests to work with latest shoulda gem Signed-off-by: Dmitriy Zaporozhets --- spec/models/list_spec.rb | 6 ------ spec/models/notification_setting_spec.rb | 4 +++- spec/models/user_spec.rb | 4 +++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb index db2c2619968..a6cc01bea5f 100644 --- a/spec/models/list_spec.rb +++ b/spec/models/list_spec.rb @@ -13,12 +13,6 @@ describe List do it { is_expected.to validate_presence_of(:position) } it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than_or_equal_to(0) } - it 'validates uniqueness of label scoped to board_id' do - create(:list) - - expect(subject).to validate_uniqueness_of(:label_id).scoped_to(:board_id) - end - context 'when list_type is set to closed' do subject { described_class.new(list_type: :closed) } diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index 74fa1c1f926..76a7b07949f 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -13,7 +13,9 @@ RSpec.describe NotificationSetting, type: :model do it { is_expected.to validate_presence_of(:level) } describe 'user_id' do - before { subject.user = create(:user) } + before do + subject.user = create(:user) + end it { is_expected.to validate_uniqueness_of(:user_id).scoped_to([:source_type, :source_id]).with_message(/already exists in source/) } end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a1d6d7e6e0b..20bdb7e37da 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -114,7 +114,9 @@ describe User, models: true do end it 'validates uniqueness' do - expect(subject).to validate_uniqueness_of(:username).case_insensitive + user = build(:user) + + expect(user).to validate_uniqueness_of(:username).case_insensitive end end