add working home controller test and login_helper
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
3d55c68bad
commit
0dcbf16814
3 changed files with 34 additions and 2 deletions
|
@ -2,10 +2,16 @@
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe HomeController do
|
describe HomeController, type: :controller do
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
describe "GET profile" do
|
describe "GET profile" do
|
||||||
|
before do
|
||||||
|
login user
|
||||||
|
end
|
||||||
|
|
||||||
it 'shows dashboard for logged in user' do
|
it 'shows dashboard for logged in user' do
|
||||||
get :my_profile
|
get :profile, params: { foodcoop: FoodsoftConfig[:default_scope] }
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,6 +51,7 @@ RSpec.configure do |config|
|
||||||
# --seed 1234
|
# --seed 1234
|
||||||
config.order = "random"
|
config.order = "random"
|
||||||
|
|
||||||
|
config.include SpecTestHelper, type: :controller
|
||||||
config.include SessionHelper, type: :feature
|
config.include SessionHelper, type: :feature
|
||||||
|
|
||||||
# Automatically determine spec from directory structure, see:
|
# Automatically determine spec from directory structure, see:
|
||||||
|
|
25
spec/support/spec_test_helper.rb
Normal file
25
spec/support/spec_test_helper.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# spec/support/spec_test_helper.rb
|
||||||
|
module SpecTestHelper
|
||||||
|
def login_admin
|
||||||
|
login(:admin)
|
||||||
|
end
|
||||||
|
|
||||||
|
def login(user)
|
||||||
|
user = User.where(:nick => user.nick).first if user.is_a?(Symbol)
|
||||||
|
session[:user_id] = user.id
|
||||||
|
session[:scope] = FoodsoftConfig[:default_scope] # Save scope in session to not allow switching between foodcoops with one account
|
||||||
|
session[:locale] = user.locale
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def current_user
|
||||||
|
User.find(session[:user_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# spec/spec_helper.rb
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.include SpecTestHelper, :type => :controller
|
||||||
|
end
|
Loading…
Reference in a new issue