В application_controller
У меня есть два метода, результаты которых я хочу проверить в maintenance_mode_controller_specs
. Как создать макет maintenance_mode_active?
, который будет возвращать false
, чтобы использовать его внутри check_maintenance?
?
application_controller.rb
before_action: check_maintenance?
private
def check_maintenance?
if maintenance_mode_active? == true
redirect_to maintenance_mode
elsif request.fullpath.include?(maintenance_mode_path)
redirect_to :root
end
end
def maintenance_mode_active?
# do sth ...
mode.active?
end
maintenance_mode_controller_spec.rb
context 'when maintenance mode is active' do
let(:maintenance_mode?) { instance_double(ApplicationController) }
before do
allow(ApplicationController).to receive(:maintenance_mode_active?).and_return(false)
end
it 'redirect to root path' do
expect(described_class).should redirect_to(maintenance_mode_path)
end
end