fix date and guid assignment for fetched posts
This commit is contained in:
parent
3ae76cd5eb
commit
2e3da0cf05
2 changed files with 41 additions and 5 deletions
|
|
@ -103,17 +103,26 @@ class PublicFetcher
|
||||||
|
|
||||||
FEDERATION_LOGGER.debug post.to_s[0..250]
|
FEDERATION_LOGGER.debug post.to_s[0..250]
|
||||||
|
|
||||||
|
# disable some stuff we don't want for bulk inserts
|
||||||
|
StatusMessage.skip_callback :create, :set_guid
|
||||||
|
|
||||||
entry = StatusMessage.diaspora_initialize(
|
entry = StatusMessage.diaspora_initialize(
|
||||||
:author => @person,
|
:author => @person,
|
||||||
:public => true,
|
:public => true
|
||||||
|
)
|
||||||
|
entry.assign_attributes({
|
||||||
:guid => post['guid'],
|
:guid => post['guid'],
|
||||||
:text => post['text'],
|
:text => post['text'],
|
||||||
:provider_display_name => post['provider_display_name'],
|
:provider_display_name => post['provider_display_name'],
|
||||||
:created_at => ActiveSupport::TimeZone.new('UTC').parse(post['created_at']),
|
:created_at => ActiveSupport::TimeZone.new('UTC').parse(post['created_at']).to_datetime,
|
||||||
:interacted_at => ActiveSupport::TimeZone.new('UTC').parse(post['interacted_at']),
|
:interacted_at => ActiveSupport::TimeZone.new('UTC').parse(post['interacted_at']).to_datetime,
|
||||||
:frame_name => post['frame_name']
|
:frame_name => post['frame_name']
|
||||||
)
|
}, :without_protection => true)
|
||||||
entry.save
|
entry.save
|
||||||
|
|
||||||
|
# re-enable everything we disabled before
|
||||||
|
StatusMessage.set_callback :create, :set_guid
|
||||||
|
|
||||||
end
|
end
|
||||||
set_fetch_status PublicFetcher::Status_Processed
|
set_fetch_status PublicFetcher::Status_Processed
|
||||||
end
|
end
|
||||||
|
|
@ -173,4 +182,4 @@ class PublicFetcher
|
||||||
|
|
||||||
type_ok
|
type_ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,33 @@ describe PublicFetcher do
|
||||||
@person.fetch_status.should_not eql(PublicFetcher::Status_Initial)
|
@person.fetch_status.should_not eql(PublicFetcher::Status_Initial)
|
||||||
@person.fetch_status.should eql(PublicFetcher::Status_Processed)
|
@person.fetch_status.should eql(PublicFetcher::Status_Processed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'created post' do
|
||||||
|
before do
|
||||||
|
@data = JSON.parse(@fixture).select { |item| item['post_type'] == 'StatusMessage' }
|
||||||
|
|
||||||
|
#save posts to db
|
||||||
|
@fetcher.instance_eval {
|
||||||
|
process_posts
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'applies the date from JSON to the record' do
|
||||||
|
@data.each do |post|
|
||||||
|
date = ActiveSupport::TimeZone.new('UTC').parse(post['created_at'])
|
||||||
|
|
||||||
|
entry = StatusMessage.find_by_guid(post['guid'])
|
||||||
|
entry.created_at.should eql(date)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'copied the text correctly' do
|
||||||
|
@data.each do |post|
|
||||||
|
entry = StatusMessage.find_by_guid(post['guid'])
|
||||||
|
entry.raw_message.should eql(post['text'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "private methods" do
|
context "private methods" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue