Skip to content

Commit

Permalink
Adds blog.has_twitter_configured? + specs instead of testing the valu…
Browse files Browse the repository at this point in the history
…e of variales.
  • Loading branch information
Frédéric de Villamil committed Aug 19, 2013
1 parent 31aa708 commit 8f10197
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/blog.rb
Expand Up @@ -241,6 +241,12 @@ def urls_to_ping_for(article)
end
urls_to_ping
end

def has_twitter_configured?
return false if self.twitter_consumer_key.nil? or self.twitter_consumer_secret.nil?
return false if self.twitter_consumer_key.empty? or self.twitter_consumer_secret.empty?
true
end

private

Expand Down
42 changes: 42 additions & 0 deletions spec/models/blog_spec.rb
Expand Up @@ -157,4 +157,46 @@ def set_permalink permalink
blog.urls_to_ping_for(article).map(&:url).should eq ["http://ping.example.com/ping", "http://anotherurl.net/other_line"]
end
end

describe "Blog Twitter configuration" do
it "A blog without :twitter_consumer_key or twitter_consumer_secret should not have Twitter configured" do
blog = FactoryGirl.build(:blog)
blog.has_twitter_configured?.should == false
end

it "A blog with an empty :twitter_consumer_key and no twitter_consumer_secret should not have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_key: "")
blog.has_twitter_configured?.should == false
end

it "A blog with an empty twitter_consumer_key and an empty twitter_consumer_secret should not have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_key: "", twitter_consumer_secret: "")
blog.has_twitter_configured?.should == false
end

it "A blog with a twitter_consumer_key and no twitter_consumer_secret should not have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_key: "12345")
blog.has_twitter_configured?.should == false
end

it "A blog with a twitter_consumer_key and an empty twitter_consumer_secret should not have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_key: "12345", twitter_consumer_secret: "")
blog.has_twitter_configured?.should == false
end

it "A blog with a twitter_consumer_secret and no twitter_consumer_key should not have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_secret: "67890")
blog.has_twitter_configured?.should == false
end

it "A blog with a twitter_consumer_secret and an empty twitter_consumer_key should not have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_secret: "67890", twitter_consumer_key: "")
blog.has_twitter_configured?.should == false
end

it "A blog with a twitter_consumer_key and a twitter_consumer_secret should have Twitter configured" do
blog = FactoryGirl.build(:blog, twitter_consumer_key: "12345", twitter_consumer_secret: "67890")
blog.has_twitter_configured?.should == true
end
end
end

0 comments on commit 8f10197

Please sign in to comment.