144 lines
4.1 KiB
Ruby
144 lines
4.1 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe CastingCallsController, type: :controller do
|
|
render_views
|
|
|
|
let(:user) { create(:user) }
|
|
let(:account) { user.primary_account }
|
|
let(:project) { create(:project, account: user.primary_account) }
|
|
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
describe "#index" do
|
|
it "responds successfully" do
|
|
get :index, params: { project_id: project }
|
|
|
|
expect(response).to be_successful
|
|
end
|
|
|
|
it "renders content if there are existing broadcasts" do
|
|
create(:casting_call, project: project)
|
|
|
|
get :index, params: { project_id: project }
|
|
|
|
expect(response.body).to have_link "Create Casting Call"
|
|
expect(response.body).to have_content "Active"
|
|
end
|
|
|
|
context "when there are many records" do
|
|
it "paginates the table" do
|
|
create_list(:casting_call, 20, project: project)
|
|
|
|
get :index, params: { project_id: project }
|
|
|
|
expect(response.body).to have_link("2", href: project_casting_calls_path(project, page: 2))
|
|
end
|
|
end
|
|
|
|
context "when there are no records" do
|
|
it "renders splash screen" do
|
|
CastingCall.destroy_all
|
|
|
|
get :index, params: { project_id: project }
|
|
|
|
expect(response.body).not_to have_content no_casting_calls_message
|
|
expect(response.body).to have_link create_casting_call
|
|
expect(response.body).to have_link schedule_demo
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#new" do
|
|
it "responds successfully" do
|
|
get :new, params: { project_id: project }
|
|
|
|
expect(response).to be_successful
|
|
expect(assigns(:casting_call)).to be_a_new(CastingCall)
|
|
expect(response).to render_template(:new)
|
|
end
|
|
end
|
|
|
|
describe "#create" do
|
|
it "does create a new record" do
|
|
expect {
|
|
post :create, params: { project_id: project.id, casting_call: casting_call_params }
|
|
}.to change(CastingCall, :count)
|
|
end
|
|
|
|
it "logs an event" do
|
|
expect {
|
|
post :create, params: { project_id: project.id, casting_call: casting_call_params }
|
|
}.to have_enqueued_job(TrackAnalyticsJob).with(user, account, :track_create_casting_call, user_agent: "Rails Testing", user_ip: "0.0.0.0")
|
|
end
|
|
end
|
|
|
|
describe "#update" do
|
|
let!(:casting_call) { create(:casting_call, project: project, description: "My description" ) }
|
|
|
|
it "updates casting call request" do
|
|
patch :update, params: { project_id: project.id, id: casting_call.id, casting_call: update_params }
|
|
|
|
expect(casting_call.reload.description).to eq("This is updated description")
|
|
end
|
|
end
|
|
|
|
describe "#show" do
|
|
let!(:casting_call) { create(:casting_call, project: project, description: "Casting Call Request") }
|
|
|
|
it "responds successfully" do
|
|
get :show, params: { project_id: project.id, id: casting_call.id }
|
|
|
|
expect(response).to be_successful
|
|
expect(assigns(:casting_call)).to eq(casting_call)
|
|
end
|
|
|
|
it "renders content" do
|
|
get :show, params: { project_id: project.id, id: casting_call.id }
|
|
|
|
expect(response.body).to have_content "Casting Call Request"
|
|
expect(response.body).to have_content "Active"
|
|
end
|
|
end
|
|
|
|
describe "#cancel" do
|
|
let!(:casting_call) { create(:casting_call, project: project, description: "Casting Call to be Cancelled") }
|
|
|
|
it "responds with redirect" do
|
|
post :cancel, params: { project_id: project.id, id: casting_call.id }
|
|
|
|
expect(response).to be_redirect
|
|
expect(response).to redirect_to(project_casting_calls_path(project))
|
|
expect(flash.notice).not_to be_nil
|
|
end
|
|
|
|
it "updates the status to 'Cancelled'" do
|
|
expect {
|
|
post :cancel, params: { project_id: project.id, id: casting_call.id }
|
|
}.to change { casting_call.reload.status }.from("Active").to("Cancelled")
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def casting_call_params
|
|
attributes_for(:casting_call).except(:status, :user_email)
|
|
end
|
|
|
|
def update_params
|
|
{ description: "This is updated description" }
|
|
end
|
|
|
|
def no_casting_calls_message
|
|
t 'casting_calls.index.empty'
|
|
end
|
|
|
|
def create_casting_call
|
|
t 'casting_calls.splash.actions.create_casting_call'
|
|
end
|
|
|
|
def schedule_demo
|
|
t 'casting_calls.splash.actions.book_demo'
|
|
end
|
|
end |