diff --git a/app/views/plans/update.js.erb b/app/views/plans/update.js.erb new file mode 100644 index 0000000..53f05f7 --- /dev/null +++ b/app/views/plans/update.js.erb @@ -0,0 +1,7 @@ +$("form").html("<%= escape_javascript(render partial: '/edit_details', locals: {plan: @plan}) %>"); + +<% if flash[:alert].present? %> + animateNotification("<%= flash[:alert] %>", true); +<% else %> + animateNotification("<%= flash[:notice] %>", true); +<% end %> \ No newline at end of file diff --git a/test/functional/public_pages_controller_test.rb b/test/functional/public_pages_controller_test.rb new file mode 100644 index 0000000..f757a36 --- /dev/null +++ b/test/functional/public_pages_controller_test.rb @@ -0,0 +1,106 @@ +require 'test_helper' + +class PublicPagesControllerTest < ActionDispatch::IntegrationTest + + include Devise::Test::IntegrationHelpers + + setup do + @org = Org.first + scaffold_plan + + @plan.visibility = :publicly_visible + @plan.save + + @non_public_plans = [] + [:privately_visible, :organisationally_visible, :is_test].each do |vis| + @non_public_plans << Plan.create(template: @template, title: "#{vis} Plan", visibility: vis, + roles: [Role.new(user: User.last, creator: true)]) + end + + @inst_tmplt = Template.create!(title: 'Inst template', org: Org.institutions.first, migrated: false, published: true) + @dflt_tmplt = Template.create!(title: 'Dflt template', org: Org.managing_orgs.first, migrated: false, published: true, is_default: true) + @fndr_tmplt = Template.create!(title: 'Fndr template', org: Org.funders.first, migrated: false, published: true) + + [@inst_tmplt, @dflt_tmplt, @fndr_tmplt].each do |t| + t.published = true + t.is_default = true if t == @dflt_tmplt + t.save! + end + + @user = User.first + end + + # GET /public_plans (public_plans_path) + # ---------------------------------------------------------- + test 'load the list of public plans page' do + # Verify that public plans are visible when not logged in and that non-public plans are NOT in the list + get public_plans_path + assert_response :success + assert assigns(:plans) + assert @response.body.include?(plan_export_path(@plan)), "expected to see the plan download link when NOT logged in" + @non_public_plans.each do |plan| + assert_not @response.body.include?(plan_export_path(plan)), "expected to NOT see the on-public plan download link when NOT logged in" + end + + # Verify the same results are received when the user is logged in + sign_in @user + get public_plans_path + assert_response :success + assert assigns(:plans) + assert @response.body.include?(plan_export_path(@plan)), "expected to see the plan download link when NOT logged in" + @non_public_plans.each do |plan| + assert_not @response.body.include?(plan_export_path(plan)), "expected to NOT see the on-public plan download link when NOT logged in" + end + end + + # GET /plan_export/:id (plan_export_path) + # ---------------------------------------------------------- + test 'export a public plan' do + get plan_export_path(@plan, format: :pdf) + assert_response :success + + @non_public_plans.each do |p| + get plan_export_path(p, format: :pdf) + assert_response :redirect + assert_equal "You need to sign in or sign up before continuing.", flash[:alert] + assert_redirected_to root_path + end + end + + # GET /public_templates (public_templates_path) + # ---------------------------------------------------------- + test 'load the list of public templates page' do + # Verify that public templates are visible when not logged in and that non-funder and non-default + # templates are NOT in the list + get public_templates_path + assert_response :success + assert assigns(:templates) + assert @response.body.include?(template_export_path(@fndr_tmplt.dmptemplate_id)), "expected to see the funder template download link when NOT logged in" + assert @response.body.include?(template_export_path(@dflt_tmplt.dmptemplate_id)), "expected to see the default template download link when NOT logged in" + assert_not @response.body.include?(template_export_path(@inst_tmplt.dmptemplate_id)), "expected to NOT see the institution template download link when NOT logged in" + + # Verify the same results are received when the user is logged in + sign_in @user + get public_templates_path + assert_response :success + assert assigns(:templates) + assert @response.body.include?(template_export_path(@fndr_tmplt.dmptemplate_id)), "expected to see the funder template download link when NOT logged in" + assert @response.body.include?(template_export_path(@dflt_tmplt.dmptemplate_id)), "expected to see the default template download link when NOT logged in" + assert_not @response.body.include?(template_export_path(@inst_tmplt.dmptemplate_id)), "expected to NOT see the institution template download link when NOT logged in" + end + + # GET /template_export/:dmptemplate_id (template_export_path) + # ---------------------------------------------------------- + test 'export a public template' do + get template_export_path(@fndr_tmplt.dmptemplate_id, format: :pdf) + assert_response :success + + get template_export_path(@dflt_tmplt.dmptemplate_id, format: :pdf) + assert_response :success + + get template_export_path(@inst_tmplt.dmptemplate_id, format: :pdf) + assert_response :redirect + assert_equal "You need to sign in or sign up before continuing.", flash[:alert] + assert_redirected_to root_path + end +end \ No newline at end of file