Skip to content

Commit

Permalink
Twitter link limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Francois committed Oct 5, 2013
1 parent 677da43 commit 668931f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/models/note.rb
Expand Up @@ -24,6 +24,7 @@ class Note < Content
TWITTER_FTP_URL_LEGTH = 19
TWITTER_HTTP_URL_LENGTH = 20
TWITTER_HTTPS_URL_LENGTH = 21
TWITTER_LINK_LENGTH = 22

def set_permalink
self.permalink = "#{self.id}-#{self.body.to_permalink[0..79]}" if self.permalink.nil? or self.permalink.empty?
Expand Down Expand Up @@ -53,7 +54,7 @@ def initialize(*args)
end

def twitter_message_max_length
140 - (7 + self.redirects.first.to_url.length)
140 - (7 + TWITTER_LINK_LENGTH)
end

def twitter_message
Expand Down Expand Up @@ -89,7 +90,8 @@ def send_to_twitter
self.save
self.user.update_twitter_profile_image(tweet.attrs[:user][:profile_image_url])
true
rescue
rescue StandardError => e
Rails.logger.error("Error while sending to twitter: #{e}")
false
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/models/note_spec.rb
Expand Up @@ -129,7 +129,6 @@
let(:tweet) { "\"JSFuck is an esoteric and educational programming style based on the atomic parts of JavaScript. It uses only six different characters to write and execute code.\" http://www.jsfuck.com/ " }

it { expect(note.twitter_message).to start_with(tweet[0..note.twitter_message_max_length]) }
it { expect(note.twitter_message.length).to be <= 140 }
it { expect(note.twitter_message).to end_with(" (#{note.redirects.first.to_url})") }
end
end
Expand Down

0 comments on commit 668931f

Please sign in to comment.