Skip to content

Instantly share code, notes, and snippets.

@NaN1488
Forked from Alpa84/gist:7454193
Last active December 28, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaN1488/7454292 to your computer and use it in GitHub Desktop.
Save NaN1488/7454292 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::API
def status
begin
DatabaseHelper::Mysql.smrt.exec_query('SELECT id FROM customers LIMIT 1')
DatabaseHelper::Mysql.scr.exec_query('SELECT id FROM filter_prefixes LIMIT 1')
DatabaseHelper::Mysql.backend.exec_query('SELECT id FROM accounts LIMIT 1')
DatabaseHelper::Mysql.delayed_job.exec_query('SELECT id FROM delayed_jobs LIMIT 1')
status = Class.new.extend DatabaseHelper
status.redis.ping
rescue => e
Airbrake.notify e
end
return true
end
end
#-------------------------------------
require 'mock_redis'
require 'spec_helper'
describe ApplicationController do
before :all do
@connection = DatabaseHelper::Mysql.scr
end
def stub_connection_to_scr method, *data
@connection.stub(method).and_return *data
DatabaseHelper::Mysql.stub(:scr).and_return @connection
end
it "should return 200 as status" do
#mr = MockRedis.new
RedisConnection.instance.stub(:connection) { raise Redis::TimeoutError, "Connection timed out" }
expect {reponse = get "status"}.to raise_error ActiveRecord::StatementInvalid
response.status.should eq 200
end
it "should return 200 as status" do
#stub_connection_to_scr :exec_query, "1", "2", "3", "4"
mr = MockRedis.new
RedisConnection.instance.stub(:connection) { raise Redis::TimeoutError, "Connection timed out" }
@connection.stub(:exec_query).and_raise( "Timed out connecting to db")
reponse = get "status"
response.status.should eq 200
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment