gitlab-org--gitlab-foss/spec/observers/users_project_observer_spec.rb

75 lines
2.2 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe UsersProjectObserver do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:users_project) { create(:users_project,
project: project,
user: user )}
subject { UsersProjectObserver.instance }
2012-09-03 14:46:17 -04:00
describe "#after_commit" do
it "should called when UsersProject created" do
2012-09-03 14:46:17 -04:00
subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
2012-09-14 18:00:59 -04:00
create(:users_project)
end
end
2012-09-14 18:00:59 -04:00
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
2012-09-03 13:48:38 -04:00
subject.after_commit(users_project)
2012-09-14 18:00:59 -04:00
Event.stub(:create => true)
end
2012-09-14 18:00:59 -04:00
2012-09-09 16:18:28 -04:00
it "should create new event" do
Event.should_receive(:create).with(
2012-09-14 18:00:59 -04:00
project_id: users_project.project.id,
action: Event::Joined,
2012-09-09 16:18:28 -04:00
author_id: users_project.user.id
)
2012-09-14 18:00:59 -04:00
2012-09-09 16:18:28 -04:00
subject.after_create(users_project)
end
end
describe "#after_update" do
it "should called when UsersProject updated" do
2012-09-03 14:46:17 -04:00
subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
2012-09-20 03:25:29 -04:00
create(:users_project).update_attribute(:project_access, UsersProject::MASTER)
end
end
2012-09-14 18:00:59 -04:00
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
2012-09-03 13:48:38 -04:00
subject.after_commit(users_project)
end
2012-09-03 14:46:17 -04:00
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
2012-09-14 18:00:59 -04:00
2012-09-09 17:27:47 -04:00
describe "#after_destroy" do
it "should called when UsersProject destroyed" do
subject.should_receive(:after_destroy)
2012-09-14 18:00:59 -04:00
2012-09-09 17:27:47 -04:00
UsersProject.observers.enable :users_project_observer do
2012-09-14 18:00:59 -04:00
create(:users_project).destroy
2012-09-09 17:27:47 -04:00
end
end
2012-09-14 18:00:59 -04:00
2012-09-09 17:27:47 -04:00
it "should create new event" do
Event.should_receive(:create).with(
2012-09-14 18:00:59 -04:00
project_id: users_project.project.id,
action: Event::Left,
2012-09-09 17:27:47 -04:00
author_id: users_project.user.id
)
subject.after_destroy(users_project)
end
end
end