-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
murb
committed
Oct 11, 2023
1 parent
6ac1765
commit 1e7c5d9
Showing
8 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ShortCodeResolverController < ApplicationController | ||
skip_before_action :authenticate_activated_user! | ||
|
||
def resolve | ||
# "short_code_resolver/resolve/:collection_code/:work_code" | ||
raise ActiveRecord::RecordNotFound.new("not found") if params[:collection_code].blank? | ||
|
||
collection = Collection.find_by_unique_short_code!(params[:collection_code]) | ||
work = collection.works_including_child_works.find_by_stock_number!(params[:work_code]) | ||
|
||
redirect_to collection_work_path(collection, work) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20231011205842_add_unique_short_code_to_collections.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddUniqueShortCodeToCollections < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :collections, :unique_short_code, :string | ||
add_index :collections, :unique_short_code, unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "ShortCodeResolvers", type: :request do | ||
describe "GET /resolve" do | ||
let(:work) { works(:work_diptych_2) } | ||
|
||
it "returns http not found for unknown collection code" do | ||
expect { | ||
get "/short_code_resolver/resolve/ABC/123" | ||
}.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
it "returns http not found for unknown work code" do | ||
expect { | ||
get "/short_code_resolver/resolve/COL4/123" | ||
}.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
it "redirects when known combi is given" do | ||
get "/short_code_resolver/resolve/#{work.collection.unique_short_code}/#{work.stock_number}" | ||
expect(response).to redirect_to(collection_work_path(work.collection, work)) | ||
end | ||
end | ||
end |