-
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.
Merge pull request #8 from medusa-project/feature-31
add tests for datafiles controller, including download
- Loading branch information
Showing
1 changed file
with
156 additions
and
0 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,156 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DatafilesController, type: :controller do | ||
let(:dataset) { create(:dataset) } | ||
let(:datafile) { create(:datafile, dataset: dataset) } | ||
let(:valid_attributes) { attributes_for(:datafile, dataset_id: dataset.id) } | ||
let(:invalid_attributes) { { binary_name: nil } } | ||
|
||
before do | ||
allow(controller).to receive(:authorize!).and_return(true) | ||
end | ||
|
||
describe "GET #index" do | ||
it "returns a success response" do | ||
get :index, params: { dataset_id: dataset.key } | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #show" do | ||
it "returns a success response" do | ||
get :show, params: { id: datafile.web_id } | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #new" do | ||
it "returns a success response" do | ||
get :new, params: { dataset_id: dataset.key } | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #edit" do | ||
it "returns a success response" do | ||
get :edit, params: { id: datafile.web_id } | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #download" do | ||
# assumes at least one datafile exists, which is created in the setup | ||
it "returns a success response and increases tallies" do | ||
datafile = Datafile.first | ||
get :download, params: { id: datafile.web_id } | ||
expect(response).to be_successful | ||
# expect DatasetDownloadTally total to increase by 1 | ||
expect(DatasetDownloadTally.count).to eq(1) | ||
# expect DayFileDownload total to increase by 1 | ||
expect(DayFileDownload.count).to eq(1) | ||
end | ||
end | ||
|
||
# describe "POST #create" do | ||
# context "with valid params" do | ||
# it "creates a new Datafile" do | ||
# expect { | ||
# post :create, params: { datafile: valid_attributes } | ||
# }.to change(Datafile, :count).by(1) | ||
# end | ||
|
||
# it "renders a JSON response with the new datafile" do | ||
# post :create, params: { datafile: valid_attributes } | ||
# expect(response).to have_http_status(:created) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
|
||
# context "with invalid params" do | ||
# it "renders a JSON response with errors for the new datafile" do | ||
# post :create, params: { datafile: invalid_attributes } | ||
# expect(response).to have_http_status(:unprocessable_entity) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
# end | ||
|
||
# describe "PATCH #update" do | ||
# context "with valid params" do | ||
# let(:new_attributes) { { description: "Updated description" } } | ||
|
||
# it "updates the requested datafile" do | ||
# patch :update, params: { id: datafile.web_id, datafile: new_attributes } | ||
# datafile.reload | ||
# expect(datafile.description).to eq("Updated description") | ||
# end | ||
|
||
# it "renders a JSON response with the datafile" do | ||
# patch :update, params: { id: datafile.web_id, datafile: new_attributes } | ||
# expect(response).to have_http_status(:ok) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
|
||
# context "with invalid params" do | ||
# it "renders a JSON response with errors for the datafile" do | ||
# patch :update, params: { id: datafile.web_id, datafile: invalid_attributes } | ||
# expect(response).to have_http_status(:unprocessable_entity) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
# end | ||
|
||
# describe "DELETE #destroy" do | ||
# it "destroys the requested datafile" do | ||
# datafile # create the datafile | ||
# expect { | ||
# delete :destroy, params: { id: datafile.web_id } | ||
# }.to change(Datafile, :count).by(-1) | ||
# end | ||
|
||
# it "renders a JSON response with the confirmation" do | ||
# delete :destroy, params: { id: datafile.web_id } | ||
# expect(response).to have_http_status(:ok) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
|
||
# describe "GET #download" do | ||
# it "records the download and initiates the download" do | ||
# expect(datafile).to receive(:record_download).with(anything) | ||
# get :download, params: { id: datafile.web_id } | ||
# expect(response).to have_http_status(:ok) | ||
# end | ||
# end | ||
|
||
# describe "GET #view" do | ||
# it "renders the file inline" do | ||
# get :view, params: { id: datafile.web_id } | ||
# expect(response).to have_http_status(:ok) | ||
# end | ||
# end | ||
|
||
# describe "GET #filepath" do | ||
# context "when file is in S3" do | ||
# before { allow(IDB_CONFIG[:aws]).to receive(:[]).with(:s3_mode).and_return(true) } | ||
|
||
# it "returns an error message" do | ||
# get :filepath, params: { id: datafile.web_id } | ||
# expect(response).to have_http_status(:bad_request) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
|
||
# context "when file is on filesystem" do | ||
# before { allow(IDB_CONFIG[:aws]).to receive(:[]).with(:s3_mode).and_return(false) } | ||
|
||
# it "returns the filepath" do | ||
# allow(datafile).to receive(:filepath).and_return("/path/to/file") | ||
# get :filepath, params: { id: datafile.web_id } | ||
# expect(response).to have_http_status(:ok) | ||
# expect(response.content_type).to eq('application/json') | ||
# end | ||
# end | ||
# end | ||
end |