2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-03-05 14:44:01 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ProjectHook do
|
2017-07-20 11:12:06 -04:00
|
|
|
describe 'associations' do
|
2016-02-22 07:55:36 -05:00
|
|
|
it { is_expected.to belong_to :project }
|
|
|
|
end
|
|
|
|
|
2017-07-20 11:12:06 -04:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
end
|
|
|
|
|
2020-04-22 11:09:27 -04:00
|
|
|
it_behaves_like 'includes Limitable concern' do
|
|
|
|
subject { build(:project_hook, project: create(:project)) }
|
|
|
|
end
|
|
|
|
|
2014-03-05 14:44:01 -05:00
|
|
|
describe '.push_hooks' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns hooks for push events only' do
|
2014-03-05 14:44:01 -05:00
|
|
|
hook = create(:project_hook, push_events: true)
|
2015-10-03 02:48:54 -04:00
|
|
|
create(:project_hook, push_events: false)
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.push_hooks).to eq([hook])
|
2014-03-05 14:44:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.tag_push_hooks' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns hooks for tag push events only' do
|
2014-03-05 14:44:01 -05:00
|
|
|
hook = create(:project_hook, tag_push_events: true)
|
2015-10-03 02:48:54 -04:00
|
|
|
create(:project_hook, tag_push_events: false)
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.tag_push_hooks).to eq([hook])
|
2014-03-05 14:44:01 -05:00
|
|
|
end
|
|
|
|
end
|
2021-05-14 05:10:24 -04:00
|
|
|
|
|
|
|
describe '#rate_limit' do
|
|
|
|
let_it_be(:hook) { create(:project_hook) }
|
|
|
|
let_it_be(:plan_limits) { create(:plan_limits, :default_plan, web_hook_calls: 100) }
|
|
|
|
|
|
|
|
it 'returns the default limit' do
|
|
|
|
expect(hook.rate_limit).to be(100)
|
|
|
|
end
|
|
|
|
end
|
2021-05-20 08:10:26 -04:00
|
|
|
|
|
|
|
describe '#application_context' do
|
|
|
|
let_it_be(:hook) { build(:project_hook) }
|
|
|
|
|
|
|
|
it 'includes the type and project' do
|
|
|
|
expect(hook.application_context).to include(
|
|
|
|
related_class: 'ProjectHook',
|
|
|
|
project: hook.project
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2014-03-05 14:44:01 -05:00
|
|
|
end
|