setup bare minimum devise authentication in tests
This commit is contained in:
parent
6148f55e1c
commit
be3924aa54
4 changed files with 15 additions and 6 deletions
|
@ -50,17 +50,20 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticated?
|
def authenticated?
|
||||||
|
return nil if warden.nil? #rspec tests
|
||||||
current_user
|
current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin?
|
def admin?
|
||||||
current_user && current_user.admin
|
authenticated? && current_user.admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_invite_link
|
def get_invite_link
|
||||||
|
unless warden.nil? # rspec tests
|
||||||
unsafe_uri = request.env["REQUEST_URI"]
|
unsafe_uri = request.env["REQUEST_URI"]
|
||||||
valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/
|
valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/
|
||||||
safe_uri = unsafe_uri.try(:match, valid_url) ? unsafe_uri : "http://metamaps.cc/"
|
safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/"
|
||||||
@invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "")
|
@invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class MetacodesController < ApplicationController
|
class MetacodesController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_admin, except: [:index]
|
before_filter :require_admin, except: [:index]
|
||||||
|
|
||||||
# GET /metacodes
|
# GET /metacodes
|
||||||
|
|
|
@ -19,6 +19,10 @@ require 'rails_helper'
|
||||||
# that an instance is receiving a specific message.
|
# that an instance is receiving a specific message.
|
||||||
|
|
||||||
RSpec.describe MetacodesController, :type => :controller do
|
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
|
# This should return the minimal set of attributes required to create a valid
|
||||||
# Metacode. As you add validations to Metacode, be sure to
|
# Metacode. As you add validations to Metacode, be sure to
|
||||||
|
|
|
@ -45,4 +45,7 @@ RSpec.configure do |config|
|
||||||
# The different available types are documented in the features, such as in
|
# The different available types are documented in the features, such as in
|
||||||
# https://relishapp.com/rspec/rspec-rails/docs
|
# https://relishapp.com/rspec/rspec-rails/docs
|
||||||
config.infer_spec_type_from_file_location!
|
config.infer_spec_type_from_file_location!
|
||||||
|
|
||||||
|
config.include Devise::TestHelpers, type: :controller
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue