use self instead of AppConfig to query redis_url inside AppConfig

This commit is contained in:
Jonne Haß 2012-09-18 15:52:57 +02:00
parent 6c1a1ec6d2
commit 2f9dbdbd86
2 changed files with 53 additions and 3 deletions

View file

@ -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))

View file

@ -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