mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
Set created_at manually through PostCreator
This commit is contained in:
parent
5f7f87437c
commit
286a06bd4e
@ -67,6 +67,7 @@ class PostCreator
|
||||
post.no_bump = @opts[:no_bump] if @opts[:no_bump].present?
|
||||
post.extract_quoted_post_numbers
|
||||
post.acting_user = @opts[:acting_user] if @opts[:acting_user].present?
|
||||
post.created_at = Time.zone.parse(@opts[:created_at].to_s) if @opts[:created_at].present?
|
||||
|
||||
post.image_sizes = @opts[:image_sizes] if @opts[:image_sizes].present?
|
||||
post.invalidate_oneboxes = @opts[:invalidate_oneboxes] if @opts[:invalidate_oneboxes].present?
|
||||
@ -193,6 +194,7 @@ class PostCreator
|
||||
category = Category.where(name: @opts[:category]).first
|
||||
topic_params[:category_id] = category.id if category.present?
|
||||
topic_params[:meta_data] = @opts[:meta_data] if @opts[:meta_data].present?
|
||||
topic_params[:created_at] = Time.zone.parse(@opts[:created_at].to_s) if @opts[:created_at].present?
|
||||
|
||||
topic = Topic.new(topic_params)
|
||||
|
||||
|
@ -284,5 +284,27 @@ describe PostCreator do
|
||||
target_user2.notifications.count.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'setting created_at' do
|
||||
created_at = 1.week.ago
|
||||
let(:topic) do
|
||||
PostCreator.create(user,
|
||||
raw: 'This is very interesting test post content',
|
||||
title: 'This is a very interesting test post title',
|
||||
created_at: created_at)
|
||||
end
|
||||
|
||||
let(:post) do
|
||||
PostCreator.create(user,
|
||||
raw: 'This is very interesting test post content',
|
||||
topic_id: Topic.last,
|
||||
created_at: created_at)
|
||||
end
|
||||
|
||||
it 'acts correctly' do
|
||||
topic.created_at.should be_within(10.seconds).of(created_at)
|
||||
post.created_at.should be_within(10.seconds).of(created_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user