Browse Source

update tests to specify created_by

pull/1055/head
Kat 4 years ago
parent
commit
de96f02118
  1. 18
      spec/features/form/check_answers_page_spec.rb
  2. 3
      spec/features/form/checkboxes_spec.rb
  3. 6
      spec/features/form/conditional_questions_spec.rb
  4. 4
      spec/features/form/page_routing_spec.rb
  5. 3
      spec/features/form/progressive_total_field_spec.rb
  6. 6
      spec/features/form/saving_data_spec.rb
  7. 12
      spec/features/form/validations_spec.rb
  8. 4
      spec/features/organisation_spec.rb
  9. 3
      spec/helpers/interruption_screen_helper_spec.rb
  10. 5
      spec/jobs/email_csv_job_spec.rb
  11. 1
      spec/models/form/lettings/questions/created_by_id_spec.rb
  12. 4
      spec/models/organisation_spec.rb
  13. 3
      spec/models/user_spec.rb
  14. 29
      spec/requests/form_controller_spec.rb
  15. 28
      spec/requests/lettings_logs_controller_spec.rb
  16. 4
      spec/requests/organisations_controller_spec.rb

18
spec/features/form/check_answers_page_spec.rb

@ -13,8 +13,7 @@ RSpec.describe "Form Check Answers Page" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
needstype: 2, needstype: 2,
scheme:, scheme:,
location:, location:,
@ -26,8 +25,7 @@ RSpec.describe "Form Check Answers Page" do
previous_la_known: 1, previous_la_known: 1,
prevloc: "E09000033", prevloc: "E09000033",
is_previous_la_inferred: false, is_previous_la_inferred: false,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:completed_lettings_log) do let(:completed_lettings_log) do
@ -36,6 +34,7 @@ RSpec.describe "Form Check Answers Page" do
:completed, :completed,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
created_by: user,
startdate: Time.zone.local(2021, 5, 1), startdate: Time.zone.local(2021, 5, 1),
) )
end end
@ -190,8 +189,7 @@ RSpec.describe "Form Check Answers Page" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
tenancycode: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
@ -203,8 +201,7 @@ RSpec.describe "Form Check Answers Page" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
tenancycode: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
@ -218,8 +215,7 @@ RSpec.describe "Form Check Answers Page" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
tenancycode: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
@ -236,8 +232,6 @@ RSpec.describe "Form Check Answers Page" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
created_by: user, created_by: user,
needstype: 1, needstype: 1,
tenancycode: nil, tenancycode: nil,

3
spec/features/form/checkboxes_spec.rb

@ -9,8 +9,7 @@ RSpec.describe "Checkboxes" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:id) { lettings_log.id } let(:id) { lettings_log.id }

6
spec/features/form/conditional_questions_spec.rb

@ -8,16 +8,14 @@ RSpec.describe "Form Conditional Questions" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:sales_log) do let(:sales_log) do
FactoryBot.create( FactoryBot.create(
:sales_log, :sales_log,
:completed, :completed,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:id) { lettings_log.id } let(:id) { lettings_log.id }

4
spec/features/form/page_routing_spec.rb

@ -8,8 +8,7 @@ RSpec.describe "Form Page Routing" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:id) { lettings_log.id } let(:id) { lettings_log.id }
@ -120,6 +119,7 @@ RSpec.describe "Form Page Routing" do
:lettings_log, :lettings_log,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
created_by: user,
needstype: 2, needstype: 2,
) )
end end

3
spec/features/form/progressive_total_field_spec.rb

@ -8,8 +8,7 @@ RSpec.describe "Accessible Automcomplete" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end

6
spec/features/form/saving_data_spec.rb

@ -8,8 +8,7 @@ RSpec.describe "Form Saving Data" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:id) { lettings_log.id } let(:id) { lettings_log.id }
@ -17,8 +16,7 @@ RSpec.describe "Form Saving Data" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :in_progress, :lettings_log, :in_progress,
housingneeds_a: 1, housingneeds_a: 1,
owning_organisation: user.organisation, created_by: user
managing_organisation: user.organisation
) )
end end
let(:question_answers) do let(:question_answers) do

12
spec/features/form/validations_spec.rb

@ -8,24 +8,21 @@ RSpec.describe "validations" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
renewal: 0, renewal: 0,
) )
end end
let(:empty_lettings_log) do let(:empty_lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:completed_without_declaration) do let(:completed_without_declaration) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:completed, :completed,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
status: 1, status: 1,
declaration: nil, declaration: nil,
startdate: Time.zone.local(2021, 5, 1), startdate: Time.zone.local(2021, 5, 1),
@ -124,8 +121,7 @@ RSpec.describe "validations" do
:lettings_log, :lettings_log,
:in_progress, :in_progress,
ecstat1: 1, ecstat1: 1,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end
let(:income_over_soft_limit) { 750 } let(:income_over_soft_limit) { 750 }

4
spec/features/organisation_spec.rb

@ -136,8 +136,8 @@ RSpec.describe "User Features" do
context "when viewing lettings logs for specific organisation" do context "when viewing lettings logs for specific organisation" do
let(:first_log) { organisation.lettings_logs.first } let(:first_log) { organisation.lettings_logs.first }
let!(:log_to_search) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation, managing_organisation_id: organisation.id) } let!(:log_to_search) { FactoryBot.create(:lettings_log, created_by: user) }
let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) } let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user) }
let(:number_of_lettings_logs) { LettingsLog.count } let(:number_of_lettings_logs) { LettingsLog.count }
before do before do

3
spec/helpers/interruption_screen_helper_spec.rb

@ -12,8 +12,7 @@ RSpec.describe InterruptionScreenHelper do
ecstat1: 1, ecstat1: 1,
earnings: 750, earnings: 750,
incfreq: 1, incfreq: 1,
owning_organisation: user.organisation, created_by: user,
managing_organisation: user.organisation,
) )
end end

5
spec/jobs/email_csv_job_spec.rb

@ -19,8 +19,7 @@ describe EmailCsvJob do
let!(:lettings_log) do let!(:lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
ecstat1: 1, ecstat1: 1,
) )
end end
@ -31,8 +30,6 @@ describe EmailCsvJob do
before do before do
FactoryBot.create(:lettings_log, FactoryBot.create(:lettings_log,
:completed, :completed,
owning_organisation: organisation,
managing_organisation: organisation,
created_by: user, created_by: user,
startdate: Time.zone.local(2021, 5, 1)) startdate: Time.zone.local(2021, 5, 1))

1
spec/models/form/lettings/questions/created_by_id_spec.rb

@ -71,6 +71,7 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
let(:lettings_log) do let(:lettings_log) do
create( create(
:lettings_log, :lettings_log,
created_by: user_2,
owning_organisation: user_2.organisation, owning_organisation: user_2.organisation,
managing_organisation: user_3.organisation, managing_organisation: user_3.organisation,
) )

4
spec/models/organisation_spec.rb

@ -151,7 +151,6 @@ RSpec.describe Organisation, type: :model do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:completed, :completed,
owning_organisation: organisation,
managing_organisation: other_organisation, managing_organisation: other_organisation,
created_by: user, created_by: user,
) )
@ -159,8 +158,7 @@ RSpec.describe Organisation, type: :model do
let!(:managed_lettings_log) do let!(:managed_lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
owning_organisation: other_organisation, created_by: user,
managing_organisation: organisation,
) )
end end

3
spec/models/user_spec.rb

@ -8,7 +8,6 @@ RSpec.describe User, type: :model do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:completed, :completed,
owning_organisation: user.organisation,
managing_organisation: other_organisation, managing_organisation: other_organisation,
created_by: user, created_by: user,
) )
@ -16,8 +15,8 @@ RSpec.describe User, type: :model do
let!(:managed_lettings_log) do let!(:managed_lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
created_by: user,
owning_organisation: other_organisation, owning_organisation: other_organisation,
managing_organisation: user.organisation,
) )
end end

29
spec/requests/form_controller_spec.rb

@ -4,12 +4,12 @@ RSpec.describe FormController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:other_organisation) { create(:organisation) } let(:other_user) { create(:user) }
let(:other_organisation) { other_user.organisation }
let!(:unauthorized_lettings_log) do let!(:unauthorized_lettings_log) do
create( create(
:lettings_log, :lettings_log,
owning_organisation: other_organisation, created_by: other_user,
managing_organisation: other_organisation,
) )
end end
let(:setup_complete_lettings_log) do let(:setup_complete_lettings_log) do
@ -18,16 +18,14 @@ RSpec.describe FormController, type: :request do
:about_completed, :about_completed,
status: 1, status: 1,
startdate: Time.zone.local(2021, 10, 10), startdate: Time.zone.local(2021, 10, 10),
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
) )
end end
let(:completed_lettings_log) do let(:completed_lettings_log) do
create( create(
:lettings_log, :lettings_log,
:completed, :completed,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
startdate: Time.zone.local(2021, 5, 1), startdate: Time.zone.local(2021, 5, 1),
) )
end end
@ -43,8 +41,7 @@ RSpec.describe FormController, type: :request do
let!(:lettings_log) do let!(:lettings_log) do
create( create(
:lettings_log, :lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
) )
end end
@ -72,8 +69,7 @@ RSpec.describe FormController, type: :request do
let!(:lettings_log) do let!(:lettings_log) do
create( create(
:lettings_log, :lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
) )
end end
@ -156,8 +152,7 @@ RSpec.describe FormController, type: :request do
create( create(
:lettings_log, :lettings_log,
startdate: Time.zone.local(2022, 12, 1), startdate: Time.zone.local(2022, 12, 1),
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
) )
end end
let(:headers) { { "Accept" => "text/html" } } let(:headers) { { "Accept" => "text/html" } }
@ -224,8 +219,7 @@ RSpec.describe FormController, type: :request do
let(:lettings_log) do let(:lettings_log) do
create( create(
:lettings_log, :lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
) )
end end
let(:page_id) { "person_1_age" } let(:page_id) { "person_1_age" }
@ -566,12 +560,11 @@ RSpec.describe FormController, type: :request do
context "with lettings logs that are not owned or managed by your organisation" do context "with lettings logs that are not owned or managed by your organisation" do
let(:answer) { 25 } let(:answer) { 25 }
let(:other_organisation) { create(:organisation) } let(:other_user) { create(:user) }
let(:unauthorized_lettings_log) do let(:unauthorized_lettings_log) do
create( create(
:lettings_log, :lettings_log,
owning_organisation: other_organisation, created_by: other_user,
managing_organisation: other_organisation,
) )
end end

28
spec/requests/lettings_logs_controller_spec.rb

@ -150,20 +150,19 @@ RSpec.describe LettingsLogsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_user) { FactoryBot.create(:user) }
let(:other_organisation) { other_user.organisation }
let!(:lettings_log) do let!(:lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
tenancycode: "LC783", tenancycode: "LC783",
) )
end end
let!(:unauthorized_lettings_log) do let!(:unauthorized_lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
owning_organisation: other_organisation, created_by: other_user,
managing_organisation: other_organisation,
tenancycode: "UA984", tenancycode: "UA984",
) )
end end
@ -266,9 +265,8 @@ RSpec.describe LettingsLogsController, type: :request do
context "with year filter" do context "with year filter" do
let!(:lettings_log_2021) do let!(:lettings_log_2021) do
FactoryBot.create(:lettings_log, :in_progress, FactoryBot.create(:lettings_log, :in_progress,
owning_organisation: organisation, created_by: user,
startdate: Time.zone.local(2022, 3, 1), startdate: Time.zone.local(2022, 3, 1))
managing_organisation: organisation)
end end
let!(:lettings_log_2022) do let!(:lettings_log_2022) do
lettings_log = FactoryBot.build(:lettings_log, :completed, lettings_log = FactoryBot.build(:lettings_log, :completed,
@ -567,7 +565,7 @@ RSpec.describe LettingsLogsController, type: :request do
context "when there are more than 20 logs" do context "when there are more than 20 logs" do
before do before do
FactoryBot.create_list(:lettings_log, 25, owning_organisation: organisation, managing_organisation: organisation) FactoryBot.create_list(:lettings_log, 25, created_by: user)
end end
context "when on the first page" do context "when on the first page" do
@ -699,8 +697,7 @@ RSpec.describe LettingsLogsController, type: :request do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:conditional_section_complete, :conditional_section_complete,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
) )
end end
@ -756,8 +753,7 @@ RSpec.describe LettingsLogsController, type: :request do
context "when accessing the check answers page" do context "when accessing the check answers page" do
let(:postcode_lettings_log) do let(:postcode_lettings_log) do
FactoryBot.create(:lettings_log, FactoryBot.create(:lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
postcode_known: "No") postcode_known: "No")
end end
let(:id) { postcode_lettings_log.id } let(:id) { postcode_lettings_log.id }
@ -771,8 +767,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "shows the inferred la" do it "shows the inferred la" do
lettings_log = FactoryBot.create(:lettings_log, lettings_log = FactoryBot.create(:lettings_log,
owning_organisation: organisation, created_by: user,
managing_organisation: organisation,
postcode_known: 1, postcode_known: 1,
postcode_full: "PO5 3TE") postcode_full: "PO5 3TE")
id = lettings_log.id id = lettings_log.id
@ -1096,8 +1091,7 @@ RSpec.describe LettingsLogsController, type: :request do
let!(:lettings_log) do let!(:lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
owning_organisation:, created_by: user,
managing_organisation: owning_organisation,
ecstat1: 1, ecstat1: 1,
) )
end end

4
spec/requests/organisations_controller_spec.rb

@ -590,8 +590,8 @@ RSpec.describe OrganisationsController, type: :request do
let(:number_of_org2_lettings_logs) { 4 } let(:number_of_org2_lettings_logs) { 4 }
before do before do
FactoryBot.create_list(:lettings_log, number_of_org1_lettings_logs, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) FactoryBot.create_list(:lettings_log, number_of_org1_lettings_logs, created_by: user)
FactoryBot.create_list(:lettings_log, number_of_org2_lettings_logs, owning_organisation_id: unauthorised_organisation.id, managing_organisation_id: unauthorised_organisation.id) FactoryBot.create_list(:lettings_log, number_of_org2_lettings_logs, created_by: nil, owning_organisation_id: unauthorised_organisation.id, managing_organisation_id: unauthorised_organisation.id)
get "/organisations/#{organisation.id}/lettings-logs", headers:, params: {} get "/organisations/#{organisation.id}/lettings-logs", headers:, params: {}
end end

Loading…
Cancel
Save