diff --git a/test/integration/template_versioning_test.rb b/test/integration/template_versioning_test.rb index c14d408..773db78 100644 --- a/test/integration/template_versioning_test.rb +++ b/test/integration/template_versioning_test.rb @@ -107,24 +107,35 @@ # ---------------------------------------------------------- test 'plans get attached to the appropriate template version' do - # Template is published - put admin_publish_template_path(@template) - @template = Template.current(@dmptemplate_id) - liveA = Template.live(@dmptemplate_id) + funder_template = Template.create(org: Org.funders.first, title: 'Testing integration') + + # Sign in as the funder so that we cna publish the template + sign_in User.find_by(org: funder_template.org) + + # Publish the funder template + put admin_publish_template_path(funder_template) + assert_response :redirect + assert_redirected_to admin_index_template_path(funder_template.org) + + @template = Template.current(funder_template.dmptemplate_id) + liveA = Template.live(funder_template.dmptemplate_id) + @dmptemplate_id = @template.dmptemplate_id + + sign_in @user # Plan A gets attached to the template v1 - post plans_path, {plan: {funder_id: @user.org_id}} + post plans_path, {plan: {funder_id: @template.org.id}} assert @response.body.include?("id=\"template_id_#{liveA.id}\""), "expected the user to be presented with the published template" post plans_path, {template_id: liveA.id} planA = Plan.last assert_equal liveA, planA.template, "expected the latest published version to have been assigned to PlanA" - # Template v1 is updated and gets versioned to v2 + # Template v2 is updated put admin_update_template_path(@template), {template: {title: "Blah blah blah"}} @template = Template.current(@dmptemplate_id) # Plan B gets attached to the template v1 because v2 is not yet published - post plans_path, {plan: {funder_id: @user.org_id}} + post plans_path, {plan: {funder_id: @template.org.id}} assert @response.body.include?("id=\"template_id_#{liveA.id}\""), "expected the user to be presented with the published template" post plans_path, {template_id: liveA.id} planB = Plan.last @@ -133,13 +144,18 @@ # Plan A should still be attached to v1 assert_equal liveA, planA.template, "expected PlanA to still be attached to the original published version" + # Sign back in as the funder + sign_in User.find_by(org: funder_template.org) + # Template v2 is published put admin_publish_template_path(@template) @template = Template.current(@dmptemplate_id) liveB = Template.live(@dmptemplate_id) + sign_in @user + # Plan C gets attached to template v2 - post plans_path, {plan: {funder_id: @user.org_id}} + post plans_path, {plan: {funder_id: @template.org.id}} assert_not @response.body.include?("id=\"template_id_#{liveA.id}\""), "expected the user to NOT be presented with the OLD published template" assert @response.body.include?("id=\"template_id_#{liveB.id}\""), "expected the user to be presented with the published template" post plans_path, {template_id: liveB.id}