diff --git a/Gemfile b/Gemfile index c64213479f71251a59ebefda0eeaef409b742a4a..39ffd95b2e264f544faea1ce1623c22c1c33c566 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,6 @@ end gem "rails", "~> 4.1.0" gem "protected_attributes" -gem 'rails-observers' # Make links from text gem 'rails_autolink', '~> 1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 6c27b6e37399ceb816764368b3071dc68a61ffc4..382633c2246fae54d0ddb1ab2b53dde6163a683c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -365,8 +365,6 @@ GEM bundler (>= 1.3.0, < 2.0) railties (= 4.1.1) sprockets-rails (~> 2.0) - rails-observers (0.1.2) - activemodel (~> 4.0) rails_autolink (1.1.6) rails (> 3.1) rails_best_practices (1.14.4) @@ -644,7 +642,6 @@ DEPENDENCIES rack-cors rack-mini-profiler rails (~> 4.1.0) - rails-observers rails_autolink (~> 1.1) rails_best_practices raphael-rails (~> 2.1.2) diff --git a/app/models/users_project.rb b/app/models/users_project.rb index e8810f56defbe9ec3989cc20a4c75181b9f12543..6495bed4e6177b00e0053875cfc6621fd07447f0 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -37,6 +37,10 @@ class UsersProject < ActiveRecord::Base scope :in_projects, ->(projects) { where(project_id: projects.map { |p| p.id }) } scope :with_user, ->(user) { where(user_id: user.id) } + after_create :post_create_hook + after_update :post_update_hook + after_destroy :post_destroy_hook + class << self # Add users to project teams with passed access option @@ -114,4 +118,37 @@ class UsersProject < ActiveRecord::Base def owner? project.owner == user end + + def post_create_hook + Event.create( + project_id: self.project.id, + action: Event::JOINED, + author_id: self.user.id + ) + + notification_service.new_team_member(self) + system_hook_service.execute_hooks_for(self, :create) + end + + def post_update_hook + notification_service.update_team_member(self) if self.project_access_changed? + end + + def post_destroy_hook + Event.create( + project_id: self.project.id, + action: Event::LEFT, + author_id: self.user.id + ) + + system_hook_service.execute_hooks_for(self, :destroy) + end + + def notification_service + NotificationService.new + end + + def system_hook_service + SystemHooksService.new + end end diff --git a/app/observers/base_observer.rb b/app/observers/base_observer.rb deleted file mode 100644 index 5a821d269a29d13b3a846f4f4b57bc9177c63b00..0000000000000000000000000000000000000000 --- a/app/observers/base_observer.rb +++ /dev/null @@ -1,17 +0,0 @@ -class BaseObserver < ActiveRecord::Observer - def notification - NotificationService.new - end - - def event_service - EventCreateService.new - end - - def log_info message - Gitlab::AppLogger.info message - end - - def system_hook_service - SystemHooksService.new - end -end diff --git a/app/observers/users_project_observer.rb b/app/observers/users_project_observer.rb deleted file mode 100644 index b0c37d1d2228acda7556da0e29bcef4e393c5404..0000000000000000000000000000000000000000 --- a/app/observers/users_project_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -class UsersProjectObserver < BaseObserver - def after_create(users_project) - Event.create( - project_id: users_project.project.id, - action: Event::JOINED, - author_id: users_project.user.id - ) - - notification.new_team_member(users_project) - system_hook_service.execute_hooks_for(users_project, :create) - end - - def after_update(users_project) - notification.update_team_member(users_project) if users_project.project_access_changed? - end - - def after_destroy(users_project) - Event.create( - project_id: users_project.project.id, - action: Event::LEFT, - author_id: users_project.user.id - ) - system_hook_service.execute_hooks_for(users_project, :destroy) - end -end diff --git a/config/application.rb b/config/application.rb index b68a4ffe347b89c9ef59359433c6186701c26bb2..0a77f58f6d1e0b035e5493b46347ade8aaaaadb6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,9 +18,6 @@ module Gitlab # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Activate observers that should always be running. - config.active_record.observers = :users_project_observer - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb index 1aba40966c471e99ec3b3ac2031d70f6c70cf3b6..82da19746f8618274e6825be36599de28e1bc8c1 100644 --- a/spec/features/admin/admin_users_spec.rb +++ b/spec/features/admin/admin_users_spec.rb @@ -47,20 +47,16 @@ describe "Admin::Users", feature: true do it "should call send mail" do Notify.should_receive(:new_user_email) - User.observers.enable :user_observer do - click_button "Create user" - end + click_button "Create user" end it "should send valid email to user with email & password" do - User.observers.enable :user_observer do - click_button "Create user" - user = User.last - email = ActionMailer::Base.deliveries.last - email.subject.should have_content("Account was created") - email.text_part.body.should have_content(user.email) - email.text_part.body.should have_content('password') - end + click_button "Create user" + user = User.last + email = ActionMailer::Base.deliveries.last + email.subject.should have_content("Account was created") + email.text_part.body.should have_content(user.email) + email.text_part.body.should have_content('password') end end diff --git a/spec/features/profile_spec.rb b/spec/features/profile_spec.rb index e8364bbb96290c395b2ae6590fcdf881aa4e6125..bdf7b59114bc787f24948e3f161c5790f0999595 100644 --- a/spec/features/profile_spec.rb +++ b/spec/features/profile_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe "Profile account page", feature: true do - before(:each) { enable_observers } - after(:each) {disable_observers} let(:user) { create(:user) } before do diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index 1e24782c39ae0f46c45e12d5fcb4edb0287492af..524c4d5fa2184a21ed97ee3f102882ac7a056975 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe "Projects", feature: true do - before(:each) { enable_observers } - after(:each) {disable_observers} before { login_as :user } describe "DELETE /projects/:id" do diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb index f12eb124296e863ea9736062183cf4ef9d00ffa3..cce9f06cb690f302a8eaa98f4bf6cd222af1caec 100644 --- a/spec/features/search_spec.rb +++ b/spec/features/search_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' describe "Search", feature: true do before do - ActiveRecord::Base.observers.enable(:user_observer) login_as :user @project = create(:project, namespace: @user.namespace) @project.team << [@user, :reporter] diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a2519fbd6846b8361dc8deebaa3b61e852b3dfce..93eae5a9ebd00a2398edd714186fcbb7aa669c86 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -27,9 +27,6 @@ require 'spec_helper' describe Project do - before { enable_observers } - after { disable_observers } - describe "Associations" do it { should belong_to(:group) } it { should belong_to(:namespace) } diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb index 47d6d861d70ed862218f25199d0fadf0e19a7977..51aaccf22673bd289220c849234c0e1ec2162bc0 100644 --- a/spec/models/system_hook_spec.rb +++ b/spec/models/system_hook_spec.rb @@ -19,8 +19,6 @@ require "spec_helper" describe SystemHook do describe "execute" do - before(:each) { ActiveRecord::Base.observers.enable(:all) } - before(:each) do @system_hook = create(:system_hook) WebMock.stub_request(:post, @system_hook.url) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4e0ebb584d115564aeaebc00772a6eb1eff1ad84..0a665b7defbe334962060810230e55aef999fd3a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -145,7 +145,6 @@ describe User do describe 'projects' do before do - ActiveRecord::Base.observers.enable(:user_observer) @user = create :user @project = create :project, namespace: @user.namespace @project_2 = create :project, group: create(:group) # Grant MASTER access to the user @@ -168,7 +167,6 @@ describe User do describe 'groups' do before do - ActiveRecord::Base.observers.enable(:user_observer) @user = create :user @group = create :group @group.add_owner(@user) @@ -181,7 +179,6 @@ describe User do describe 'group multiple owners' do before do - ActiveRecord::Base.observers.enable(:user_observer) @user = create :user @user2 = create :user @group = create :group @@ -195,7 +192,6 @@ describe User do describe 'namespaced' do before do - ActiveRecord::Base.observers.enable(:user_observer) @user = create :user @project = create :project, namespace: @user.namespace end @@ -339,7 +335,7 @@ describe User do user.all_ssh_keys.should include(key.key) end end - + describe :avatar_type do let(:user) { create(:user) } diff --git a/spec/observers/users_project_observer_spec.rb b/spec/observers/users_project_observer_spec.rb deleted file mode 100644 index b024465e8c340f1483cd9097ecd0e3a51e12f68c..0000000000000000000000000000000000000000 --- a/spec/observers/users_project_observer_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'spec_helper' - -describe UsersProjectObserver do - before(:each) { enable_observers } - after(:each) { disable_observers } - - let(:user) { create(:user) } - let(:project) { create(:project) } - subject { UsersProjectObserver.instance } - before { subject.stub(notification: double('NotificationService').as_null_object) } - - describe "#after_update" do - before do - @users_project = create :users_project - end - - it "should called when UsersProject updated" do - subject.should_receive(:after_update) - @users_project.update_attribute(:project_access, UsersProject::MASTER) - end - - it "should send email to user" do - subject.should_receive(:notification) - @users_project.update_attribute(:project_access, UsersProject::OWNER) - end - - it "should not called after UsersProject destroyed" do - subject.should_not_receive(:after_update) - @users_project.destroy - end - end - - describe "#after_destroy" do - before do - @users_project = create :users_project - end - - it "should called when UsersProject destroyed" do - subject.should_receive(:after_destroy) - @users_project.destroy - end - - it "should create new event" do - Event.should_receive(:create) - @users_project.destroy - end - end - - describe "#after_create" do - it "should send email to user" do - subject.should_receive(:notification) - Event.stub(create: true) - - create(:users_project) - end - - it "should create new event" do - Event.should_receive(:create) - - create(:users_project) - end - end -end diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 72589da5d40343eafba3ab2ba8dedd05714aaf6f..b145e620122b021440bb73977d05c78835f0c1e7 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -3,8 +3,6 @@ require 'mime/types' describe API::API, api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) {disable_observers} let(:user) { create(:user) } let(:user2) { create(:user) } diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 165276d143535c23f3520b400cc714b6ddac8136..b56269d275d475b7b21313c7a19f221890621d60 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -3,9 +3,6 @@ require 'mime/types' describe API::API, api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) {disable_observers} - let(:user) { create(:user) } let(:user2) { create(:user) } let!(:project) { create(:project, creator_id: user.id) } diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index edfe935d985bec74f9d86ed22571260a607d67e9..e84122f2fbc3ca0eb317f3c3d74b0993e66d5049 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } before { project.team << [user, :developer] } diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 8797c3fbbbf697a763bd68986c485883d7d7bb02..dbe8043c633266bb598897b42e970bf91bf8095b 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:user) { create(:user) } let(:key) { create(:key, user: user) } let(:project) { create(:project) } diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index e62bc8443529f960ece52ec16bbee5bf5ad5175b..dff7f20cb325cda83862b27263b7137f253c641b 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } let!(:issue) { create(:issue, author: user, assignee: user, project: project) } diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 2fb3684fdf0b11fcdb5e8f0330a58f2dfc86d3e3..3611d9d6dc3317d05252bb61b5782eca5c096e6d 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -2,8 +2,6 @@ require "spec_helper" describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } let(:user) { create(:user) } let!(:project) {create(:project, creator_id: user.id, namespace: user.namespace) } let!(:merge_request) { create(:merge_request, :simple, author: user, assignee: user, source_project: project, target_project: project, title: "Test") } diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index 0d2740c5acf9cb69ae593c9d0eecfd828442a155..f0619a1c80100aa9f390ec9a3a93d7712aee903c 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) {disable_observers} - let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } let!(:milestone) { create(:milestone, project: project) } @@ -92,9 +89,6 @@ describe API::API, api: true do end describe "PUT /projects/:id/milestones/:milestone_id to test observer on close" do - before { enable_observers } - after { disable_observers } - it "should create an activity event when an milestone is closed" do Event.should_receive(:create) diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb index 2de7d1e23c3c98cc3d096081479a11907cf6daca..d9d52468b15699deebe37293e65e7a090599d1b6 100644 --- a/spec/requests/api/namespaces_spec.rb +++ b/spec/requests/api/namespaces_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:admin) { create(:admin) } let!(:group1) { create(:group) } let!(:group2) { create(:group) } diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index 2875db04ee45a22fd429829ea498a4439a17357d..7aa53787aedb666c0d1311b8f140e451d2452c42 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } let!(:issue) { create(:issue, project: project, author: user) } @@ -128,14 +125,10 @@ describe API::API, api: true do end describe "POST /projects/:id/noteable/:noteable_id/notes to test observer on create" do - before { enable_observers } - after { disable_observers } - it "should create an activity event when an issue note is created" do Event.should_receive(:create) post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!' end end - end diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb index 6e281f5a43e165e1b3cdf605cba953f4b0ab6fb3..cdb5e3d061278e36dba652fd7c5028f74474db24 100644 --- a/spec/requests/api/project_hooks_spec.rb +++ b/spec/requests/api/project_hooks_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, 'ProjectHooks', api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) { disable_observers } - let(:user) { create(:user) } let(:user3) { create(:user) } let!(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } diff --git a/spec/requests/api/project_members_spec.rb b/spec/requests/api/project_members_spec.rb index 032f850010c7a46ab94f78f9f2347728d7c634ca..3c480c2ac4b8b0eed700a432d6ee11f92afb157d 100644 --- a/spec/requests/api/project_members_spec.rb +++ b/spec/requests/api/project_members_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) { disable_observers } - let(:user) { create(:user) } let(:user2) { create(:user) } let(:user3) { create(:user) } diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 415735091c353899a4786b972640979ae6d82320..41841e855fd178247da139d34a38a38a9e9c7dd1 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -2,9 +2,6 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) { disable_observers } - let(:user) { create(:user) } let(:user2) { create(:user) } let(:user3) { create(:user) } diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 5afb3bddcb7a464e2d1b948a999ee94c1c680917..94850d0f1aea71c80daa74656f091b725a86f4bd 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -3,9 +3,6 @@ require 'mime/types' describe API::API, api: true do include ApiHelpers - before(:each) { enable_observers } - after(:each) {disable_observers} - let(:user) { create(:user) } let(:user2) { create(:user) } let!(:project) { create(:project, creator_id: user.id) } diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 684f8615999ffa1ae09b12c5c29beb26842f2cc4..f883c9e028ad9a87739a15ff3f8033ebb29a2bcc 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -2,9 +2,6 @@ require "spec_helper" describe API::API, api: true do include ApiHelpers - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:user) { create(:user) } let(:project) {create(:project, creator_id: user.id, namespace: user.namespace) } diff --git a/spec/services/issues/bulk_update_context_spec.rb b/spec/services/issues/bulk_update_context_spec.rb index 548109a845030c7d651c0b024fbe3d1a0c890abc..f4c9148f1a37bcc4e0e74beb51eedd97c50ff07a 100644 --- a/spec/services/issues/bulk_update_context_spec.rb +++ b/spec/services/issues/bulk_update_context_spec.rb @@ -1,12 +1,9 @@ require 'spec_helper' describe Issues::BulkUpdateService do - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - let(:issue) { create(:issue, project: @project) - } + } before do @user = create :user @@ -23,7 +20,7 @@ describe Issues::BulkUpdateService do @issues = 5.times.collect do create(:issue, project: @project) end - @params = { + @params = { update: { status: 'closed', issues_ids: @issues.map(&:id) @@ -48,7 +45,7 @@ describe Issues::BulkUpdateService do @issues = 5.times.collect do create(:closed_issue, project: @project) end - @params = { + @params = { update: { status: 'reopen', issues_ids: @issues.map(&:id) @@ -71,7 +68,7 @@ describe Issues::BulkUpdateService do before do @new_assignee = create :user - @params = { + @params = { update: { issues_ids: [issue.id], assignee_id: @new_assignee.id @@ -93,7 +90,7 @@ describe Issues::BulkUpdateService do before do @milestone = create :milestone - @params = { + @params = { update: { issues_ids: [issue.id], milestone_id: @milestone.id diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb index 0eac6bed74b973c6e6289ea834d6b7c4fc036a7f..3dac0539031c1cfd6ad5f4c8d585007b750b8a80 100644 --- a/spec/services/projects/create_service_spec.rb +++ b/spec/services/projects/create_service_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper' describe Projects::CreateService do - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - describe :create_by_user do before do @user = create :user diff --git a/spec/services/projects/image_service_spec.rb b/spec/services/projects/image_service_spec.rb index 070c21698cf5fc303cf2801c58f0ca175ca95db7..23c4e227ae303ed6534eeb591650ba3e1b7cc6f5 100644 --- a/spec/services/projects/image_service_spec.rb +++ b/spec/services/projects/image_service_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper' describe Projects::ImageService do - before(:each) { enable_observers } - after(:each) { disable_observers } - describe 'Image service' do before do @user = create :user diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 563a8b0c01c658bd90725734da1fd65cb1ba9683..2508dfc45654622ddfa19f37abf6f002ff7d7159 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper' describe Projects::TransferService do - before(:each) { enable_observers } - after(:each) {disable_observers} - let(:user) { create(:user) } let(:group) { create(:group) } let(:group2) { create(:group) } diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index 1854c0d82339e9df02f3eac242fd8e7e1ef92fef..bb0470e3771a592d822b18d3d42020dbfc402f44 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -1,9 +1,6 @@ require 'spec_helper' describe Projects::UpdateService do - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - describe :update_by_user do before do @user = create :user diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 65a641bcf12884d8a837d3e804f6a16ed87fcbd1..2181238ae9f9ef47812ad20f5442d5f046799e6d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,7 +43,7 @@ RSpec.configure do |config| # instead of true. config.before(:suite) do - TestEnv.init(observers: false, init_repos: true, repos: false) + TestEnv.init(init_repos: true, repos: false) end config.before(:each) do TestEnv.setup_stubs diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb index cc0ec2f4e3d60d7484e03c23aaa0c542f86fd05d..7713e9f17d7257179896c9628c110686c0aa00e3 100644 --- a/spec/support/login_helpers.rb +++ b/spec/support/login_helpers.rb @@ -3,9 +3,7 @@ module LoginHelpers # # role - User role (e.g., :admin, :user) def login_as(role) - ActiveRecord::Base.observers.enable(:user_observer) do - @user = create(role) - end + @user = create(role) login_with(@user) end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index b1bb65a836e34fef5fc5680b60b87d387d140d52..85059dfa9e98577aca4a14ac3084253b973a2f25 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -17,14 +17,6 @@ module TestEnv def init(opts = {}) RSpec::Mocks::setup(self) - # Disable observers to improve test speed - # - # You can enable it in whole test case where needed by next string: - # - # before(:each) { enable_observers } - # - disable_observers if opts[:observers] == false - # Disable mailer for spinach tests disable_mailer if opts[:mailer] == false setup_stubs @@ -33,14 +25,6 @@ module TestEnv setup_test_repos(opts) if opts[:repos] == true end - def enable_observers - ActiveRecord::Base.observers.enable(:all) - end - - def disable_observers - ActiveRecord::Base.observers.disable(:all) - end - def disable_mailer NotificationService.any_instance.stub(mailer: double.as_null_object) end @@ -89,10 +73,6 @@ module TestEnv Repository.any_instance.stub( size: 12.45 ) - - BaseObserver.any_instance.stub( - current_user: double("current_user", id: 1) - ) end def clear_repo_dir(namespace, name)