Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/hooks/web_hook_spec.rb')
-rw-r--r--spec/models/hooks/web_hook_spec.rb81
1 files changed, 69 insertions, 12 deletions
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index da8c10b67a6..dd5bf8b99dd 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -113,24 +113,81 @@ RSpec.describe WebHook do
end
describe 'push_events_branch_filter' do
- it { is_expected.to allow_values("good_branch_name", "another/good-branch_name").for(:push_events_branch_filter) }
- it { is_expected.to allow_values("").for(:push_events_branch_filter) }
- it { is_expected.not_to allow_values("bad branch name", "bad~branchname").for(:push_events_branch_filter) }
-
- it 'gets rid of whitespace' do
- hook.push_events_branch_filter = ' branch '
- hook.save!
+ before do
+ subject.branch_filter_strategy = strategy
+ end
+
+ context 'with "all branches" strategy' do
+ let(:strategy) { 'all_branches' }
+
+ it {
+ is_expected.to allow_values(
+ "good_branch_name",
+ "another/good-branch_name",
+ "good branch name",
+ "good~branchname",
+ "good_branchname(",
+ "good_branchname[",
+ ""
+ ).for(:push_events_branch_filter)
+ }
+ end
+
+ context 'with "wildcard" strategy' do
+ let(:strategy) { 'wildcard' }
+
+ it {
+ is_expected.to allow_values(
+ "good_branch_name",
+ "another/good-branch_name",
+ "good_branch_name(",
+ ""
+ ).for(:push_events_branch_filter)
+ }
+
+ it {
+ is_expected.not_to allow_values(
+ "bad branch name",
+ "bad~branchname",
+ "bad_branch_name["
+ ).for(:push_events_branch_filter)
+ }
+
+ it 'gets rid of whitespace' do
+ hook.push_events_branch_filter = ' branch '
+ hook.save!
+
+ expect(hook.push_events_branch_filter).to eq('branch')
+ end
- expect(hook.push_events_branch_filter).to eq('branch')
+ it 'stores whitespace only as empty' do
+ hook.push_events_branch_filter = ' '
+ hook.save!
+ expect(hook.push_events_branch_filter).to eq('')
+ end
end
- it 'stores whitespace only as empty' do
- hook.push_events_branch_filter = ' '
- hook.save!
+ context 'with "regex" strategy' do
+ let(:strategy) { 'regex' }
+
+ it {
+ is_expected.to allow_values(
+ "good_branch_name",
+ "another/good-branch_name",
+ "good branch name",
+ "good~branch~name",
+ ""
+ ).for(:push_events_branch_filter)
+ }
- expect(hook.push_events_branch_filter).to eq('')
+ it { is_expected.not_to allow_values("bad_branch_name(", "bad_branch_name[").for(:push_events_branch_filter) }
end
end
+
+ it "only consider these branch filter strategies are valid" do
+ expected_valid_types = %w[all_branches regex wildcard]
+ expect(described_class.branch_filter_strategies.keys).to contain_exactly(*expected_valid_types)
+ end
end
describe 'encrypted attributes' do