Skip to content

Commit

Permalink
Handle routes with percent escaped values
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 6, 2015
1 parent 0700489 commit f0e8c7e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
HydraEditor::Engine.routes.draw do
resources :records, only: [:new, :edit, :create, :update], constraints: { id: /[a-zA-Z0-9_.:\-]+/ }
resources :records, only: [:new, :edit, :create, :update], constraints: { id: /[a-zA-Z0-9_.:\-\/%]+/ }
end
31 changes: 25 additions & 6 deletions spec/routing/records_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@

routes { HydraEditor::Engine.routes }

let(:audio) { Audio.new(id: id) }
before do
@audio = Audio.new(id: 'test_7.a-b')
allow(@audio).to receive(:persisted?).and_return(true)
allow(@audio).to receive(:save).and_return(true)
allow(audio).to receive(:persisted?).and_return(true)
allow(audio).to receive(:save).and_return(true)
end

it "should handle pids with hyphens" do
expect(get: edit_record_path(@audio)).
to route_to(controller: "records", action: "edit", id: "test_7.a-b")
context "ids with hyphens" do
let(:id) { 'test_7.a-b' }
it "routes them" do
expect(get: edit_record_path(audio)).
to route_to(controller: "records", action: "edit", id: "test_7.a-b")
end
end

context "ids with percent" do
let(:id) { 'test_7%2Fa-b' }
it "routes them" do
expect(get: edit_record_path(audio)).
to route_to(controller: "records", action: "edit", id: "test_7/a-b")
end
end

context "ids with slash" do
let(:id) { '16/2d/0a/8f/162d0a8f-49df-4fe1-9ee2-ea9357adcf88' }
it "routes them" do
expect(get: edit_record_path(audio)).
to route_to(controller: "records", action: "edit", id: "16/2d/0a/8f/162d0a8f-49df-4fe1-9ee2-ea9357adcf88")
end
end
end

0 comments on commit f0e8c7e

Please sign in to comment.