1
0

scope_transformer_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ScopeTransformer do
  4. describe '#apply' do
  5. subject { described_class.new.apply(ScopeParser.new.parse(input)) }
  6. shared_examples 'a scope' do |namespace, term, access|
  7. it 'parses the attributes' do
  8. expect(subject)
  9. .to have_attributes(
  10. term: term,
  11. namespace: namespace,
  12. access: access
  13. )
  14. end
  15. end
  16. context 'with scope "profile"' do
  17. let(:input) { 'profile' }
  18. it_behaves_like 'a scope', nil, 'profile', 'read'
  19. end
  20. context 'with scope "read"' do
  21. let(:input) { 'read' }
  22. it_behaves_like 'a scope', nil, 'all', 'read'
  23. end
  24. context 'with scope "write"' do
  25. let(:input) { 'write' }
  26. it_behaves_like 'a scope', nil, 'all', 'write'
  27. end
  28. context 'with scope "follow"' do
  29. let(:input) { 'follow' }
  30. it_behaves_like 'a scope', nil, 'follow', 'read/write'
  31. end
  32. context 'with scope "crypto"' do
  33. let(:input) { 'crypto' }
  34. it_behaves_like 'a scope', nil, 'crypto', 'read/write'
  35. end
  36. context 'with scope "push"' do
  37. let(:input) { 'push' }
  38. it_behaves_like 'a scope', nil, 'push', 'read/write'
  39. end
  40. context 'with scope "admin:read"' do
  41. let(:input) { 'admin:read' }
  42. it_behaves_like 'a scope', 'admin', 'all', 'read'
  43. end
  44. context 'with scope "admin:write"' do
  45. let(:input) { 'admin:write' }
  46. it_behaves_like 'a scope', 'admin', 'all', 'write'
  47. end
  48. context 'with scope "admin:read:accounts"' do
  49. let(:input) { 'admin:read:accounts' }
  50. it_behaves_like 'a scope', 'admin', 'accounts', 'read'
  51. end
  52. context 'with scope "admin:write:accounts"' do
  53. let(:input) { 'admin:write:accounts' }
  54. it_behaves_like 'a scope', 'admin', 'accounts', 'write'
  55. end
  56. context 'with scope "read:accounts"' do
  57. let(:input) { 'read:accounts' }
  58. it_behaves_like 'a scope', nil, 'accounts', 'read'
  59. end
  60. context 'with scope "write:accounts"' do
  61. let(:input) { 'write:accounts' }
  62. it_behaves_like 'a scope', nil, 'accounts', 'write'
  63. end
  64. end
  65. end