scope_transformer_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. 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 term' do
  8. expect(subject.term).to eq term
  9. end
  10. it 'parses the namespace' do
  11. expect(subject.namespace).to eq namespace
  12. end
  13. it 'parses the access' do
  14. expect(subject.access).to eq access
  15. end
  16. end
  17. context 'for scope "read"' do
  18. let(:input) { 'read' }
  19. it_behaves_like 'a scope', nil, 'all', 'read'
  20. end
  21. context 'for scope "write"' do
  22. let(:input) { 'write' }
  23. it_behaves_like 'a scope', nil, 'all', 'write'
  24. end
  25. context 'for scope "follow"' do
  26. let(:input) { 'follow' }
  27. it_behaves_like 'a scope', nil, 'follow', 'read/write'
  28. end
  29. context 'for scope "crypto"' do
  30. let(:input) { 'crypto' }
  31. it_behaves_like 'a scope', nil, 'crypto', 'read/write'
  32. end
  33. context 'for scope "push"' do
  34. let(:input) { 'push' }
  35. it_behaves_like 'a scope', nil, 'push', 'read/write'
  36. end
  37. context 'for scope "admin:read"' do
  38. let(:input) { 'admin:read' }
  39. it_behaves_like 'a scope', 'admin', 'all', 'read'
  40. end
  41. context 'for scope "admin:write"' do
  42. let(:input) { 'admin:write' }
  43. it_behaves_like 'a scope', 'admin', 'all', 'write'
  44. end
  45. context 'for scope "admin:read:accounts"' do
  46. let(:input) { 'admin:read:accounts' }
  47. it_behaves_like 'a scope', 'admin', 'accounts', 'read'
  48. end
  49. context 'for scope "admin:write:accounts"' do
  50. let(:input) { 'admin:write:accounts' }
  51. it_behaves_like 'a scope', 'admin', 'accounts', 'write'
  52. end
  53. context 'for scope "read:accounts"' do
  54. let(:input) { 'read:accounts' }
  55. it_behaves_like 'a scope', nil, 'accounts', 'read'
  56. end
  57. context 'for scope "write:accounts"' do
  58. let(:input) { 'write:accounts' }
  59. it_behaves_like 'a scope', nil, 'accounts', 'write'
  60. end
  61. end
  62. end