From 2f9dbdbd8668cba8e5552451bc8ad92033ef8f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Tue, 18 Sep 2012 15:52:57 +0200 Subject: [PATCH] use self instead of AppConfig to query redis_url inside AppConfig --- app/models/app_config.rb | 6 ++-- spec/models/app_config_spec.rb | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 5d350e78a..a2b8e1091 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -183,9 +183,9 @@ HELP redis_options = { :url => ENV['REDIS_URL'] } elsif ENV['RAILS_ENV']== 'integration2' redis_options = { :host => 'localhost', :port => 6380 } - elsif AppConfig[:redis_url].present? - puts "WARNING: You're redis_url doesn't start with redis://" unless AppConfig[:redis_url].start_with?("redis://") - redis_options = { :url => AppConfig[:redis_url] } + elsif self[:redis_url].present? + puts "WARNING: You're redis_url doesn't start with redis://" unless self[:redis_url].start_with?("redis://") + redis_options = { :url => self[:redis_url] } end Redis.new(redis_options.merge(:thread_safe => true)) diff --git a/spec/models/app_config_spec.rb b/spec/models/app_config_spec.rb index 25a34d98c..792fd84cb 100644 --- a/spec/models/app_config_spec.rb +++ b/spec/models/app_config_spec.rb @@ -178,6 +178,56 @@ describe AppConfig do end end + describe ".get_redis_instance" do + context "with REDISTOGO_URL set" do + before do + ENV["REDISTOGO_URL"] = "redis://myserver" + end + + after do + ENV["REDISTOGO_URL"] = nil + end + + it "uses that" do + AppConfig.get_redis_instance.client.host.should == "myserver" + end + end + + context "with REDIS_URL set" do + before do + ENV["REDIS_URL"] = "redis://yourserver" + end + + after do + ENV["REDIS_URL"] = nil + end + + it "uses that" do + AppConfig.get_redis_instance.client.host.should == "yourserver" + end + end + + context "with redis_url set" do + before do + AppConfig[:redis_url] = "redis://ourserver" + end + + after do + AppConfig[:redis_url] = "" + end + + it "uses that" do + AppConfig.get_redis_instance.client.host.should == "ourserver" + end + end + + context "with nothing set" do + it "uses localhost" do + AppConfig.get_redis_instance.client.host.should == "127.0.0.1" + end + end + end + describe ".[]=" do describe "when setting pod_url" do context "with a symbol" do