Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for the social media URL dsl attribute

  • Loading branch information...
commit 213714f695857359060abd6a87b3bbcc1b228d95 1 parent d80e613
@fabiopelosin fabiopelosin authored
Showing with 70 additions and 18 deletions.
  1. +19 −5 lib/cocoapods_notifier/twitter_notifier.rb
  2. +51 −13 spec/unit/twitter_spec.rb
View
24 lib/cocoapods_notifier/twitter_notifier.rb
@@ -29,7 +29,8 @@ def tweet(pod)
# @return [String]
#
def status_for_pod(pod)
- make_status(pod.name, pod.summary, pod.homepage)
+ social_media_url = pod.spec.social_media_url
+ make_status(pod.name, pod.summary, pod.homepage, social_media_url)
end
# Returns the body for the tweet of the given Pod taking into account
@@ -41,16 +42,29 @@ def status_for_pod(pod)
#
# @return [String] The body of the tweet.
#
- def make_status(pod_name, pod_summary, pod_homepage)
- message = "[#{pod_name}] #{pod_summary}"
+ def make_status(name, summary, homepage, social_media_url)
+ account = account_for_social_media_url(social_media_url)
+ if account
+ message = "[#{name} by #{account}] #{summary}"
+ else
+ message = "[#{name}] #{summary}"
+ end
if message.length > message_max_length
- message = truncate_message(message, message_max_length, ELLIPSIS_STRING)
+ max_lenght = message_max_length
+ message = truncate_message(message, max_lenght, ELLIPSIS_STRING)
end
message << LINK_SEPARATOR_STRING
- message << pod_homepage
+ message << homepage
message
end
+ def account_for_social_media_url(url)
+ return nil unless url
+ reg_ex = %r[\Ahttps?://twitter.com/([^/]+)\z]
+ match_data = reg_ex.match(url)
+ "@#{match_data[1]}" if match_data
+ end
+
private
# Private Helpers
View
64 spec/unit/twitter_spec.rb
@@ -22,28 +22,66 @@
end
- #---------------------------------------------------------------------------#
+ describe "#make_status" do
+
+ it "generates a status for a Pod" do
+ name = 'Pod'
+ summary = 'A short description.'
+ homepage = 'www.example.com'
+ social_media_url = 'https://twitter.com/cocoapods'
+ result = @sut.make_status(name, summary, homepage, social_media_url)
+ result.should == "[Pod by @cocoapods] A short description. www.example.com"
+ end
- describe "Private Helpers" do
+ it "doesn't modifies short messages" do
+ result = @sut.send(:make_status, 'Pod', "A short description.", 'www.example.com', nil)
+ result.should == "[Pod] A short description. www.example.com"
+ end
+
+ it "truncates a long messages" do
+ summary = "A short description"
+ summary << "#" * 140
+ result = @sut.send(:make_status, 'Pod', summary, 'www.example.com', nil)
+ result.gsub('www.example.com', '').length.should == 119
+ result.should.match /\[Pod\] A short description.+ www.example.com/
+ end
- describe "#make_status" do
+ describe "social media URL" do
- it "doesn't modifies short messages" do
- result = @sut.send(:make_status, 'Pod', "A short description.", 'www.example.com')
- result.should == "[Pod] A short description. www.example.com"
+ before do
+ @name = 'Pod'
+ @summary = 'A short description.'
+ @homepage = 'www.example.com'
end
- it "truncates a long messages" do
- pod_summary = "A short description"
- pod_summary << "#" * 140
- result = @sut.send(:make_status, 'Pod', pod_summary, 'www.example.com')
- result.gsub('www.example.com', '').length.should == 119
- result.should.match /\[Pod\] A short description.+ www.example.com/
+ it "supports URLs with the twitter domain using the https protocol" do
+ social_media_url = 'https://twitter.com/cocoapods'
+ result = @sut.make_status(@name, @summary, @homepage, social_media_url)
+ result.should == "[Pod by @cocoapods] A short description. www.example.com"
end
+ it "supports URLs with the twitter domain using the http protocol" do
+ social_media_url = 'http://twitter.com/cocoapods'
+ result = @sut.make_status(@name, @summary, @homepage, social_media_url)
+ result.should == "[Pod by @cocoapods] A short description. www.example.com"
+ end
+
+ it "is not confused by URLs not relative to twitter" do
+ social_media_url = 'http://facebook.com/cocoapods'
+ result = @sut.make_status(@name, @summary, @homepage, social_media_url)
+ result.should == "[Pod] A short description. www.example.com"
+ end
+
+ it "handles nil social media URLs" do
+ result = @sut.make_status(@name, @summary, @homepage, nil)
+ result.should == "[Pod] A short description. www.example.com"
+ end
end
+ end
- #--------------------------------------#
+ #---------------------------------------------------------------------------#
+
+ describe "Private Helpers" do
describe "#truncate_message" do
Please sign in to comment.
Something went wrong with that request. Please try again.