setup bare minimum devise authentication in tests

This commit is contained in:
Devin Howard 2015-12-16 21:32:50 +08:00
parent 6148f55e1c
commit be3924aa54
4 changed files with 15 additions and 6 deletions

View file

@ -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

View file

@ -1,5 +1,4 @@
class MetacodesController < ApplicationController
before_filter :require_admin, except: [:index]
# GET /metacodes

View file

@ -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

View file

@ -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