diff options
Diffstat (limited to 'spec/models/operations')
-rw-r--r-- | spec/models/operations/feature_flag_spec.rb | 34 | ||||
-rw-r--r-- | spec/models/operations/feature_flags/user_list_spec.rb | 19 |
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/operations/feature_flag_spec.rb b/spec/models/operations/feature_flag_spec.rb index b4e941f2856..93dd7d4f0bb 100644 --- a/spec/models/operations/feature_flag_spec.rb +++ b/spec/models/operations/feature_flag_spec.rb @@ -261,4 +261,38 @@ RSpec.describe Operations::FeatureFlag do expect(flags.map(&:id)).to eq([feature_flag.id, feature_flag_b.id]) end end + + describe '#hook_attrs' do + it 'includes expected attributes' do + hook_attrs = { + id: subject.id, + name: subject.name, + description: subject.description, + active: subject.active + } + expect(subject.hook_attrs).to eq(hook_attrs) + end + end + + describe "#execute_hooks" do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:feature_flag) { create(:operations_feature_flag, project: project) } + + it 'does not execute the hook when feature_flag event is disabled' do + create(:project_hook, project: project, feature_flag_events: false) + expect(WebHookWorker).not_to receive(:perform_async) + + feature_flag.execute_hooks(user) + feature_flag.touch + end + + it 'executes hook when feature_flag event is enabled' do + hook = create(:project_hook, project: project, feature_flag_events: true) + expect(WebHookWorker).to receive(:perform_async).with(hook.id, an_instance_of(Hash), 'feature_flag_hooks') + + feature_flag.execute_hooks(user) + feature_flag.touch + end + end end diff --git a/spec/models/operations/feature_flags/user_list_spec.rb b/spec/models/operations/feature_flags/user_list_spec.rb index 020416aa7bc..3a48d3389a3 100644 --- a/spec/models/operations/feature_flags/user_list_spec.rb +++ b/spec/models/operations/feature_flags/user_list_spec.rb @@ -92,6 +92,25 @@ RSpec.describe Operations::FeatureFlags::UserList do end end + describe '.for_name_like' do + let_it_be(:project) { create(:project) } + let_it_be(:user_list_one) { create(:operations_feature_flag_user_list, project: project, name: 'one') } + let_it_be(:user_list_two) { create(:operations_feature_flag_user_list, project: project, name: 'list_two') } + let_it_be(:user_list_three) { create(:operations_feature_flag_user_list, project: project, name: 'list_three') } + + it 'returns a found name' do + lists = project.operations_feature_flags_user_lists.for_name_like('list') + + expect(lists).to contain_exactly(user_list_two, user_list_three) + end + + it 'returns an empty array when no lists match the query' do + lists = project.operations_feature_flags_user_lists.for_name_like('no match') + + expect(lists).to be_empty + end + end + it_behaves_like 'AtomicInternalId' do let(:internal_id_attribute) { :iid } let(:instance) { build(:operations_feature_flag_user_list) } |