diff --git a/test/functional/guidance_groups_controller_test.rb b/test/functional/guidance_groups_controller_test.rb index d9f4bd2..fd6400e 100644 --- a/test/functional/guidance_groups_controller_test.rb +++ b/test/functional/guidance_groups_controller_test.rb @@ -28,7 +28,7 @@ # admin_update_guidance_group PUT /org/admin/guidancegroup/:id/admin_update guidance_groups#admin_update setup do - @user = org_admin_from(GuidanceGroup.first.org) + scaffold_org_admin(GuidanceGroup.first.org) end # GET /org/admin/guidancegroup/:id/admin_show (admin_show_guidance_group_path) diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb index 1deaa50..d40bc2f 100644 --- a/test/functional/questions_controller_test.rb +++ b/test/functional/questions_controller_test.rb @@ -9,7 +9,7 @@ @section = @template.phases.first.sections.first # Get the first Org Admin - @user = org_admin_from(@template.org) + scaffold_org_admin(@template.org) @question_format = QuestionFormat.where(option_based: false).first end diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb index f38d68f..8316bd1 100644 --- a/test/functional/sections_controller_test.rb +++ b/test/functional/sections_controller_test.rb @@ -9,7 +9,7 @@ @phase = @template.phases.first # Get the first Org Admin - @user = org_admin_from(@template.org) + scaffold_org_admin(@template.org) end # TODO: The following methods SHOULD replace the old 'admin_' prefixed methods. The routes file already has diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 0cfa3a2..75664ef 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -8,7 +8,7 @@ scaffold_template # Get the first Org Admin - @user = org_admin_from(@template.org) + scaffold_org_admin(@template.org) end # TODO: The following methods SHOULD replace the old 'admin_' prefixed methods. The routes file already has diff --git a/test/test_helper.rb b/test/test_helper.rb index 3843548..239e398 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,27 +25,19 @@ require_relative '../db/seeds.rb' # Add more helper methods to be used by all tests here... - - # Return the user instance variable - # ---------------------------------------------------------------------- - def current_user - return @user - end - # Get the organisational admin for the Org specified or create one # ---------------------------------------------------------------------- - def org_admin_from(org) - usr = org.users.select{|u| u.can_org_admin?}.first - if usr.nil? - usr = 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) - end - usr + 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? end + # Convert Ruby Class Names into attribute names (e.g. MyClass --> my_class) # ---------------------------------------------------------------------- @@ -212,3 +204,12 @@ 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