Permalink
Browse files

Pass tests

  • Loading branch information...
1 parent ec209f3 commit 020b8cc58a2f9e4ddffbb3384c8f24d6cb761889 @gkop gkop committed Nov 6, 2012
Showing with 23 additions and 10 deletions.
  1. +5 −5 lib/tweeter.rb
  2. +18 −5 spec/lib/tweeter_spec.rb
View
@@ -12,12 +12,12 @@ def self.blog_post_tweet(post)
def self.build_tweet(post)
url = build_url(post)
- text = random_tweet post
- text = short_tweet post if tweet_length(text, url) > MAXIMUM_LENGTH
+ text = random_tweet(post, url)
+ text = short_tweet(post, url) if tweet_length(text, url) > MAXIMUM_LENGTH
text
end
- def self.random_tweet(post, url)
+ def self.random_tweet(post, url=build_url(post))
name = post.author.name
title = post.title
[
@@ -27,7 +27,7 @@ def self.random_tweet(post, url)
].shuffle.first
end
- def self.short_tweet(post, url)
+ def self.short_tweet(post, url=build_url(post))
title = post.title
text = "Check out our newest blog post at #{url} about \"#{title}\""
@@ -44,7 +44,7 @@ def self.build_url(post)
def self.tweet_length(text, url)
# Url's only count for 20 chars at most
if url.length > 20
- text.length - url_length + 20
+ text.length - url.length + 20
else
text.length
end
View
@@ -1,6 +1,14 @@
require 'spec_helper'
describe Tweeter do
+ let(:post) { mock_model(Post) }
+ let(:permalink_attrs) { {:year => '2012', :month => '1', :day => '1',
+ :title => 'Title!'} }
+
+ before do
+ ENV['COSHX_HOST'] = 'example.com'
+ end
+
describe "blog post tweet" do
it "sends twitter a tweet about the blog post" do
Twitter.should_receive(:update)
@@ -14,7 +22,8 @@
it "returns the random tweet" do
described_class.should_not_receive :short_tweet
- described_class.build_tweet(mock_model(Post)).should == 'hello'
+ post.should_receive(:permalink_attributes).and_return(permalink_attrs)
+ described_class.build_tweet(post).should == 'hello'
end
end
@@ -25,14 +34,15 @@
end
it "returns a short tweet" do
- described_class.build_tweet(mock_model(Post)).should == 'hello'
+ post.should_receive(:permalink_attributes).and_return(permalink_attrs)
+ described_class.build_tweet(post).should == 'hello'
end
end
end
describe "short tweet" do
let(:title) { "Hey dog I heard you like twitter so I put some tweets in a tweeter module so you can tweet after you blog. Hey dog I heard you like twitter so I put some tweets in a tweeter module so you can tweet after you blog." }
- let(:post) { build_stubbed :post, title: title }
+ let(:post) { build_stubbed :post, title: title, posted_on: Date.parse("5/5/12")}
it "trims tweets to 140 chars" do
described_class.short_tweet(post).length.should == 140
@@ -42,8 +52,11 @@
describe "random tweet should contain the" do
let(:author) { 'Calvin' }
let(:title) { 'Why is Twitter always down?' }
- let(:url) { Rails.application.routes.url_helpers.post_url post }
- let(:post) { build_stubbed :post, author: build_stubbed(:admin, :name => author), title: title }
+ let(:url) do
+ Rails.application.routes.url_helpers.show_post_url(
+ post.permalink_attributes.merge(:host => ENV['COSHX_HOST']))
+ end
+ let(:post) { build_stubbed :post, author: build_stubbed(:admin, :name => author), title: title, posted_on: Date.parse("5/5/12")}
subject { Tweeter.random_tweet post }
it "author" do

0 comments on commit 020b8cc

Please sign in to comment.