FEATURE: Locale support for seeded categories and topics (#7110)

This commit is contained in:
Gerhard Schlager
2019-03-18 21:09:13 +01:00
committed by GitHub
parent d91b47064e
commit 3fd04df781
33 changed files with 985 additions and 353 deletions

View File

@ -28,7 +28,11 @@ RSpec.describe Admin::SiteTextsController do
put "/admin/customize/site_texts/some_key.json", params: {
site_text: { value: 'foo' }
}
expect(response.status).to eq(404)
put "/admin/customize/reseed.json", params: {
category_ids: [], topic_ids: []
}
expect(response.status).to eq(404)
end
end
@ -243,5 +247,57 @@ RSpec.describe Admin::SiteTextsController do
expect(json['site_text']['value']).to_not eq(ru_mf_text)
end
end
context "reseeding" do
before do
staff_category = Fabricate(
:category,
name: "Staff EN",
user: Discourse.system_user
)
SiteSetting.staff_category_id = staff_category.id
guidelines_topic = Fabricate(
:topic,
title: "The English Guidelines",
category: @staff_category,
user: Discourse.system_user
)
Fabricate(:post, topic: guidelines_topic, user: Discourse.system_user)
SiteSetting.guidelines_topic_id = guidelines_topic.id
end
describe '#get_reseed_options' do
it 'returns correct json' do
get "/admin/customize/reseed.json"
expect(response.status).to eq(200)
expected_reseed_options = {
categories: [
{ id: "uncategorized_category_id", name: I18n.t("uncategorized_category_name"), selected: true },
{ id: "staff_category_id", name: "Staff EN", selected: true }
],
topics: [{ id: "guidelines_topic_id", name: "The English Guidelines", selected: true }]
}
expect(JSON.parse(response.body, symbolize_names: true)).to eq(expected_reseed_options)
end
end
describe '#reseed' do
it 'reseeds categories and topics' do
SiteSetting.default_locale = :de
post "/admin/customize/reseed.json", params: {
category_ids: ["staff_category_id"],
topic_ids: ["guidelines_topic_id"]
}
expect(response.status).to eq(200)
expect(Category.find(SiteSetting.staff_category_id).name).to eq(I18n.t("staff_category_name"))
expect(Topic.find(SiteSetting.guidelines_topic_id).title).to eq(I18n.t("guidelines_topic.title"))
end
end
end
end
end