-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Move controller spec to request spec * Renaming specs and changing diaper_drive factory * diaper drive participants csv import spec
- Loading branch information
1 parent
68d7319
commit f16cdb5
Showing
7 changed files
with
229 additions
and
180 deletions.
There are no files selected for viewing
90 changes: 0 additions & 90 deletions
90
spec/controllers/diaper_drive_participants_controller_spec.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
132 changes: 132 additions & 0 deletions
132
spec/requests/diaper_drive_participants_requests_spec.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,132 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "DiaperDriveParticipants", type: :request do | ||
let(:default_params) do | ||
{ organization_id: @organization.to_param } | ||
end | ||
|
||
context "While signed in" do | ||
before do | ||
sign_in(@user) | ||
end | ||
|
||
describe "GET #index" do | ||
it "returns http success" do | ||
get diaper_drive_participants_path(default_params) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #new" do | ||
it "returns http success" do | ||
get new_diaper_drive_participant_path(default_params) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #edit" do | ||
it "returns http success" do | ||
get edit_diaper_drive_participant_path(default_params.merge(id: create(:diaper_drive_participant, organization: @user.organization))) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "POST #import_csv" do | ||
let(:model_class) { DiaperDriveParticipant } | ||
|
||
context "with a csv file" do | ||
let(:file) { fixture_file_upload("#{model_class.name.underscore.pluralize}.csv", "text/csv") } | ||
subject { post import_csv_diaper_drive_participants_path(default_params), params: { file: file } } | ||
|
||
it "invokes .import_csv" do | ||
expect(model_class).to respond_to(:import_csv).with(2).arguments | ||
end | ||
|
||
it "redirects" do | ||
subject | ||
expect(response).to be_redirect | ||
end | ||
|
||
it "presents a flash notice message" do | ||
subject | ||
expect(response).to have_notice "#{model_class.name.underscore.humanize.pluralize} were imported successfully!" | ||
end | ||
end | ||
|
||
context "without a csv file" do | ||
subject { post import_csv_diaper_drive_participants_path(default_params) } | ||
|
||
it "redirects to :index" do | ||
subject | ||
expect(response).to be_redirect | ||
end | ||
|
||
it "presents a flash error message" do | ||
subject | ||
expect(response).to have_error "No file was attached!" | ||
end | ||
end | ||
|
||
context "csv file with wrong headers" do | ||
let(:file) { fixture_file_upload("wrong_headers.csv", "text/csv") } | ||
subject { post import_csv_diaper_drive_participants_path(default_params), params: { file: file } } | ||
|
||
it "redirects" do | ||
subject | ||
expect(response).to be_redirect | ||
end | ||
|
||
it "presents a flash error message" do | ||
subject | ||
expect(response).to have_error "Check headers in file!" | ||
end | ||
end | ||
end | ||
|
||
describe "GET #show" do | ||
it "returns http success" do | ||
get diaper_drive_participant_path(default_params.merge(id: create(:diaper_drive_participant, organization: @organization))) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "XHR #create" do | ||
it "successful create" do | ||
post diaper_drive_participants_path(default_params.merge(diaper_drive_participant: { name: "test", email: "123@mail.ru" }, xhr: true)) | ||
expect(response).to be_successful | ||
end | ||
|
||
it "flash error" do | ||
post diaper_drive_participants_path(default_params.merge(diaper_drive_participant: { name: "test" }, xhr: true)) | ||
expect(response).to be_successful | ||
expect(response).to have_error(/try again/i) | ||
end | ||
end | ||
|
||
describe "POST #create" do | ||
it "successful create" do | ||
post diaper_drive_participants_path(default_params.merge(diaper_drive_participant: { business_name: "businesstest", | ||
contact_name: "test", email: "123@mail.ru" })) | ||
expect(response).to redirect_to(diaper_drive_participants_path) | ||
expect(response).to have_notice(/added!/i) | ||
end | ||
|
||
it "flash error" do | ||
post diaper_drive_participants_path(default_params.merge(diaper_drive_participant: { name: "test" }, xhr: true)) | ||
expect(response).to be_successful | ||
expect(response).to have_error(/try again/i) | ||
end | ||
end | ||
|
||
context "Looking at a different organization" do | ||
let(:object) { create(:diaper_drive_participant, organization: create(:organization)) } | ||
include_examples "requiring authorization" | ||
end | ||
end | ||
|
||
context "While not signed in" do | ||
let(:object) { create(:diaper_drive_participant) } | ||
|
||
include_examples "requiring authorization" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "DiaperDrives", type: :request do | ||
let(:default_params) do | ||
{ organization_id: @organization.id.to_param } | ||
end | ||
|
||
context "While signed in >" do | ||
let(:diaper_drive) { create(:diaper_drive) } | ||
before do | ||
sign_in(@user) | ||
end | ||
|
||
describe "GET #index" do | ||
it "returns http success" do | ||
get diaper_drives_path(default_params) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #new" do | ||
it "returns http success" do | ||
get new_diaper_drive_path(default_params) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "POST#create" do | ||
it "returns redirect http status" do | ||
post diaper_drives_path(default_params.merge(diaper_drive: attributes_for(:diaper_drive))) | ||
expect(response).to have_http_status(:redirect) | ||
end | ||
end | ||
|
||
describe "PUT#update" do | ||
it "returns redirect http status" do | ||
put diaper_drive_path(default_params.merge(id: diaper_drive.id, diaper_drive: attributes_for(:diaper_drive))) | ||
expect(response).to have_http_status(:redirect) | ||
end | ||
end | ||
|
||
describe "GET #edit" do | ||
it "returns http success" do | ||
get edit_diaper_drive_path(default_params.merge(id: diaper_drive.id)) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET #show" do | ||
it "returns http success" do | ||
get diaper_drive_path(default_params.merge(id: diaper_drive.id)) | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "DELETE #destroy" do | ||
it "redirects to the index" do | ||
delete diaper_drive_path(default_params.merge(id: diaper_drive.id)) | ||
expect(response).to redirect_to(diaper_drives_path) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.