add working home controller test and login_helper
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
viehlieb 2022-09-27 09:45:28 +02:00
parent 3d55c68bad
commit 0dcbf16814
3 changed files with 34 additions and 2 deletions

View file

@ -2,10 +2,16 @@
require 'spec_helper'
describe HomeController do
describe HomeController, type: :controller do
let(:user) { create(:user) }
describe "GET profile" do
before do
login user
end
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)
end
end

View file

@ -51,6 +51,7 @@ RSpec.configure do |config|
# --seed 1234
config.order = "random"
config.include SpecTestHelper, type: :controller
config.include SessionHelper, type: :feature
# Automatically determine spec from directory structure, see:

View 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