Skip to content

Commit

Permalink
Merge pull request #735 from projecthydra-labs/refactor_single_use_links
Browse files Browse the repository at this point in the history
SingleUseLinks should be created with a post
  • Loading branch information
cbeer committed Apr 19, 2016
2 parents 8648414 + 8625868 commit 4a2aeeb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/routing/curation_concerns/routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 0 additions & 29 deletions spec/views/single_use_links/new_download.html.erb_spec.rb

This file was deleted.

0 comments on commit 4a2aeeb

Please sign in to comment.