@ -88,234 +88,6 @@ RSpec.describe SchemesHelper do
end
include TagHelper
describe " display_scheme_attributes " do
let ( :owning_organisation ) { FactoryBot . create ( :organisation , name : " Acme LTD Owning " ) }
let ( :managing_organisation ) { FactoryBot . create ( :organisation , name : " Acme LTD Managing " ) }
let! ( :scheme ) do
FactoryBot . create ( :scheme ,
service_name : " Test service_name " ,
sensitive : 0 ,
scheme_type : 7 ,
registered_under_care_act : 3 ,
owning_organisation : ,
arrangement_type : " V " ,
primary_client_group : " S " ,
has_other_client_group : 1 ,
secondary_client_group : " I " ,
support_type : 4 ,
intended_stay : " P " ,
created_at : Time . zone . local ( 2022 , 4 , 1 ) )
end
let! ( :scheme_where_managing_organisation_is_owning_organisation ) { FactoryBot . create ( :scheme , arrangement_type : " D " ) }
let ( :support_user ) { FactoryBot . create ( :user , :support ) }
let ( :coordinator_user ) { FactoryBot . create ( :user , :data_coordinator ) }
context " when scheme has no locations " do
it " returns correct display attributes " do
attributes = [
{ name : " Scheme code " , value : " S #{ scheme . id } " } ,
{ name : " Name " , value : " Test service_name " , edit : true } ,
{ name : " Status " , value : status_tag ( :incomplete ) } ,
{ name : " Confidential information " , value : " No " , edit : true } ,
{ name : " Type of scheme " , value : " Housing for older people " } ,
{ name : " Registered under Care Standards Act 2000 " , value : " Yes – registered care home providing personal care " } ,
{ name : " Housing stock owned by " , value : " Acme LTD Owning " , edit : true } ,
{ name : " Support services provided by " , value : " A registered charity or voluntary organisation " } ,
{ name : " Primary client group " , value : " Rough sleepers " } ,
{ name : " Has another client group " , value : " Yes " } ,
{ name : " Secondary client group " , value : " Refugees (permanent) " } ,
{ name : " Level of support given " , value : " High level " } ,
{ name : " Intended length of stay " , value : " Permanent " } ,
{ name : " Availability " , value : " Active from 1 April 2021 " } ,
]
expect ( display_scheme_attributes ( scheme ) ) . to eq ( attributes )
end
end
context " when scheme has a location " do
before do
FactoryBot . create ( :location , scheme : )
end
it " returns correct display attributes " do
attributes = [
{ name : " Scheme code " , value : " S #{ scheme . id } " } ,
{ name : " Name " , value : " Test service_name " , edit : true } ,
{ name : " Status " , value : status_tag ( :active ) } ,
{ name : " Confidential information " , value : " No " , edit : true } ,
{ name : " Type of scheme " , value : " Housing for older people " } ,
{ name : " Registered under Care Standards Act 2000 " , value : " Yes – registered care home providing personal care " } ,
{ name : " Housing stock owned by " , value : " Acme LTD Owning " , edit : true } ,
{ name : " Support services provided by " , value : " A registered charity or voluntary organisation " } ,
{ name : " Primary client group " , value : " Rough sleepers " } ,
{ name : " Has another client group " , value : " Yes " } ,
{ name : " Secondary client group " , value : " Refugees (permanent) " } ,
{ name : " Level of support given " , value : " High level " } ,
{ name : " Intended length of stay " , value : " Permanent " } ,
{ name : " Availability " , value : " Active from 1 April 2021 " } ,
]
expect ( display_scheme_attributes ( scheme ) ) . to eq ( attributes )
end
context " when the managing organisation is the owning organisation " do
it " doesn't show the organisation providing support " do
attributes = display_scheme_attributes ( scheme_where_managing_organisation_is_owning_organisation ) . find { | x | x [ :name ] == " Organisation providing support " }
expect ( attributes ) . to be_nil
end
end
context " when viewing availability " do
context " with no deactivations " do
it " displays current collection start date as availability date if created_at is later than collection start date " do
scheme . update! ( created_at : Time . zone . local ( 2022 , 4 , 16 ) )
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 " )
end
end
context " with previous deactivations " do
context " and all reactivated deactivations " do
before do
Timecop . freeze ( Time . zone . local ( 2023 , 11 , 10 ) )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 8 , 10 ) , reactivation_date : Time . zone . local ( 2022 , 9 , 1 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 9 , 15 ) , reactivation_date : Time . zone . local ( 2022 , 9 , 28 ) , scheme : )
Timecop . return
scheme . reload
end
it " displays the timeline of availability " do
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 to 9 August 2022 \n Deactivated on 10 August 2022 \n Active from 1 September 2022 to 14 September 2022 \n Deactivated on 15 September 2022 \n Active from 28 September 2022 " )
end
end
context " and non reactivated deactivation " do
before do
Timecop . freeze ( Time . zone . local ( 2023 , 11 , 10 ) )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 8 , 10 ) , reactivation_date : Time . zone . local ( 2022 , 9 , 1 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 9 , 15 ) , reactivation_date : nil , scheme : )
Timecop . return
scheme . reload
end
it " displays the timeline of availability " do
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 to 9 August 2022 \n Deactivated on 10 August 2022 \n Active from 1 September 2022 to 14 September 2022 \n Deactivated on 15 September 2022 " )
end
end
end
context " with out of order deactivations " do
context " and all reactivated deactivations " do
before do
Timecop . freeze ( Time . zone . local ( 2023 , 11 , 10 ) )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 9 , 24 ) , reactivation_date : Time . zone . local ( 2022 , 9 , 28 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 6 , 15 ) , reactivation_date : Time . zone . local ( 2022 , 6 , 18 ) , scheme : )
Timecop . return
scheme . reload
end
it " displays the timeline of availability " do
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 to 14 June 2022 \n Deactivated on 15 June 2022 \n Active from 18 June 2022 to 23 September 2022 \n Deactivated on 24 September 2022 \n Active from 28 September 2022 " )
end
end
context " and one non reactivated deactivation " do
before do
Timecop . freeze ( Time . zone . local ( 2023 , 11 , 10 ) )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 9 , 24 ) , reactivation_date : Time . zone . local ( 2022 , 9 , 28 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 6 , 15 ) , reactivation_date : nil , scheme : )
Timecop . return
scheme . reload
end
it " displays the timeline of availability " do
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 to 14 June 2022 \n Deactivated on 15 June 2022 \n Active from 28 September 2022 " )
end
end
end
context " with multiple out of order deactivations " do
context " and one non reactivated deactivation " do
before do
Timecop . freeze ( Time . zone . local ( 2023 , 11 , 10 ) )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 9 , 24 ) , reactivation_date : Time . zone . local ( 2022 , 9 , 28 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 10 , 24 ) , reactivation_date : Time . zone . local ( 2022 , 10 , 28 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 6 , 15 ) , reactivation_date : nil , scheme : )
Timecop . return
scheme . reload
end
it " displays the timeline of availability " do
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 to 14 June 2022 \n Deactivated on 15 June 2022 \n Active from 28 September 2022 to 23 October 2022 \n Deactivated on 24 October 2022 \n Active from 28 October 2022 " )
end
end
end
context " with intersecting deactivations " do
before do
Timecop . freeze ( Time . zone . local ( 2023 , 11 , 10 ) )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 10 , 10 ) , reactivation_date : Time . zone . local ( 2022 , 12 , 1 ) , scheme : )
FactoryBot . create ( :scheme_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 11 , 11 ) , reactivation_date : Time . zone . local ( 2022 , 12 , 11 ) , scheme : )
Timecop . return
scheme . reload
end
it " displays the timeline of availability " do
availability_attribute = display_scheme_attributes ( scheme ) . find { | x | x [ :name ] == " Availability " } [ :value ]
expect ( availability_attribute ) . to eq ( " Active from 1 April 2021 to 9 October 2022 \n Deactivated on 10 October 2022 \n Active from 11 December 2022 " )
end
end
end
end
context " when scheme has no secondary client group " do
before do
scheme . update! ( has_other_client_group : 0 )
end
it " returns correct display attributes " do
attributes = [
{ name : " Scheme code " , value : " S #{ scheme . id } " } ,
{ name : " Name " , value : " Test service_name " , edit : true } ,
{ name : " Status " , value : status_tag ( :incomplete ) } ,
{ name : " Confidential information " , value : " No " , edit : true } ,
{ name : " Type of scheme " , value : " Housing for older people " } ,
{ name : " Registered under Care Standards Act 2000 " , value : " Yes – registered care home providing personal care " } ,
{ name : " Housing stock owned by " , value : " Acme LTD Owning " , edit : true } ,
{ name : " Support services provided by " , value : " A registered charity or voluntary organisation " } ,
{ name : " Primary client group " , value : " Rough sleepers " } ,
{ name : " Has another client group " , value : " No " } ,
{ name : " Level of support given " , value : " High level " } ,
{ name : " Intended length of stay " , value : " Permanent " } ,
{ name : " Availability " , value : " Active from 1 April 2021 " } ,
]
expect ( display_scheme_attributes ( scheme ) ) . to eq ( attributes )
end
end
context " when scheme was merged from another organisation " do
before do
FactoryBot . create ( :location , scheme : )
scheme . startdate = Time . zone . local ( 2023 , 1 , 5 )
end
it " returns correct availability " do
expect ( display_scheme_attributes ( scheme ) ) . to include ( { name : " Availability " , value : " Active from 5 January 2023 " } )
end
end
end
describe " edit_scheme_text " do
let ( :parent_organisation ) { FactoryBot . create ( :organisation , name : " Parent " ) }
let ( :child_organisation ) { FactoryBot . create ( :organisation , name : " Child " ) }