require 'spec_helper' describe Roqua::StatusChecks::StatusController, type: :controller do context 'visiting the status page while balancer member and database is up' do it 'returns the correct status' do allow(Roqua::StatusChecks::CheckLoadBalancerMember).to receive(:balancer_member?).and_return(true) allow(Roqua::StatusChecks::CheckDbConnection).to receive(:connected?).and_return(true) get :balancer_status expect(response.status).to eq(200) expect(response.body).to eq("{\"status\":\"ok\",\"member\":true}") end end context 'visiting the status page while not balancer member and database is up' do it 'returns the correct status' do allow(Roqua::StatusChecks::CheckLoadBalancerMember).to receive(:balancer_member?).and_return(false) allow(Roqua::StatusChecks::CheckDbConnection).to receive(:connected?).and_return(true) get :balancer_status expect(response.status).to eq(503) expect(response.body).to eq("{\"status\":\"ok\",\"member\":false}") end end context 'visiting the status page while balancer member and database is down' do it 'returns the correct status' do allow(Roqua::StatusChecks::CheckLoadBalancerMember).to receive(:balancer_member?).and_return(true) allow(Roqua::StatusChecks::CheckDbConnection).to receive(:connected?).and_return(false) get :balancer_status expect(response.status).to eq(503) expect(response.body).to eq("{\"status\":\"error\",\"member\":true}") end end context 'visiting the status page while not balancer member and database is down' do it 'returns the correct status' do allow(Roqua::StatusChecks::CheckLoadBalancerMember).to receive(:balancer_member?).and_return(false) allow(Roqua::StatusChecks::CheckDbConnection).to receive(:connected?).and_return(false) get :balancer_status expect(response.status).to eq(503) expect(response.body).to eq("{\"status\":\"error\",\"member\":false}") end end context 'visiting the status page while balancer_state is on nor off' do it 'returns the correct status' do allow(Roqua::StatusChecks::CheckLoadBalancerMember).to receive(:balancer_member?) .and_raise(Roqua::StatusChecks::CheckLoadBalancerMember::InvalidStatus) get :balancer_status expect(response.status).to eq(500) expect(response.body).to eq("{\"status\":\"unknown status\"}") end end end