2022-12-05 10:13:02 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SpecTestHelper
|
|
|
|
def login(user)
|
2022-11-28 11:30:38 +01:00
|
|
|
user = User.where(:nick => user.nick).first if user.is_a?(Symbol)
|
2022-12-05 10:13:02 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
def get_with_defaults(action, params: {}, xhr: false, format: nil)
|
|
|
|
params['foodcoop'] = FoodsoftConfig[:default_scope]
|
|
|
|
get action, params: params, xhr: xhr, format: format
|
|
|
|
end
|
2022-11-28 11:30:38 +01:00
|
|
|
|
|
|
|
def post_with_defaults(action, params: {}, xhr: false, format: nil)
|
|
|
|
params['foodcoop'] = FoodsoftConfig[:default_scope]
|
|
|
|
post action, params: params, xhr: xhr, format: format
|
|
|
|
end
|
2022-12-05 10:13:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2022-11-28 11:30:38 +01:00
|
|
|
config.include SpecTestHelper, :type => :controller
|
2022-12-05 10:13:02 +01:00
|
|
|
end
|