diff --git a/app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb b/app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
index c12c99369..f4d3ec3f2 100644
--- a/app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
+++ b/app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
@@ -15,24 +15,14 @@ module SingleUseLinksControllerBehavior
end
end
- def new_download
+ def create_download
@su = SingleUseLink.create itemId: params[:id], path: main_app.download_path(id: asset)
- @link = curation_concerns.download_single_use_link_path(@su.downloadKey)
-
- respond_to do |format|
- format.html
- format.js { render js: @link }
- end
+ render text: curation_concerns.download_single_use_link_url(@su.downloadKey)
end
- def new_show
+ def create_show
@su = SingleUseLink.create itemId: params[:id], path: polymorphic_path([main_app, asset])
- @link = curation_concerns.show_single_use_link_path(@su.downloadKey)
-
- respond_to do |format|
- format.html
- format.js { render js: @link }
- end
+ render text: curation_concerns.show_single_use_link_url(@su.downloadKey)
end
protected
diff --git a/app/views/curation_concerns/single_use_links/new_download.html.erb b/app/views/curation_concerns/single_use_links/new_download.html.erb
deleted file mode 100644
index a5726ac4f..000000000
--- a/app/views/curation_concerns/single_use_links/new_download.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
Single Use Link
-
Anyone can use the following link once to download the file
-<%= link_to @asset, @link, class: 'download-link', data: { 'no-turbolink' => ''}, target: '_blank' %>
-
diff --git a/app/views/curation_concerns/single_use_links/new_show.html.erb b/app/views/curation_concerns/single_use_links/new_show.html.erb
deleted file mode 100644
index c4eb70e4a..000000000
--- a/app/views/curation_concerns/single_use_links/new_show.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
Single Use Link
-
Anyone can use the following link once to view the file metadata
-<%= link_to @asset, @link, target: '_blank' %>
-
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index b9962d8c1..e7b77d269 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,8 @@
CurationConcerns::Engine.routes.draw do
get 'single_use_link/show/:id' => 'single_use_links_viewer#show', as: :show_single_use_link
get 'single_use_link/download/:id' => 'single_use_links_viewer#download', as: :download_single_use_link
- get 'single_use_link/generate_download/:id' => 'single_use_links#new_download', as: :generate_download_single_use_link
- get 'single_use_link/generate_show/:id' => 'single_use_links#new_show', as: :generate_show_single_use_link
+ post 'single_use_link/generate_download/:id' => 'single_use_links#create_download', as: :generate_download_single_use_link
+ post 'single_use_link/generate_show/:id' => 'single_use_links#create_show', as: :generate_show_single_use_link
# mount BrowseEverything::Engine => '/remote_files/browse'
resources :classify_concerns, only: [:new, :create]
diff --git a/spec/controllers/curation_concerns/single_use_links_controller_spec.rb b/spec/controllers/curation_concerns/single_use_links_controller_spec.rb
index 7575e1641..ff9b404c8 100644
--- a/spec/controllers/curation_concerns/single_use_links_controller_spec.rb
+++ b/spec/controllers/curation_concerns/single_use_links_controller_spec.rb
@@ -21,17 +21,17 @@
describe "GET 'download'" do
it "and_return http success" do
- get 'new_download', id: file
+ post 'create_download', id: file
expect(response).to be_success
- expect(assigns[:link]).to eq routes.url_helpers.download_single_use_link_path(hash)
+ expect(response.body).to eq download_single_use_link_url(hash)
end
end
describe "GET 'show'" do
it "and_return http success" do
- get 'new_show', id: file
+ post 'create_show', id: file
expect(response).to be_success
- expect(assigns[:link]).to eq routes.url_helpers.show_single_use_link_path(hash)
+ expect(response.body).to eq show_single_use_link_url(hash)
end
end
end
@@ -40,22 +40,22 @@
before do
@other_user = create(:user)
file.read_users << @other_user
- file.save
+ file.save!
sign_in @other_user
file.read_users << @other_user
- file.save
+ file.save!
end
describe "GET 'download'" do
it "and_return http success" do
- get 'new_download', id: file
+ post 'create_download', id: file
expect(response).not_to be_success
end
end
describe "GET 'show'" do
it "and_return http success" do
- get 'new_show', id: file
+ post 'create_show', id: file
expect(response).not_to be_success
end
end
@@ -64,14 +64,14 @@
describe "unknown user" do
describe "GET 'download'" do
it "and_return http failure" do
- get 'new_download', id: file
+ post 'create_download', id: file
expect(response).not_to be_success
end
end
describe "GET 'show'" do
it "and_return http failure" do
- get 'new_show', id: file
+ post 'create_show', id: file
expect(response).not_to be_success
end
end
diff --git a/spec/routing/curation_concerns/routes_spec.rb b/spec/routing/curation_concerns/routes_spec.rb
index 74062793f..0fcc124c2 100644
--- a/spec/routing/curation_concerns/routes_spec.rb
+++ b/spec/routing/curation_concerns/routes_spec.rb
@@ -29,14 +29,14 @@ module CurationConcerns
describe 'Single Use Link Generator' do
routes { CurationConcerns::Engine.routes }
- it 'routes to #show' do
+ it 'routes to #create_show' do
expect(generate_show_single_use_link_path('abc123')).to eq '/single_use_link/generate_show/abc123'
- expect(get("/single_use_link/generate_show/abc123")).to route_to("curation_concerns/single_use_links#new_show", id: 'abc123')
+ expect(post("/single_use_link/generate_show/abc123")).to route_to("curation_concerns/single_use_links#create_show", id: 'abc123')
end
- it 'routes to #download' do
+ it 'routes to #create_download' do
expect(generate_download_single_use_link_path('abc123')).to eq '/single_use_link/generate_download/abc123'
- expect(get("/single_use_link/generate_download/abc123")).to route_to("curation_concerns/single_use_links#new_download", id: 'abc123')
+ expect(post("/single_use_link/generate_download/abc123")).to route_to("curation_concerns/single_use_links#create_download", id: 'abc123')
end
end
diff --git a/spec/views/single_use_links/new_download.html.erb_spec.rb b/spec/views/single_use_links/new_download.html.erb_spec.rb
deleted file mode 100644
index 1c0832942..000000000
--- a/spec/views/single_use_links/new_download.html.erb_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require 'spec_helper'
-
-describe 'curation_concerns/single_use_links/new_download.html.erb' do
- let(:user) { create(:user) }
-
- let(:f) do
- file = FileSet.create do |gf|
- gf.apply_depositor_metadata(user)
- end
- Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_path + '/world.png'), :original_file)
- file
- end
-
- let(:hash) { "some-dummy-sha2-hash" }
-
- before do
- assign :asset, f
- assign :link, CurationConcerns::Engine.routes.url_helpers.download_single_use_link_path(hash)
- render
- end
-
- it "has the download link" do
- expect(rendered).to have_selector "a.download-link"
- end
-
- it "has turbolinks disabled in the download link" do
- expect(rendered).to have_selector "a.download-link[data-no-turbolink]"
- end
-end