@ -18,11 +18,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context " with an organisation that the user belongs to " do
context " with an organisation that the user belongs to " do
let! ( :stock_owner ) { FactoryBot . create ( :organisation ) }
let! ( :stock_owner ) { FactoryBot . create ( :organisation ) }
let! ( :other_org_stock_owner ) { FactoryBot . create ( :organisation , name : " Foobar LTD " ) }
let! ( :other_org_stock_owner ) { FactoryBot . create ( :organisation , name : " Foobar LTD " ) }
let! ( :inactive_stock_owner ) { FactoryBot . create ( :organisation , name : " Inactive LTD " , active : false ) }
let! ( :other_organisation ) { FactoryBot . create ( :organisation , name : " Foobar LTD 2 " ) }
let! ( :other_organisation ) { FactoryBot . create ( :organisation , name : " Foobar LTD 2 " ) }
before do
before do
FactoryBot . create ( :organisation_relationship , child_organisation : organisation , parent_organisation : stock_owner )
FactoryBot . create ( :organisation_relationship , child_organisation : organisation , parent_organisation : stock_owner )
FactoryBot . create ( :organisation_relationship , child_organisation : other_organisation , parent_organisation : other_org_stock_owner )
FactoryBot . create ( :organisation_relationship , child_organisation : other_organisation , parent_organisation : other_org_stock_owner )
FactoryBot . create ( :organisation_relationship , child_organisation : organisation , parent_organisation : inactive_stock_owner )
get " /organisations/ #{ organisation . id } /stock-owners " , headers : , params : { }
get " /organisations/ #{ organisation . id } /stock-owners " , headers : , params : { }
end
end
@ -46,11 +48,18 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect ( page ) . not_to have_content ( other_org_stock_owner . name )
expect ( page ) . not_to have_content ( other_org_stock_owner . name )
end
end
it " does not show inactive stock owners " do
expect ( page ) . not_to have_content ( inactive_stock_owner . name )
end
it " shows the pagination count " do
it " shows the pagination count " do
expect ( page ) . to have_content ( " 1 total stock owners " )
expect ( page ) . to have_content ( " 1 total stock owners " )
end
end
context " when adding a stock owner " do
context " when adding a stock owner " do
let! ( :active_organisation ) { FactoryBot . create ( :organisation , name : " Active Org " , active : true ) }
let! ( :inactive_organisation ) { FactoryBot . create ( :organisation , name : " Inactive LTD " , active : false ) }
before do
before do
get " /organisations/ #{ organisation . id } /stock-owners/add " , headers : , params : { }
get " /organisations/ #{ organisation . id } /stock-owners/add " , headers : , params : { }
end
end
@ -66,6 +75,11 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it " shows a cancel button " do
it " shows a cancel button " do
expect ( page ) . to have_link ( " Cancel " , href : " /organisations/ #{ organisation . id } /stock-owners " )
expect ( page ) . to have_link ( " Cancel " , href : " /organisations/ #{ organisation . id } /stock-owners " )
end
end
it " includes only active organisations as options " do
expect ( response . body ) . to include ( active_organisation . name )
expect ( response . body ) . not_to include ( inactive_organisation . name )
end
end
end
end
end
@ -84,11 +98,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context " with an organisation that the user belongs to " do
context " with an organisation that the user belongs to " do
let! ( :managing_agent ) { FactoryBot . create ( :organisation ) }
let! ( :managing_agent ) { FactoryBot . create ( :organisation ) }
let! ( :other_org_managing_agent ) { FactoryBot . create ( :organisation , name : " Foobar LTD " ) }
let! ( :other_org_managing_agent ) { FactoryBot . create ( :organisation , name : " Foobar LTD " ) }
let! ( :inactive_managing_agent ) { FactoryBot . create ( :organisation , name : " Inactive LTD " , active : false ) }
let! ( :other_organisation ) { FactoryBot . create ( :organisation , name : " Foobar LTD " ) }
let! ( :other_organisation ) { FactoryBot . create ( :organisation , name : " Foobar LTD " ) }
before do
before do
FactoryBot . create ( :organisation_relationship , parent_organisation : organisation , child_organisation : managing_agent )
FactoryBot . create ( :organisation_relationship , parent_organisation : organisation , child_organisation : managing_agent )
FactoryBot . create ( :organisation_relationship , parent_organisation : other_organisation , child_organisation : other_org_managing_agent )
FactoryBot . create ( :organisation_relationship , parent_organisation : other_organisation , child_organisation : other_org_managing_agent )
FactoryBot . create ( :organisation_relationship , parent_organisation : organisation , child_organisation : inactive_managing_agent )
get " /organisations/ #{ organisation . id } /managing-agents " , headers : , params : { }
get " /organisations/ #{ organisation . id } /managing-agents " , headers : , params : { }
end
end
@ -112,12 +128,19 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect ( page ) . not_to have_content ( other_org_managing_agent . name )
expect ( page ) . not_to have_content ( other_org_managing_agent . name )
end
end
it " does not show inactive managing-agents " do
expect ( page ) . not_to have_content ( inactive_managing_agent . name )
end
it " shows the pagination count " do
it " shows the pagination count " do
expect ( page ) . to have_content ( " 1 total managing agents " )
expect ( page ) . to have_content ( " 1 total managing agents " )
end
end
end
end
context " when adding a managing agent " do
context " when adding a managing agent " do
let! ( :active_organisation ) { FactoryBot . create ( :organisation , name : " Active Org " , active : true ) }
let! ( :inactive_organisation ) { FactoryBot . create ( :organisation , name : " Inactive LTD " , active : false ) }
before do
before do
get " /organisations/ #{ organisation . id } /managing-agents/add " , headers : , params : { }
get " /organisations/ #{ organisation . id } /managing-agents/add " , headers : , params : { }
end
end
@ -125,6 +148,11 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it " has the correct header " do
it " has the correct header " do
expect ( response . body ) . to include ( " What is the name of your managing agent? " )
expect ( response . body ) . to include ( " What is the name of your managing agent? " )
end
end
it " includes only active organisations as options " do
expect ( response . body ) . to include ( active_organisation . name )
expect ( response . body ) . not_to include ( inactive_organisation . name )
end
end
end
context " with an organisation that are not in scope for the user, i.e. that they do not belong to " do
context " with an organisation that are not in scope for the user, i.e. that they do not belong to " do