diff options
Diffstat (limited to 'spec/models/broadcast_message_spec.rb')
| -rw-r--r-- | spec/models/broadcast_message_spec.rb | 54 |
1 files changed, 3 insertions, 51 deletions
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 3a072cfe2ec..d981189c6f1 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -23,8 +23,6 @@ RSpec.describe BroadcastMessage do it { is_expected.to allow_value(1).for(:broadcast_type) } it { is_expected.not_to allow_value(nil).for(:broadcast_type) } - it { is_expected.not_to allow_value(nil).for(:target_access_levels) } - it { is_expected.to validate_inclusion_of(:target_access_levels).in_array(described_class::ALLOWED_TARGET_ACCESS_LEVELS) } end shared_examples 'time constrainted' do |broadcast_type| @@ -177,48 +175,12 @@ RSpec.describe BroadcastMessage do end end - shared_examples "matches with user access level" do |broadcast_type| - context 'when target_access_levels is empty' do - let_it_be(:message) { create(:broadcast_message, target_access_levels: [], broadcast_type: broadcast_type) } - - it 'returns the message if user access level is not nil' do - expect(subject.call(nil, Gitlab::Access::MINIMAL_ACCESS)).to include(message) - end - - it 'returns the message if user access level is nil' do - expect(subject.call(nil, nil)).to include(message) - end - end - - context 'when target_access_levels is not empty' do - let_it_be(:target_access_levels) { [Gitlab::Access::GUEST] } - let_it_be(:message) { create(:broadcast_message, target_access_levels: target_access_levels, broadcast_type: broadcast_type) } - - it "does not return the message if user access level is nil" do - expect(subject.call(nil, nil)).to be_empty - end - - it "returns the message if user access level is in target_access_levels" do - expect(subject.call(nil, Gitlab::Access::GUEST)).to include(message) - end - - it "does not return the message if user access level is not in target_access_levels" do - expect(subject.call(nil, Gitlab::Access::MINIMAL_ACCESS)).to be_empty - end - end - end - describe '.current', :use_clean_rails_memory_store_caching do - subject do - -> (path = nil, user_access_level = nil) do - described_class.current(current_path: path, user_access_level: user_access_level) - end - end + subject { -> (path = nil) { described_class.current(path) } } it_behaves_like 'time constrainted', :banner it_behaves_like 'message cache', :banner it_behaves_like 'matches with current path', :banner - it_behaves_like 'matches with user access level', :banner it 'returns both types' do banner_message = create(:broadcast_message, broadcast_type: :banner) @@ -229,16 +191,11 @@ RSpec.describe BroadcastMessage do end describe '.current_banner_messages', :use_clean_rails_memory_store_caching do - subject do - -> (path = nil, user_access_level = nil) do - described_class.current_banner_messages(current_path: path, user_access_level: user_access_level) - end - end + subject { -> (path = nil) { described_class.current_banner_messages(path) } } it_behaves_like 'time constrainted', :banner it_behaves_like 'message cache', :banner it_behaves_like 'matches with current path', :banner - it_behaves_like 'matches with user access level', :banner it 'only returns banners' do banner_message = create(:broadcast_message, broadcast_type: :banner) @@ -249,16 +206,11 @@ RSpec.describe BroadcastMessage do end describe '.current_notification_messages', :use_clean_rails_memory_store_caching do - subject do - -> (path = nil, user_access_level = nil) do - described_class.current_notification_messages(current_path: path, user_access_level: user_access_level) - end - end + subject { -> (path = nil) { described_class.current_notification_messages(path) } } it_behaves_like 'time constrainted', :notification it_behaves_like 'message cache', :notification it_behaves_like 'matches with current path', :notification - it_behaves_like 'matches with user access level', :notification it 'only returns notifications' do notification_message = create(:broadcast_message, broadcast_type: :notification) |
