require "rails_helper" RSpec.describe PathParserService do let(:path) { "/one/two/three/prefix - name#42" } { "{tags}" => %r{^/?.*?(?[[:print:]]*)$}, "{creator}" => %r{^/?.*?(?[[:print:]&&[^/]]*?)$}, "{collection}" => %r{^/?.*?(?[[:print:]&&[^/]]*?)$}, "{tags}/{creator}" => %r{^/?.*?(?[[:print:]]*)/(?[[:print:]&&[^/]]*?)$}, "{tags}/{creator}/{modelName}{modelId}" => %r{^/?.*?(?[[:print:]]*)/(?[[:print:]&&[^/]]*?)/(?[[:print:]&&[^/]]*?)(?#[[:digit:]]+)?$}, "@{creator}{modelId}" => %r{^/?.*?@(?[[:print:]&&[^/]]*?)(?#[[:digit:]]+)?$}, "{creator}/{collection}/{tags}/{modelName}{modelId}" => %r{^/?.*?(?[[:print:]&&[^/]]*?)/(?[[:print:]&&[^/]]*?)/(?[[:print:]]*)/(?[[:print:]&&[^/]]*?)(?#[[:digit:]]+)?$} }.each_pair do |tag, regexp| it "correctly converts #{tag} into a regexp matcher" do service = described_class.new(tag, path) expect(service.send(:path_parse_pattern)).to eql regexp end end { "{tags}/{modelName}{modelId}" => { tags: ["one", "two", "three"], model_name: "prefix - name" }, "{creator}/{modelName}{modelId}" => { creator: "three", model_name: "prefix - name" }, "{collection}/{modelName}{modelId}" => { collection: "three", model_name: "prefix - name" }, "{tags}/{creator}/{modelName}{modelId}" => { creator: "three", tags: ["one", "two"], model_name: "prefix - name" }, "{creator}{modelId}" => { creator: "prefix - name" }, "{tags}/{creator}/{collection} - {modelName}{modelId}" => { tags: ["one", "two"], creator: "three", collection: "prefix", model_name: "name" } }.each_pair do |tag, values| it "correctly matches components of #{tag}" do service = described_class.new(tag, path) expect(service.call).to eql values end end end