twog 0.3.0 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +20 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +120 -0
- data/History.rdoc +35 -4
- data/LICENSE +3 -1
- data/README.md +77 -0
- data/Rakefile +15 -20
- data/VERSION.yml +3 -3
- data/bin/twog +36 -14
- data/lib/twog.rb +31 -21
- data/lib/twog/blog_posts_handler.rb +9 -7
- data/lib/twog/post.rb +23 -0
- data/lib/twog/rss_entry_to_twog_post_mapper.rb +7 -0
- data/lib/twog/rss_parser.rb +11 -9
- data/lib/twog/twitter_handler.rb +32 -44
- data/spec/spec_helper.rb +63 -59
- data/spec/twog/blog_posts_handler_spec.rb +38 -0
- data/spec/twog/post_spec.rb +77 -0
- data/spec/twog/rss_entry_to_twog_post_mapper_spec.rb +32 -0
- data/spec/twog/rss_parser_spec.rb +17 -0
- data/spec/{twitter_handler_spec.rb → twog/twitter_handler_spec.rb} +25 -27
- data/spec/twog/twog_spec.rb +43 -0
- data/twog.gemspec +64 -56
- metadata +170 -85
- data/.gitignore +0 -3
- data/README.textile +0 -49
- data/spec/blog_posts_handler_spec.rb +0 -33
- data/spec/rss_parser_spec.rb +0 -18
- data/spec/twog_spec.rb +0 -40
data/lib/twog.rb
CHANGED
@@ -9,32 +9,42 @@ require 'bitly'
|
|
9
9
|
|
10
10
|
# internal requires
|
11
11
|
require 'twog/rss_parser'
|
12
|
+
require 'twog/rss_entry_to_twog_post_mapper'
|
12
13
|
require 'twog/blog_posts_handler'
|
13
14
|
require 'twog/twitter_handler'
|
15
|
+
require 'twog/post'
|
14
16
|
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
module Twog
|
19
|
+
module Twog
|
20
|
+
include RssParser
|
21
|
+
include RssEntryToTwogPostMapper
|
22
|
+
include BlogPostsHandler
|
23
|
+
include TwitterHandler
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
25
|
+
def run(conf)
|
26
|
+
posts = get_posts_to_tweet(conf)
|
27
|
+
return unless posts && posts.length > 0
|
28
|
+
bitly = get_bitly_from(conf)
|
29
|
+
tweet(posts, conf, bitly)
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
def get_posts_to_tweet(conf)
|
33
|
+
posts = parse_feed(conf['rss_feed'])
|
34
|
+
posts = map(posts)
|
35
|
+
posts = get_new_blog_posts(posts, conf['last_blog_post_tweeted'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_bitly_from(conf)
|
39
|
+
bitly_username = conf['bitly_username']
|
40
|
+
bitly_api_key = conf['bitly_api_key']
|
41
|
+
return nil unless (bitly_username && bitly_api_key)
|
42
|
+
Bitly.new(bitly_username, bitly_api_key)
|
43
|
+
end
|
44
|
+
|
45
|
+
def version
|
46
|
+
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
|
47
|
+
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
|
48
|
+
end
|
39
49
|
end
|
40
50
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Twog
|
2
|
+
module BlogPostsHandler
|
3
|
+
def get_new_blog_posts(posts, last_blog_post_tweeted)
|
4
|
+
return [] unless posts && posts.length > 0
|
5
|
+
return posts unless last_blog_post_tweeted
|
6
|
+
new_posts = posts.reject do |post|
|
7
|
+
Time.parse(post.date.to_s) <= Time.parse(last_blog_post_tweeted.to_s)
|
8
|
+
end
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/twog/post.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Twog
|
2
|
+
class Post
|
3
|
+
def initialize(post)
|
4
|
+
@post = post
|
5
|
+
end
|
6
|
+
|
7
|
+
def link
|
8
|
+
@post.link.respond_to?('href') ? @post.link.href : @post.link
|
9
|
+
end
|
10
|
+
|
11
|
+
def date
|
12
|
+
@post.respond_to?('updated') ? @post.updated.content : @post.pubDate
|
13
|
+
end
|
14
|
+
|
15
|
+
def title
|
16
|
+
@post.title.respond_to?('content') ? @post.title.content : @post.title
|
17
|
+
end
|
18
|
+
|
19
|
+
def <=>(other_post)
|
20
|
+
Time.parse(self.date.to_s) <=> Time.parse(other_post.date.to_s)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/twog/rss_parser.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Twog
|
2
|
+
module RssParser
|
3
|
+
def parse_feed(rss_feed_url)
|
4
|
+
raise Exception.new('RSS feed missing') unless rss_feed_url
|
5
|
+
rss = RSS::Parser.parse(get_content(rss_feed_url), false)
|
6
|
+
rss.items
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def get_content(rss_feed_url)
|
10
|
+
open(rss_feed_url) do |f|
|
11
|
+
f.read
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/twog/twitter_handler.rb
CHANGED
@@ -1,51 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Twog
|
2
|
+
module TwitterHandler
|
3
|
+
def tweet(posts, conf, bitly)
|
4
|
+
return unless posts && posts.length > 0
|
5
|
+
raise Exception.new('OAuth Consumer Key missing') unless conf['consumer_key']
|
6
|
+
raise Exception.new('OAuth Consumer Secret missing') unless conf['consumer_secret']
|
7
|
+
raise Exception.new('OAuth Access Token missing') unless conf['access_token']
|
8
|
+
raise Exception.new('OAuth Access Secret missing') unless conf['access_secret']
|
9
|
+
posts.sort.each do |post|
|
10
|
+
link = bitly ? bitly.shorten(post.link).short_url : item.link
|
11
|
+
use_twitter_oauth(post, link, conf)
|
12
|
+
update_config_file_with_latest_tweet_date(post.date.to_s, conf)
|
13
|
+
end
|
11
14
|
end
|
12
|
-
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
update_config_file_with_latest_tweet_date(item.updated.content.to_s, conf)
|
16
|
+
def use_twitter_oauth(post, link, conf)
|
17
|
+
client = TwitterOAuth::Client.new(
|
18
|
+
:consumer_key => conf['consumer_key'],
|
19
|
+
:consumer_secret => conf['consumer_secret'],
|
20
|
+
:token => conf['access_token'],
|
21
|
+
:secret => conf['access_secret']
|
22
|
+
)
|
23
|
+
raise Exception.new('TwitterOAuth unauthorized') unless client.authorized?
|
24
|
+
text = ensure_text_is_of_length(140, post.title, link)
|
25
|
+
client.update(text)
|
26
26
|
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def use_twitter_oauth(item, link, conf)
|
30
|
-
client = TwitterOAuth::Client.new(
|
31
|
-
:consumer_key => conf['consumer_key'],
|
32
|
-
:consumer_secret => conf['consumer_secret'],
|
33
|
-
:token => conf['access_token'],
|
34
|
-
:secret => conf['access_secret']
|
35
|
-
)
|
36
|
-
raise Exception.new('TwitterOAuth unauthorized') unless client.authorized?
|
37
|
-
text = ensure_text_is_of_length(140, item.title.content, link)
|
38
|
-
client.update(text)
|
39
|
-
end
|
40
27
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
28
|
+
def ensure_text_is_of_length(length, title, link)
|
29
|
+
blogged = "blogged:"
|
30
|
+
title = title[0,(length-((" "*2).length+blogged.length+link.length))]
|
31
|
+
[blogged, title, link].join(' ')
|
32
|
+
end
|
46
33
|
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
def update_config_file_with_latest_tweet_date(last_blog_post_tweeted, conf)
|
35
|
+
conf['last_blog_post_tweeted'] = last_blog_post_tweeted
|
36
|
+
File.open("#{ENV['HOME']}/.twog/conf.yaml","w") { |out| out.write(conf.to_yaml) }
|
37
|
+
end
|
50
38
|
end
|
51
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,62 +1,66 @@
|
|
1
|
-
|
1
|
+
$: << File.join(File.dirname(__FILE__), "/../lib")
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'twog'
|
2
5
|
require 'rss'
|
6
|
+
require 'simplecov'
|
7
|
+
|
8
|
+
include Twog
|
9
|
+
|
10
|
+
if ENV['COVERAGE']
|
11
|
+
require 'simplecov'
|
12
|
+
SimpleCov.start
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_conf
|
16
|
+
@conf = {'rss_feed' => 'rss feed',
|
17
|
+
'bitly_username' => 'username',
|
18
|
+
'bitly_api_key' => 'api key',
|
19
|
+
'consumer_key' => 'consumerkey',
|
20
|
+
'consumer_secret' => 'consumersecret',
|
21
|
+
'access_token' => 'accesstoken',
|
22
|
+
'access_secret' => 'accesssecret',
|
23
|
+
'last_blog_post_tweeted' => '31 Mar 2010 07:52:17 -0600'}
|
24
|
+
end
|
3
25
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
<content type="html"><h1>Pair Programming</h1>
|
24
|
-
<p class="meta">29 Jan 2009 &#8211; San Antonio</p>
|
25
|
-
<p>I recently found this post, <a href="http://blog.jayfields.com/2008/02/pair-programming-all-time.html">Pair Programming all the time</a>, by <a href="http://blog.jayfields.com/">Jay Fields</a> and loved it. I&#8217;ve felt the same way about pair programming.</p>
|
26
|
-
<blockquote>
|
27
|
-
<p>&#8220;I define all the time (in terms of pairing) as when I&#8217;m writing code that I&#8217;m going to commit.&#8221;</p>
|
28
|
-
</blockquote>
|
29
|
-
<p>That is perfect. Common sense but stated explicitly. I worked in an Agile shop for 2 1/2 years and the environment was setup to highlight pair programming. Pictures and little explanation <a href="http://www.lostechies.com/blogs/joe_ocampo/archive/2007/12/09/where-the-magic-happens-our-dev-lap.aspx">here</a> (Thanks Joe). We even marked tasks in the stories as low (L) or high (H) to dictate whether a pair was necessary (this was decided during our modeling week by the two developers who tasked the story, but always up for discussion during the iteration). It worked out pretty well.</p>
|
30
|
-
<p>I understand and have heard all the reasons to not pair program. Sometimes it works and sometimes it doesn&#8217;t. I&#8217;ve personally experienced the benefits. You learn to work with different personalities and that can only benefit you in your professional career. And, the obvious reason, is immediate code review. But, as my friend Scott C. Reynolds <a href="http://www.lostechies.com/blogs/scottcreynolds/archive/2009/01/23/on-teaching-learning-and-being-honest-with-ourselves.aspx">says</a> (more or less):</p>
|
31
|
-
<blockquote>
|
32
|
-
<p>&#8220;Not everyone is cut from the same cloth&#8221;</p>
|
33
|
-
</blockquote>
|
34
|
-
<p>That is true and that is life. I hope this helps someone understand that not all pair programming enthusiasts are zealots. I know it&#8217;s a fine line though.</p></content>
|
35
|
-
</entry>
|
36
|
-
EOS
|
37
|
-
return entry
|
38
|
-
end
|
39
|
-
|
40
|
-
def rss_entry
|
41
|
-
rss = RSS::Parser.parse(rss_feed_url_content)
|
42
|
-
rss.items[0]
|
43
|
-
end
|
44
|
-
|
45
|
-
def rss_feed_url_content
|
46
|
-
post=<<-EOS
|
47
|
-
<?xml version="1.0" encoding="utf-8"?>
|
48
|
-
<feed xmlns="http://www.w3.org/2005/Atom">
|
49
|
-
|
50
|
-
<title>Jason Meridth</title>
|
51
|
-
<link href="http://blog.jasonmeridth.com/atom.xml" rel="self"/>
|
52
|
-
<link href="http://blog.jasonmeridth.com/"/>
|
53
|
-
<updated>2010-04-04T13:15:31-07:00</updated>
|
54
|
-
<id>http://blog.jasonmeridth.com/</id>
|
55
|
-
<author>
|
56
|
-
<name>Jason Meridth</name>
|
57
|
-
<email>jmeridth@gmail.com</email>
|
58
|
-
</author>
|
59
|
-
EOS
|
60
|
-
return "#{post}#{rss_feed_entry}"
|
61
|
-
end
|
26
|
+
def rss_feed_entry
|
27
|
+
entry=<<-EOS
|
28
|
+
<item>
|
29
|
+
<title>Gocode Vim Plugin and Go Modules</title>
|
30
|
+
<description>
|
31
|
+
<p><strong>Update</strong>: My friend <a href="https://twitter.com/_seemethere">Eli Uriegas</a> let me know that you don’t need <code class="highlighter-rouge">gocode</code> anymore since <code class="highlighter-rouge">vim-go</code> has autocompletion. I tested it out and he is correct. <a href="https://twitter.com/_seemethere/status/1081626050717728770">Here</a> is his tweet with a link to his dotfiles on how he sets up his <code class="highlighter-rouge">.vimrc</code> to use <code class="highlighter-rouge">vim-go</code></p> <p><em>Original Post:</em></p> <p>I recently purchased <a href="https://lets-go.alexedwards.net/">Let’s Go</a> from Alex Edwards. I wanted an end-to-end Golang website tutorial. It has been great. Lots learned.</p> <p>Unfortunately, he is using Go’s modules and the version of the gocode Vim plugin I was using did not support Go modules.</p> <h3 id="solution">Solution:</h3> <p>Use <a href="https://github.com/stamblerre/gocode">this fork</a> of the gocode Vim plugin and you’ll get support for Go modules.</p> <p>I use <a href="https://github.com/junegunn/vim-plug">Vim Plug</a> for my Vim plugins. Huge fan of Vundle but I like the post-actions feature of Plug. I just had to change one line of my vimrc and re-run updates.</p> <div class="language-diff highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gh">diff --git a/vimrc b/vimrc index 3e8edf1..8395705 100644 </span><span class="gd">--- a/vimrc </span><span class="gi">+++ b/vimrc </span><span class="gu">@@ -73,7 +73,7 @@ endif </span> let editor_name='nvim' Plug 'zchee/deoplete-go', { 'do': 'make'} endif <span class="gd">- Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.config/nvim/plugged/gocode/vim/symlink.sh' } </span><span class="gi">+ Plug 'stamblerre/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' } </span> Plug 'godoctor/godoctor.vim', {'for': 'go'} " Gocode refactoring tool " } </code></pre></div></div> <p>That is the line I had to change then run <code class="highlighter-rouge">:PlugUpdate!</code> and the new plugin was installed.</p> <p>I figured all of this out due to <a href="https://github.com/zchee/deoplete-go/issues/134#issuecomment-435436305">this comment</a> by <a href="https://github.com/cippaciong">Tommaso Sardelli</a> on Github. Thank you Tommaso.</p>
|
32
|
+
</description>
|
33
|
+
<pubDate>Sat, 05 Jan 2019 11:09:26 -0600</pubDate>
|
34
|
+
<link>
|
35
|
+
https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/
|
36
|
+
</link>
|
37
|
+
<guid isPermaLink="true">
|
38
|
+
https://blog.jasonmeridth.com/posts/gocode-vim-plugin-and-go-modules/
|
39
|
+
</guid>
|
40
|
+
<category>go</category>
|
41
|
+
<category>vim</category>
|
42
|
+
</item>
|
43
|
+
EOS
|
44
|
+
return entry
|
62
45
|
end
|
46
|
+
|
47
|
+
def rss_entry
|
48
|
+
rss = RSS::Parser.parse(rss_feed_url_content)
|
49
|
+
rss.items[0]
|
50
|
+
end
|
51
|
+
|
52
|
+
def rss_feed_url_content
|
53
|
+
rss_header=<<-EOS
|
54
|
+
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
55
|
+
<channel>
|
56
|
+
<title>Learn, Converse, Share</title>
|
57
|
+
<description>My Personal Blog</description>
|
58
|
+
<link>https://blog.jasonmeridth.com/</link>
|
59
|
+
<atom:link href="https://blog.jasonmeridth.com/feed.xml" rel="self" type="application/rss+xml"/>
|
60
|
+
<pubDate>Fri, 01 Mar 2019 13:02:56 -0600</pubDate>
|
61
|
+
<lastBuildDate>Fri, 01 Mar 2019 13:02:56 -0600</lastBuildDate>
|
62
|
+
<generator>Jekyll v3.7.4</generator>
|
63
|
+
EOS
|
64
|
+
return "#{rss_header}#{rss_feed_entry}</channel></rss>"
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
describe BlogPostsHandler do
|
4
|
+
include BlogPostsHandler
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
post = Twog::Post.new(double('', pubDate: Time.now, link: 'http://tinyurl.com'))
|
8
|
+
@posts = [post]
|
9
|
+
@last_blog_post_tweeted = test_conf['last_blog_post_tweeted']
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should determine that there is one new blog post to tweet" do
|
13
|
+
posts = get_new_blog_posts(@posts, @last_blog_post_tweeted)
|
14
|
+
expect(posts.length).to eq(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return zero if posts are nil" do
|
18
|
+
posts = get_new_blog_posts(nil, @last_blog_post_tweeted)
|
19
|
+
expect(posts.length).to eq(0)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return zero if no posts are passed" do
|
23
|
+
posts = get_new_blog_posts([], @last_blog_post_tweeted)
|
24
|
+
expect(posts.length).to eq(0)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the posts if there is no last_blog_post_tweeted in the conf file" do
|
28
|
+
posts = get_new_blog_posts(@posts, nil)
|
29
|
+
expect(posts.length).to eq(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return zero posts if the date is older than the last blog post date tweeted" do
|
33
|
+
post = Twog::Post.new(double('', pubDate: (Date.parse(@last_blog_post_tweeted.to_s) - 10).to_s, link: 'http://tinyurl.com'))
|
34
|
+
@posts = [post]
|
35
|
+
posts = get_new_blog_posts(@posts, @last_blog_post_tweeted)
|
36
|
+
expect(posts.length).to eq(0)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
describe Post do
|
4
|
+
context "when rss entry has updated and link.href" do
|
5
|
+
before(:each) do
|
6
|
+
updated =double('update', content: '2010-04-02T01:00:00-06:00')
|
7
|
+
link = double('link', href: 'http://tinyurl.com')
|
8
|
+
title = double('title', content: 'test title')
|
9
|
+
@post = double('post', updated: updated, link: link, title: title)
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a link" do
|
14
|
+
twog_post = Twog::Post.new(@post)
|
15
|
+
expect(twog_post.date).to eq("2010-04-02T01:00:00-06:00")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return a date" do
|
19
|
+
twog_post = Twog::Post.new(@post)
|
20
|
+
expect(twog_post.date).to eq("2010-04-02T01:00:00-06:00")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return a title" do
|
24
|
+
twog_post = Twog::Post.new(@post)
|
25
|
+
expect(twog_post.title).to eq("test title")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should sort multiple posts" do
|
29
|
+
unsorted = (1..10).sort_by { rand }.collect do |i|
|
30
|
+
updated = double('update', content: (Time.now + (60*60*24*i)).to_s)
|
31
|
+
link = double('link', href: 'http://tinyurl.com')
|
32
|
+
post = double('post', updated: updated, link: link)
|
33
|
+
Twog::Post.new(post)
|
34
|
+
end
|
35
|
+
sorted = unsorted.sort!
|
36
|
+
expect(sorted.length).to eq(10)
|
37
|
+
|
38
|
+
sorted.inject {|i, j| expect(Time.parse(i.date.to_s)).to be < Time.parse(j.date.to_s); j }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should leave meeting list alone if all the times are the same" do
|
42
|
+
unsorted = (1..10).collect do |i|
|
43
|
+
updated = double('update', content: (Time.now + (60*60*24*3)).to_s)
|
44
|
+
link = double('link', href: 'http://tinyurl.com')
|
45
|
+
post = double('post', updated: updated, link: link)
|
46
|
+
Twog::Post.new(post)
|
47
|
+
end
|
48
|
+
sorted = unsorted.sort!
|
49
|
+
expect(sorted.length).to eq(10)
|
50
|
+
expect(sorted).to eq(unsorted)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when rss entry has pubDate and link" do
|
55
|
+
before(:each) do
|
56
|
+
@post = double('post', pubDate: '2010-04-02T01:00:00-06:00', link: 'http://tinyurl.com')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return a link" do
|
60
|
+
twog_post = Twog::Post.new(@post)
|
61
|
+
|
62
|
+
expect(twog_post.link).to eq("http://tinyurl.com")
|
63
|
+
expect(twog_post.date).to eq("2010-04-02T01:00:00-06:00")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should sort multiple posts again" do
|
67
|
+
unsorted = (1..10).sort_by { rand }.collect do |i|
|
68
|
+
post = double('post', pubDate: (Time.now + (60*60*24*i)).to_s, link: 'http://tinyurl.com')
|
69
|
+
Twog::Post.new(post)
|
70
|
+
end
|
71
|
+
sorted = unsorted.sort!
|
72
|
+
expect(sorted.length).to eq(10)
|
73
|
+
|
74
|
+
sorted.inject {|i, j| expect(Time.parse(i.date.to_s)).to be < Time.parse(j.date.to_s); j }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|