From 828cbab792a331f701f35ffef2f2d64c1dc863ec Mon Sep 17 00:00:00 2001 From: Sarah Mei <sarahmei@gmail.com> Date: Sat, 28 May 2011 20:13:38 -0700 Subject: [PATCH] Keep pod_url and pod_uri settings in sync. --- app/models/app_config.rb | 5 ++++- spec/models/app_config_spec.rb | 30 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 33b29956dd..f84a0f46cd 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -75,8 +75,11 @@ HELP end def self.[]= (key, value) - @@pod_uri = nil if key == :pod_url super + if key.to_sym == :pod_url + @@pod_uri = nil + normalize_pod_url + end end cattr_accessor :pod_uri diff --git a/spec/models/app_config_spec.rb b/spec/models/app_config_spec.rb index 2ce2d8a5fc..d2f974c5eb 100644 --- a/spec/models/app_config_spec.rb +++ b/spec/models/app_config_spec.rb @@ -146,10 +146,32 @@ describe AppConfig do pod_uri.scheme.should == "http" pod_uri.host.should == "example.org" end - it "clears the cached pod_uri when you set pod_url" do - AppConfig[:pod_uri].host.should == "example.org" - AppConfig[:pod_url] = "http://joindiaspora.com" - AppConfig[:pod_uri].host.should == "joindiaspora.com" + end + + describe ".[]=" do + describe "when setting pod_url" do + context "with a symbol" do + it "clears the cached pod_uri" do + AppConfig[:pod_uri].host.should == "example.org" + AppConfig[:pod_url] = "http://joindiaspora.com" + AppConfig[:pod_uri].host.should == "joindiaspora.com" + end + it "calls normalize_pod_url" do + AppConfig.should_receive(:normalize_pod_url).twice + AppConfig[:pod_url] = "http://joindiaspora.com" + end + end + context "with a string" do + it "clears the cached pod_uri" do + AppConfig[:pod_uri].host.should == "example.org" + AppConfig['pod_url'] = "http://joindiaspora.com" + AppConfig[:pod_uri].host.should == "joindiaspora.com" + end + it "calls normalize_pod_url" do + AppConfig.should_receive(:normalize_pod_url).twice + AppConfig['pod_url'] = "http://joindiaspora.com" + end + end end end end \ No newline at end of file -- GitLab