File tree 4 files changed +14
-4
lines changed
4 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ class Post < ActiveRecord::Base
3
3
validates :url , uniqueness : true
4
4
5
5
def self . sync
6
- Post . delete_all
7
6
sources . each do |source |
8
- source . new . translate . each_with_index do |hash , index |
9
- Post . create hash . merge ( source : source . name . demodulize , position : index )
7
+ post_attributes = source . new . translate
8
+ Post . where ( source : source . feed_name ) . delete_all
9
+ post_attributes . each_with_index do |hash , index |
10
+ Post . create hash . merge ( source : source . feed_name , position : index )
10
11
end
11
12
end
12
13
end
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ def self.symbol
14
14
# string of brand symbol
15
15
end
16
16
17
+ def self . feed_name
18
+ name . demodulize
19
+ end
20
+
17
21
def feed_items
18
22
# Should return a json array of the items in the feed
19
23
end
Original file line number Diff line number Diff line change 1
1
FactoryGirl . define do
2
2
factory :post do
3
- source { Post . sources . sample . name . demodulize }
3
+ source { Post . sources . sample . feed_name }
4
4
sequence ( :url ) { |n | "http://www.example-#{ n } .com" }
5
5
title 'A Post'
6
6
comments 'http://www.example.com/comments'
Original file line number Diff line number Diff line change 1
1
require 'source/base'
2
2
3
3
describe Source ::Base do
4
+ describe '#feed_name' do
5
+ it 'returns feed name' do
6
+ expect ( Source ::ProductHunt . feed_name ) . to eq ( 'ProductHunt' )
7
+ end
8
+ end
4
9
5
10
describe '.translate' do
6
11
let ( :feed_items ) { [ 1 , 2 , 3 ] }
You can’t perform that action at this time.
0 commit comments