2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-09-04 07:42:50 +00:00
|
|
|
RSpec.shared_examples 'macros' do |path:|
|
|
|
|
|
|
|
|
let!(:group1) { create :group }
|
|
|
|
let!(:group2) { create :group }
|
|
|
|
let!(:macro_without_group) { create :macro }
|
|
|
|
let!(:macro_group1) { create :macro, groups: [group1] }
|
|
|
|
let!(:macro_group2) { create :macro, groups: [group2] }
|
|
|
|
|
|
|
|
it 'supports group-dependent macros' do
|
|
|
|
|
|
|
|
# give user access to all groups including those created
|
|
|
|
# by using FactoryBot outside of the example
|
2021-06-23 11:35:27 +00:00
|
|
|
group_names_access_map = Group.all.pluck(:name).index_with do |_group_name|
|
|
|
|
'full'.freeze
|
2019-09-04 07:42:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
current_user do |user|
|
|
|
|
user.group_names_access_map = group_names_access_map
|
|
|
|
user.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
# refresh browser to get macro accessable
|
|
|
|
refresh
|
|
|
|
visit path
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
|
|
|
|
# select group
|
|
|
|
find('select[name="group_id"]').select(group1.name)
|
|
|
|
|
|
|
|
open_macro_list
|
|
|
|
expect(page).to have_selector(:macro, macro_without_group.id)
|
|
|
|
expect(page).to have_selector(:macro, macro_group1.id)
|
|
|
|
expect(page).to have_no_selector(:macro, macro_group2.id)
|
|
|
|
|
|
|
|
# select group
|
|
|
|
find('select[name="group_id"]').select(group2.name)
|
|
|
|
|
|
|
|
open_macro_list
|
|
|
|
expect(page).to have_selector(:macro, macro_without_group.id)
|
|
|
|
expect(page).to have_no_selector(:macro, macro_group1.id)
|
|
|
|
expect(page).to have_selector(:macro, macro_group2.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|