Skip to content

Commit c053e50

Browse files
committedMar 27, 2015
Delay removal of posts
1 parent 2f49c4c commit c053e50

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed
 

‎app/models/post.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ class Post < ActiveRecord::Base
33
validates :url, uniqueness: true
44

55
def self.sync
6-
Post.delete_all
76
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)
1011
end
1112
end
1213
end

‎lib/source/base.rb

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def self.symbol
1414
# string of brand symbol
1515
end
1616

17+
def self.feed_name
18+
name.demodulize
19+
end
20+
1721
def feed_items
1822
# Should return a json array of the items in the feed
1923
end

‎spec/factories/posts.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FactoryGirl.define do
22
factory :post do
3-
source { Post.sources.sample.name.demodulize }
3+
source { Post.sources.sample.feed_name }
44
sequence(:url) {|n| "http://www.example-#{n}.com" }
55
title 'A Post'
66
comments 'http://www.example.com/comments'

‎spec/lib/source/base_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'source/base'
22

33
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
49

510
describe '.translate' do
611
let(:feed_items) { [1, 2, 3] }

0 commit comments

Comments
 (0)
Please sign in to comment.