mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
RSpec setup becomes harder to follow at either extreme: trivial fixture wrappers hide lifecycle and intent, while forcing every named operation inline repeats low-level protocol and configuration details. This change documents and applies a test-setup hierarchy: - use `fab!`, `let`, `let!`, `subject`, and inline `Fabricate` according to lifecycle and role; - use a small example-group method when parameterized behavior gives one spec useful vocabulary; - move helpers into auto-loaded `spec/support` only when they are shared across spec files; - use fabricators and page objects for the data shapes and system-test interfaces they own. Core and plugin support files are loaded centrally by `rails_helper`, so plugin-specific support loaders are unnecessary. The migration specs encountered during the sweep are removed according to repository policy; production migrations are unchanged.
67 lines
2.2 KiB
Ruby
Vendored
67 lines
2.2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe "Affiliate links on localized posts" do
|
|
fab!(:admin)
|
|
fab!(:localizer_group) { Fabricate(:group, users: [admin]) }
|
|
|
|
let(:amazon_url) { "https://www.amazon.de/gp/product/B0C3WGSSWC" }
|
|
let(:affiliate_tag) { "tag=discourse-21" }
|
|
let(:post_with_link) { create_post(raw: "Great deal at #{amazon_url}", user: admin).reload }
|
|
|
|
before do
|
|
enable_current_plugin
|
|
stub_request(:get, /amazon\.de/).to_return(status: 200, body: "")
|
|
stub_request(:head, /amazon\.de/).to_return(status: 200, body: "")
|
|
Jobs.run_immediately!
|
|
SiteSetting.affiliate_amazon_de = "discourse-21"
|
|
SiteSetting.content_localization_enabled = true
|
|
SiteSetting.content_localization_allowed_groups = localizer_group.id.to_s
|
|
end
|
|
|
|
it "applies affiliate codes to a newly created localization" do
|
|
post = post_with_link
|
|
|
|
localization =
|
|
PostLocalizationCreator.create(
|
|
post: post,
|
|
locale: "ja",
|
|
raw: "お得な情報 #{amazon_url}",
|
|
user: admin,
|
|
)
|
|
|
|
expect(post.reload.cooked).to include(affiliate_tag)
|
|
expect(localization.reload.cooked).to include(affiliate_tag)
|
|
end
|
|
|
|
it "applies affiliate codes to an updated localization" do
|
|
post = post_with_link
|
|
PostLocalizationCreator.create(post: post, locale: "ja", raw: "お得な情報", user: admin)
|
|
|
|
localization =
|
|
PostLocalizationUpdater.update(
|
|
post: post,
|
|
locale: "ja",
|
|
raw: "更新されたお得な情報 #{amazon_url}",
|
|
user: admin,
|
|
)
|
|
|
|
expect(localization.reload.cooked).to include(affiliate_tag)
|
|
end
|
|
|
|
it "applies affiliate codes to an existing localization when it is recooked" do
|
|
post = post_with_link
|
|
localization =
|
|
PostLocalizationCreator.create(
|
|
post: post,
|
|
locale: "ja",
|
|
raw: "お得な情報 #{amazon_url}",
|
|
user: admin,
|
|
)
|
|
localization.update_column(:cooked, PrettyText.cook(localization.raw))
|
|
expect(localization.reload.cooked).not_to include(affiliate_tag)
|
|
|
|
Jobs::ProcessLocalizedCooked.new.execute(post_localization_id: localization.id, recook: true)
|
|
|
|
expect(localization.reload.cooked).to include(affiliate_tag)
|
|
end
|
|
end
|