2013-02-20 05:53:15 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe SystemHooksService, services: true do
|
2015-06-22 08:39:07 -04:00
|
|
|
let(:user) { create :user }
|
|
|
|
let(:project) { create :project }
|
|
|
|
let(:project_member) { create :project_member }
|
|
|
|
let(:key) { create(:key, user: user) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_member) { create(:group_member) }
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
context 'event data' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_data(user, :create)).to include(:event_name, :name, :created_at, :email, :user_id) }
|
|
|
|
it { expect(event_data(user, :destroy)).to include(:event_name, :name, :created_at, :email, :user_id) }
|
|
|
|
it { expect(event_data(project, :create)).to include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
|
|
|
it { expect(event_data(project, :destroy)).to include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2015-09-12 16:53:18 -04:00
|
|
|
it { expect(event_data(project_member, :create)).to include(:event_name, :created_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_name, :user_email, :access_level, :project_visibility) }
|
|
|
|
it { expect(event_data(project_member, :destroy)).to include(:event_name, :created_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_name, :user_email, :access_level, :project_visibility) }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_data(key, :create)).to include(:username, :key, :id) }
|
|
|
|
it { expect(event_data(key, :destroy)).to include(:username, :key, :id) }
|
2014-08-21 06:53:32 -04:00
|
|
|
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group, :create)).to include(
|
2014-08-21 06:53:32 -04:00
|
|
|
:event_name, :name, :created_at, :path, :group_id, :owner_name,
|
|
|
|
:owner_email
|
|
|
|
)
|
|
|
|
end
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group, :destroy)).to include(
|
2014-08-21 06:53:32 -04:00
|
|
|
:event_name, :name, :created_at, :path, :group_id, :owner_name,
|
|
|
|
:owner_email
|
|
|
|
)
|
|
|
|
end
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group_member, :create)).to include(
|
2014-08-21 06:53:32 -04:00
|
|
|
:event_name, :created_at, :group_name, :group_path, :group_id, :user_id,
|
|
|
|
:user_name, :user_email, :group_access
|
|
|
|
)
|
|
|
|
end
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group_member, :destroy)).to include(
|
2014-08-21 06:53:32 -04:00
|
|
|
:event_name, :created_at, :group_name, :group_path, :group_id, :user_id,
|
|
|
|
:user_name, :user_email, :group_access
|
|
|
|
)
|
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
context 'event names' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(user, :create)).to eq "user_create" }
|
|
|
|
it { expect(event_name(user, :destroy)).to eq "user_destroy" }
|
|
|
|
it { expect(event_name(project, :create)).to eq "project_create" }
|
|
|
|
it { expect(event_name(project, :destroy)).to eq "project_destroy" }
|
|
|
|
it { expect(event_name(project_member, :create)).to eq "user_add_to_team" }
|
|
|
|
it { expect(event_name(project_member, :destroy)).to eq "user_remove_from_team" }
|
|
|
|
it { expect(event_name(key, :create)).to eq 'key_create' }
|
|
|
|
it { expect(event_name(key, :destroy)).to eq 'key_destroy' }
|
|
|
|
it { expect(event_name(group, :create)).to eq 'group_create' }
|
|
|
|
it { expect(event_name(group, :destroy)).to eq 'group_destroy' }
|
|
|
|
it { expect(event_name(group_member, :create)).to eq 'user_add_to_group' }
|
|
|
|
it { expect(event_name(group_member, :destroy)).to eq 'user_remove_from_group' }
|
2013-10-08 04:06:38 -04:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
def event_data(*args)
|
2014-01-15 07:26:05 -05:00
|
|
|
SystemHooksService.new.send :build_event_data, *args
|
2013-10-08 04:06:38 -04:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
def event_name(*args)
|
2014-01-15 07:26:05 -05:00
|
|
|
SystemHooksService.new.send :build_event_name, *args
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
end
|