-
-
Save NaN1488/7454292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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