diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 51cea79..bb98094 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -21,10 +21,7 @@ #update a section of a template def admin_update @section = Section.includes(phase: :template).find(params[:id]) -puts "CONTROLLER USER: (#{current_user.can_org_admin?}) - #{current_user.inspect}" -puts "CONTROLLER ROLES: #{current_user.roles.inspect}" authorize @section -puts "THERE" @section.description = params["section-desc-#{params[:id]}"] @phase = @section.phase if @section.update_attributes(params[:section]) diff --git a/app/policies/section_policy.rb b/app/policies/section_policy.rb index f282b65..6effdbe 100644 --- a/app/policies/section_policy.rb +++ b/app/policies/section_policy.rb @@ -18,11 +18,6 @@ end def admin_update? - -puts "POLICY USER: (#{user.can_org_admin?}) - #{user.inspect}" -puts "POLICY ROLES: #{user.roles.inspect}" -puts "MODIFIER? #{user.can_modify_templates?} ORGS MATCH? #{(section.phase.template.org_id == user.org_id)}" - user.can_modify_templates? && (section.phase.template.org_id == user.org_id) end diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb index 8316bd1..893aced 100644 --- a/test/functional/sections_controller_test.rb +++ b/test/functional/sections_controller_test.rb @@ -64,12 +64,13 @@ test "update the section" do params = {title: 'Phase - UPDATE'} + puts "TEST USER (#{@user.can_org_admin?}) - #{@user.inspect}" + puts "TEST PERMS: #{@user.perms.inspect}" + # Should redirect user to the root path if they are not logged in! put admin_update_section_path(@phase.sections.first), {section: params} assert_unauthorized_redirect_to_root_path -puts "TEST USER (#{@user.can_org_admin?}) - #{@user.inspect}" -puts "TEST ROLES: #{@user.roles.inspect}" sign_in @user # Valid save diff --git a/test/test_helper.rb b/test/test_helper.rb index 239e398..578aa93 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,18 +24,14 @@ # Use the seeds.rb file to seed the test database require_relative '../db/seeds.rb' - # Add more helper methods to be used by all tests here... - # Get the organisational admin for the Org specified or create one # ---------------------------------------------------------------------- def scaffold_org_admin(org) - @user = org.users.select{|u| u.can_org_admin?}.first - @user = User.create!(email: "admin-#{org.abbreviation.downcase}@example.com", firstname: "Org", surname: "Admin", - language: Language.find_by(abbreviation: FastGettext.locale), - password: "password123", password_confirmation: "password123", - perms: Perm.where(name: ['grant_permissions', 'modify_guidance', 'modify_templates', 'modify_org_details']), - org: org, accept_terms: true, confirmed_at: Time.zone.now) if @user.nil? + language: Language.find_by(abbreviation: FastGettext.locale), + password: "password123", password_confirmation: "password123", + org: org, accept_terms: true, confirmed_at: Time.zone.now, + perms: Perm.where(name: ['grant_permissions', 'modify_guidance', 'modify_templates', 'modify_org_details'])) end @@ -204,12 +200,3 @@ to_return(:status => 200, :body => blog_feed, :headers => {}) end end - -# ============================================================================================================= -# Override the ApplicationController's current_user method since it is not set during Rails 4 integration tests -# (this will change in Rails 5). -class ApplicationController < ActionController::Base - def current_user - @user - end -end \ No newline at end of file