2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-26 04:33:29 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ExtraLocalesController do
|
|
|
|
context 'show' do
|
2018-01-09 07:23:49 +08:00
|
|
|
it "caches for 24 hours if version is provided and it matches current hash" do
|
2018-06-06 17:45:29 +08:00
|
|
|
get "/extra-locales/admin", params: { v: ExtraLocalesController.bundle_js_hash('admin') }
|
|
|
|
expect(response.status).to eq(200)
|
2018-01-09 07:23:49 +08:00
|
|
|
expect(response.headers["Cache-Control"]).to eq("max-age=86400, public, immutable")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not cache at all if version is invalid" do
|
2018-06-06 17:45:29 +08:00
|
|
|
get "/extra-locales/admin", params: { v: 'a' * 32 }
|
|
|
|
expect(response.status).to eq(200)
|
2018-01-09 07:23:49 +08:00
|
|
|
expect(response.headers["Cache-Control"]).not_to eq("max-age=86400, public, immutable")
|
|
|
|
end
|
|
|
|
|
2016-08-26 04:33:29 +08:00
|
|
|
it "needs a valid bundle" do
|
2018-06-06 17:45:29 +08:00
|
|
|
get "/extra-locales/made-up-bundle"
|
|
|
|
expect(response.status).to eq(403)
|
2016-08-26 04:33:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't work with a weird parameter" do
|
2018-06-06 17:45:29 +08:00
|
|
|
get "/extra-locales/-invalid..character!!"
|
|
|
|
expect(response.status).to eq(404)
|
2016-08-26 04:33:29 +08:00
|
|
|
end
|
2016-09-29 04:26:36 +08:00
|
|
|
|
2017-02-24 18:31:21 +08:00
|
|
|
it "includes plugin translations" do
|
|
|
|
I18n.locale = :en
|
|
|
|
I18n.reload!
|
|
|
|
|
|
|
|
JsLocaleHelper.expects(:plugin_translations)
|
2017-07-28 09:20:09 +08:00
|
|
|
.with(I18n.locale.to_s)
|
|
|
|
.returns("admin_js" => {
|
2017-08-31 12:06:56 +08:00
|
|
|
"admin" => {
|
|
|
|
"site_settings" => {
|
|
|
|
"categories" => {
|
|
|
|
"github_badges" => "Github Badges"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).at_least_once
|
|
|
|
|
2018-06-06 17:45:29 +08:00
|
|
|
get "/extra-locales/admin"
|
2016-09-29 04:26:36 +08:00
|
|
|
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2016-09-29 04:26:36 +08:00
|
|
|
expect(response.body.include?("github_badges")).to eq(true)
|
|
|
|
end
|
2016-08-26 04:33:29 +08:00
|
|
|
end
|
|
|
|
end
|