-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Set topic subtype when embedding topics (#198)
* FIX: Set topic subtype when embedding topics This commit registers a modifier to set the subtype of a topic to `Topic::POST_VOTING_SUBTYPE` during the embedding process when certain conditions are met: - a new topic is being created; - the topic will be saved to a valid category; - the category has either `create_as_post_voting_default` or `only_post_voting_in_this_category` set to `true`
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe TopicEmbed do | ||
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) } | ||
let(:title) { "How to turn a fish from good to evil in 30 seconds" } | ||
let(:url) { "http://eviltrout.com/123" } | ||
let(:contents) do | ||
"<p>hello world new post <a href='/hello'>hello</a> <img src='images/wat.jpg'></p>" | ||
end | ||
fab!(:embeddable_host) | ||
let(:category) { Fabricate(:category) } | ||
|
||
it "creates the topic with the right subtype in a category with `create_as_post_voting_default == true`" do | ||
category.custom_fields[PostVoting::CREATE_AS_POST_VOTING_DEFAULT] = true | ||
category.save! | ||
|
||
Jobs.run_immediately! | ||
imported_post = | ||
TopicEmbed.import( | ||
user, | ||
"http://eviltrout.com/abcd", | ||
title, | ||
"some random content", | ||
category_id: category.id, | ||
) | ||
|
||
expect(imported_post.topic.category).to eq(category) | ||
expect(imported_post.topic.subtype).to eq(Topic::POST_VOTING_SUBTYPE) | ||
end | ||
|
||
it "creates the topic with the right subtype in a category with `only_post_voting_in_this_category == true`" do | ||
category.custom_fields[PostVoting::ONLY_POST_VOTING_IN_THIS_CATEGORY] = true | ||
category.save! | ||
|
||
Jobs.run_immediately! | ||
imported_post = | ||
TopicEmbed.import( | ||
user, | ||
"http://eviltrout.com/abcd", | ||
title, | ||
"some random content", | ||
category_id: category.id, | ||
) | ||
|
||
expect(imported_post.topic.category).to eq(category) | ||
expect(imported_post.topic.subtype).to eq(Topic::POST_VOTING_SUBTYPE) | ||
end | ||
|
||
it "doesn't change the subtype when the category is not set to use post voting by default" do | ||
Jobs.run_immediately! | ||
imported_post = | ||
TopicEmbed.import( | ||
user, | ||
"http://eviltrout.com/abcd", | ||
title, | ||
"some random content", | ||
category_id: category.id, | ||
) | ||
|
||
expect(imported_post.topic.category).to eq(category) | ||
expect(imported_post.topic.subtype).not_to eq(Topic::POST_VOTING_SUBTYPE) | ||
end | ||
end |