macros_examples.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. RSpec.shared_examples 'macros' do |path:|
  2. let!(:group1) { create :group }
  3. let!(:group2) { create :group }
  4. let!(:macro_without_group) { create :macro }
  5. let!(:macro_group1) { create :macro, groups: [group1] }
  6. let!(:macro_group2) { create :macro, groups: [group2] }
  7. it 'supports group-dependent macros' do
  8. # give user access to all groups including those created
  9. # by using FactoryBot outside of the example
  10. group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result|
  11. result[group_name] = 'full'.freeze
  12. end
  13. current_user do |user|
  14. user.group_names_access_map = group_names_access_map
  15. user.save!
  16. end
  17. # refresh browser to get macro accessable
  18. refresh
  19. visit path
  20. within(:active_content) do
  21. # select group
  22. find('select[name="group_id"]').select(group1.name)
  23. open_macro_list
  24. expect(page).to have_selector(:macro, macro_without_group.id)
  25. expect(page).to have_selector(:macro, macro_group1.id)
  26. expect(page).to have_no_selector(:macro, macro_group2.id)
  27. # select group
  28. find('select[name="group_id"]').select(group2.name)
  29. open_macro_list
  30. expect(page).to have_selector(:macro, macro_without_group.id)
  31. expect(page).to have_no_selector(:macro, macro_group1.id)
  32. expect(page).to have_selector(:macro, macro_group2.id)
  33. end
  34. end
  35. end