Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

128 lines
4.9 KiB

require "rails_helper"
RSpec.describe CaseLogsController, type: :controller do
let(:valid_session) { {} }
context "Collection routes" do
describe "GET #index" do
it "returns a success response" do
get :index, params: {}, session: valid_session
expect(response).to be_successful
end
end
describe "Post #create" do
it "creates a new case log record" do
expect {
post :create, params: {}, session: valid_session
}.to change(CaseLog, :count).by(1)
end
it "redirects to that case log" do
post :create, params: {}, session: valid_session
expect(response.status).to eq(302)
end
end
end
context "Instance routes" do
let!(:case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
describe "GET #show" do
it "returns a success response" do
get :show, params: { id: id }
expect(response).to be_successful
end
end
describe "GET #edit" do
it "returns a success response" do
get :edit, params: { id: id }
expect(response).to be_successful
end
end
end
describe "submit_form" do
let!(:case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
let(:case_log_form_params) do
{ accessibility_requirements:
%w[ accessibility_requirements_fully_wheelchair_accessible_housing
accessibility_requirements_wheelchair_access_to_essential_rooms
accessibility_requirements_level_access_housing],
previous_page: "accessibility_requirements" }
end
let(:new_case_log_form_params) do
{
accessibility_requirements: %w[accessibility_requirements_level_access_housing],
previous_page: "accessibility_requirements",
}
end
it "sets checked items to true" do
post :submit_form, params: { id: id, case_log: case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(true)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(true)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
end
it "sets previously submitted items to false when resubmitted with new values" do
post :submit_form, params: { id: id, case_log: new_case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(false)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(false)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
end
context "given a page with checkbox and non-checkbox questions" do
let(:tenant_code) { "BZ355" }
let(:case_log_form_params) do
{ accessibility_requirements:
%w[ accessibility_requirements_fully_wheelchair_accessible_housing
accessibility_requirements_wheelchair_access_to_essential_rooms
accessibility_requirements_level_access_housing],
tenant_code: tenant_code,
previous_page: "accessibility_requirements" }
end
let(:questions_for_page) do
{"accessibility_requirements"=>
{
"type"=>"checkbox",
"answer_options"=>
{"accessibility_requirements_fully_wheelchair_accessible_housing"=>"Fully wheelchair accessible housing",
"accessibility_requirements_wheelchair_access_to_essential_rooms"=>"Wheelchair access to essential rooms",
"accessibility_requirements_level_access_housing"=>"Level access housing",
"accessibility_requirements_other_disability_requirements"=>"Other disability requirements",
"accessibility_requirements_no_disability_requirements"=>"No disability requirements",
"divider_a"=>true,
"accessibility_requirements_do_not_know"=>"Do not know",
"divider_b"=>true,
"accessibility_requirements_prefer_not_to_say"=>"Prefer not to say"
}
},
"tenant_code"=>
{
"type"=>"text"
}
}
end
it "updates both question fields" do
allow_any_instance_of(Form).to receive(:questions_for_page).and_return(questions_for_page)
post :submit_form, params: { id: id, case_log: case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(true)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(true)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
expect(case_log.tenant_code).to eq(tenant_code)
end
end
end
end