Files
old-holivud2/spec/controllers/admin/casting_call_interviews_controller_spec.rb
2020-07-16 17:38:21 +02:00

107 lines
2.7 KiB
Ruby

require "rails_helper"
RSpec.describe Admin::CastingCallInterviewsController, type: :controller do
let!(:current_user) { create(:user, :admin) }
before do
sign_in(current_user)
end
describe "#index" do
it "returns a successful response" do
get :index
expect(response).to be_successful
end
end
describe "#new" do
it "returns a successful response" do
get :new
expect(response).to be_successful
end
it "assigns user, accounts" do
get :new
expect(assigns(:casting_call_interview)).not_to be_nil
expect(assigns(:accounts)).to eq Account.all
end
end
describe "#create" do
it "does create a new record" do
expect {
post :create, params: { casting_call_interview: casting_call_interview_params }
}.to change(CastingCallInterview, :count)
end
end
describe "#edit" do
let(:casting_call_interview) { create(:casting_call_interview) }
it "returns a successful response" do
get :edit, params: { id: casting_call_interview }
expect(response).to be_successful
end
it "assigns casting call interview" do
get :edit, params: { id: casting_call_interview }
expect(assigns(:casting_call_interview)).to eq casting_call_interview
end
end
describe "#update" do
let(:casting_call_interview) { create(:casting_call_interview) }
it "redirects to casting call interviews page" do
patch :update, params: { id: casting_call_interview, casting_call_interview: update_params }
expect(response).to be_redirect
expect(response).to redirect_to admin_casting_call_interviews_path
end
it "sets a flash notice" do
patch :update, params: { id: casting_call_interview, casting_call_interview: update_params }
expect(flash.notice).to eq "The casting call interview has been updated"
end
it "updates casting call interview" do
patch :update, params: { id: casting_call_interview, casting_call_interview: update_params }
expect(casting_call_interview.reload.zoom_meeting_url).to eq("new_zoom_meeting_url")
end
end
describe "#complete" do
let(:casting_call_interview) { create(:casting_call_interview) }
it "sets interviewed_at on casting call interview" do
expect(casting_call_interview.interviewed_at).to be_nil
post :complete, params: { id: casting_call_interview }
expect(casting_call_interview.reload.interviewed_at).not_to be_nil
end
end
private
def casting_call_interview_params
casting_call = create(:casting_call)
attributes_for(:casting_call_interview).except(:interviewed_at).merge(casting_call_id: casting_call.id)
end
def update_params
{
zoom_meeting_url: "new_zoom_meeting_url"
}
end
end