diff options
Diffstat (limited to 'spec/helpers/groups_helper_spec.rb')
-rw-r--r-- | spec/helpers/groups_helper_spec.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 037b16c90ed..98719697cea 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -262,4 +262,44 @@ describe GroupsHelper do expect(parent_group_options(group2)).to eq([{ id: group.id, text: group.human_name }].to_json) end end + + describe '#can_disable_group_emails?' do + let(:current_user) { create(:user) } + let(:group) { create(:group, name: 'group') } + let(:subgroup) { create(:group, name: 'subgroup', parent: group) } + + before do + allow(helper).to receive(:current_user) { current_user } + end + + it 'returns true for the group owner' do + allow(helper).to receive(:can?).with(current_user, :set_emails_disabled, group) { true } + + expect(helper.can_disable_group_emails?(group)).to be_truthy + end + + it 'returns false for anyone else' do + allow(helper).to receive(:can?).with(current_user, :set_emails_disabled, group) { false } + + expect(helper.can_disable_group_emails?(group)).to be_falsey + end + + context 'when subgroups' do + before do + allow(helper).to receive(:can?).with(current_user, :set_emails_disabled, subgroup) { true } + end + + it 'returns false if parent group is disabling emails' do + allow(group).to receive(:emails_disabled?).and_return(true) + + expect(helper.can_disable_group_emails?(subgroup)).to be_falsey + end + + it 'returns true if parent group is not disabling emails' do + allow(group).to receive(:emails_disabled?).and_return(false) + + expect(helper.can_disable_group_emails?(subgroup)).to be_truthy + end + end + end end |