From be3924aa5453c12b827fba51cd68bff96f632022 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 21:32:50 +0800 Subject: [PATCH] setup bare minimum devise authentication in tests --- app/controllers/application_controller.rb | 13 ++++++++----- app/controllers/metacodes_controller.rb | 1 - spec/controllers/metacodes_controller_spec.rb | 4 ++++ spec/rails_helper.rb | 3 +++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c0de632a..1c6c3f35 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,17 +50,20 @@ private end def authenticated? + return nil if warden.nil? #rspec tests current_user end def admin? - current_user && current_user.admin + authenticated? && current_user.admin end def get_invite_link - unsafe_uri = request.env["REQUEST_URI"] - valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ - safe_uri = unsafe_uri.try(:match, valid_url) ? unsafe_uri : "http://metamaps.cc/" - @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") + unless warden.nil? # rspec tests + unsafe_uri = request.env["REQUEST_URI"] + valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ + safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/" + @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") + end end end diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 7a14f2a8..5d1e1367 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -1,5 +1,4 @@ class MetacodesController < ApplicationController - before_filter :require_admin, except: [:index] # GET /metacodes diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index 604609a0..c3e8a906 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -19,6 +19,10 @@ require 'rails_helper' # that an instance is receiving a specific message. RSpec.describe MetacodesController, :type => :controller do + before :each do + @user = User.new(admin: true) + sign_in @user + end # This should return the minimal set of attributes required to create a valid # Metacode. As you add validations to Metacode, be sure to diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 53365a50..d8e80d32 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -45,4 +45,7 @@ RSpec.configure do |config| # The different available types are documented in the features, such as in # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! + + config.include Devise::TestHelpers, type: :controller + end