Merge pull request #1364 from AlexDenisov/fix_project_access_notification
Project access notifications fixed
This commit is contained in:
commit
16e67fd8be
4 changed files with 27 additions and 17 deletions
1
Gemfile
1
Gemfile
|
@ -138,6 +138,7 @@ group :test do
|
||||||
gem 'email_spec'
|
gem 'email_spec'
|
||||||
gem 'resque_spec'
|
gem 'resque_spec'
|
||||||
gem "webmock"
|
gem "webmock"
|
||||||
|
gem 'test_after_commit'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :production do
|
group :production do
|
||||||
|
|
|
@ -377,6 +377,7 @@ GEM
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
sqlite3 (1.3.6)
|
sqlite3 (1.3.6)
|
||||||
stamp (0.1.6)
|
stamp (0.1.6)
|
||||||
|
test_after_commit (0.0.1)
|
||||||
therubyracer (0.10.1)
|
therubyracer (0.10.1)
|
||||||
libv8 (~> 3.3.10)
|
libv8 (~> 3.3.10)
|
||||||
thin (1.3.1)
|
thin (1.3.1)
|
||||||
|
@ -476,6 +477,7 @@ DEPENDENCIES
|
||||||
spinach-rails
|
spinach-rails
|
||||||
sqlite3
|
sqlite3
|
||||||
stamp
|
stamp
|
||||||
|
test_after_commit
|
||||||
therubyracer
|
therubyracer
|
||||||
thin
|
thin
|
||||||
uglifier (= 1.0.3)
|
uglifier (= 1.0.3)
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
class UsersProjectObserver < ActiveRecord::Observer
|
class UsersProjectObserver < ActiveRecord::Observer
|
||||||
def after_create(users_project)
|
def after_commit(users_project)
|
||||||
|
return if users_project.destroyed?
|
||||||
Notify.project_access_granted_email(users_project.id).deliver
|
Notify.project_access_granted_email(users_project.id).deliver
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_create(users_project)
|
||||||
Event.create(
|
Event.create(
|
||||||
project_id: users_project.project.id,
|
project_id: users_project.project.id,
|
||||||
action: Event::Joined,
|
action: Event::Joined,
|
||||||
|
@ -9,10 +12,6 @@ class UsersProjectObserver < ActiveRecord::Observer
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_update(users_project)
|
|
||||||
Notify.project_access_granted_email(users_project.id).deliver
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_destroy(users_project)
|
def after_destroy(users_project)
|
||||||
Event.create(
|
Event.create(
|
||||||
project_id: users_project.project.id,
|
project_id: users_project.project.id,
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe UsersProjectObserver do
|
describe UsersProjectObserver do
|
||||||
let(:users_project) { stub.as_null_object }
|
let(:user) { Factory.create :user }
|
||||||
|
let(:project) { Factory.create(:project,
|
||||||
|
code: "Fuu",
|
||||||
|
path: "Fuu" ) }
|
||||||
|
let(:users_project) { Factory.create(:users_project,
|
||||||
|
project: project,
|
||||||
|
user: user )}
|
||||||
subject { UsersProjectObserver.instance }
|
subject { UsersProjectObserver.instance }
|
||||||
|
|
||||||
describe "#after_create" do
|
describe "#after_commit" do
|
||||||
it "should called when UsersProject created" do
|
it "should called when UsersProject created" do
|
||||||
subject.should_receive(:after_create)
|
subject.should_receive(:after_commit).once
|
||||||
|
|
||||||
UsersProject.observers.enable :users_project_observer do
|
UsersProject.observers.enable :users_project_observer do
|
||||||
create(:users_project)
|
create(:users_project)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should send email to user" do
|
it "should send email to user" do
|
||||||
|
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
|
||||||
|
subject.after_commit(users_project)
|
||||||
Event.stub(:create => true)
|
Event.stub(:create => true)
|
||||||
Notify.should_receive(:project_access_granted_email).and_return(stub(deliver: true))
|
|
||||||
|
|
||||||
subject.after_create(users_project)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create new event" do
|
it "should create new event" do
|
||||||
|
@ -33,17 +37,21 @@ describe UsersProjectObserver do
|
||||||
|
|
||||||
describe "#after_update" do
|
describe "#after_update" do
|
||||||
it "should called when UsersProject updated" do
|
it "should called when UsersProject updated" do
|
||||||
subject.should_receive(:after_update)
|
subject.should_receive(:after_commit).once
|
||||||
|
|
||||||
UsersProject.observers.enable :users_project_observer do
|
UsersProject.observers.enable :users_project_observer do
|
||||||
create(:users_project).update_attribute(:project_access, 40)
|
create(:users_project).update_attribute(:project_access, UsersProject::MASTER)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should send email to user" do
|
it "should send email to user" do
|
||||||
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
|
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
|
||||||
|
subject.after_commit(users_project)
|
||||||
subject.after_update(users_project)
|
end
|
||||||
|
it "should not called after UsersProject destroyed" do
|
||||||
|
subject.should_not_receive(:after_commit)
|
||||||
|
UsersProject.observers.enable :users_project_observer do
|
||||||
|
users_project.destroy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue