GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit 2d875568 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove rails observers from application

parent a90a201d
......@@ -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'
......
......@@ -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)
......
......@@ -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 @@ def access_field
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
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
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
......@@ -18,9 +18,6 @@ class Application < Rails::Application
# :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)'
......
......@@ -47,20 +47,16 @@
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
......
require 'spec_helper'
describe "Profile account page", feature: true do
before(:each) { enable_observers }
after(:each) {disable_observers}
let(:user) { create(:user) }
before do
......
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
......
......@@ -2,7 +2,6 @@
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]
......
......@@ -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) }
......
......@@ -19,8 +19,6 @@
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)
......
......@@ -145,7 +145,6 @@
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 '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 '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 'namespaced' do
before do
ActiveRecord::Base.observers.enable(:user_observer)
@user = create :user
@project = create :project, namespace: @user.namespace
end
......@@ -339,7 +335,7 @@
user.all_ssh_keys.should include(key.key)
end
end
describe :avatar_type do
let(:user) { create(:user) }
......
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
......@@ -3,8 +3,6 @@
describe API::API, api: true do
include ApiHelpers
before(:each) { enable_observers }
after(:each) {disable_observers}
let(:user) { create(:user) }
let(:user2) { create(:user) }
......
......@@ -3,9 +3,6 @@
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) }
......
......@@ -2,9 +2,6 @@
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] }
......
......@@ -2,9 +2,6 @@
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) }
......
......@@ -2,9 +2,6 @@
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) }
......
......@@ -2,8 +2,6 @@
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") }
......
......@@ -2,9 +2,6 @@
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 @@
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)
......
......@@ -2,9 +2,6 @@
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) }
......
......@@ -2,9 +2,6 @@
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 @@
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
......@@ -2,9 +2,6 @@
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) }
......
......@@ -2,9 +2,6 @@
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) }
......
......@@ -2,9 +2,6 @@
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) }
......
......@@ -3,9 +3,6 @@
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) }
......
......@@ -2,9 +2,6 @@
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) }
......
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 @@
@issues = 5.times.collect do
create(:issue, project: @project)
end
@params = {
@params = {
update: {
status: 'closed',
issues_ids: @issues.map(&:id)
......@@ -48,7 +45,7 @@
@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 @@
before do
@new_assignee = create :user
@params = {
@params = {
update: {
issues_ids: [issue.id],
assignee_id: @new_assignee.id
......@@ -93,7 +90,7 @@
before do
@milestone = create :milestone
@params = {
@params = {
update: {
issues_ids: [issue.id],
milestone_id: @milestone.id
......
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
......
require 'spec_helper'
describe Projects::ImageService do
before(:each) { enable_observers }
after(:each) { disable_observers }
describe 'Image service' do
before do
@user = create :user
......
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) }
......
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
......
......@@ -43,7 +43,7 @@
# 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
......
......@@ -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
......
......@@ -17,14 +17,6 @@ module TestEnv
def init(opts = {})
RSpec::Mocks::setup(self)