@ -100,6 +100,93 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
context " when user's org has recently absorbed other orgs and has available_from date " do
let ( :merged_organisation ) { create ( :organisation , name : " Merged org " ) }
let ( :options ) do
{
" " = > " Select an option " ,
user . organisation . id = > " User org (Your organisation, active as of 2 February 2021) " ,
owning_org_2 . id = > " Owning org 2 " ,
owning_org_1 . id = > " Owning org 1 " ,
merged_organisation . id = > " Merged org (inactive as of 2 February 2023) " ,
}
end
before do
merged_organisation . update! ( merge_date : Time . zone . local ( 2023 , 2 , 2 ) , absorbing_organisation : user . organisation )
user . organisation . update! ( available_from : Time . zone . local ( 2021 , 2 , 2 ) )
end
it " shows merged organisation as an option " do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
context " when user's org has recently absorbed other orgs and does not have available from date " do
let ( :merged_organisation ) { create ( :organisation , name : " Merged org " ) }
let ( :options ) do
{
" " = > " Select an option " ,
user . organisation . id = > " User org (Your organisation) " ,
owning_org_2 . id = > " Owning org 2 " ,
owning_org_1 . id = > " Owning org 1 " ,
merged_organisation . id = > " Merged org (inactive as of 2 February 2023) " ,
}
end
before do
merged_organisation . update! ( merge_date : Time . zone . local ( 2023 , 2 , 2 ) , absorbing_organisation : user . organisation )
end
it " shows merged organisation as an option " do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
context " when user's org has recently absorbed other orgs with parent organisations " do
let ( :merged_organisation ) { create ( :organisation , name : " Merged org " ) }
let ( :options ) do
{
" " = > " Select an option " ,
user . organisation . id = > " User org (Your organisation, active as of 2 February 2021) " ,
owning_org_1 . id = > " Owning org 1 " ,
merged_organisation . id = > " Merged org (inactive as of 2 February 2023) " ,
}
end
before do
org_rel . update! ( child_organisation : merged_organisation )
merged_organisation . update! ( merge_date : Time . zone . local ( 2023 , 2 , 2 ) , absorbing_organisation : user . organisation )
user . organisation . update! ( available_from : Time . zone . local ( 2021 , 2 , 2 ) )
end
it " does not show merged organisations stock owners as options " do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
context " when user's org has absorbed other orgs with parent organisations during closed collection periods " do
let ( :merged_organisation ) { create ( :organisation , name : " Merged org " ) }
let ( :options ) do
{
" " = > " Select an option " ,
user . organisation . id = > " User org (Your organisation) " ,
owning_org_1 . id = > " Owning org 1 " ,
}
end
before do
Timecop . freeze ( Time . zone . local ( 2023 , 4 , 2 ) )
org_rel . update! ( child_organisation : merged_organisation )
merged_organisation . update! ( merge_date : Time . zone . local ( 2021 , 6 , 2 ) , absorbing_organisation : user . organisation )
user . organisation . update! ( available_from : Time . zone . local ( 2021 , 2 , 2 ) )
end
it " shows merged organisation as an option " do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
end
context " when user is support " do