2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Admin::VersionsController do
|
2022-11-03 11:42:44 +08:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
before do
|
2013-11-05 01:51:01 +08:00
|
|
|
Jobs::VersionCheck.any_instance.stubs(:execute).returns(true)
|
2013-07-03 23:06:07 +08:00
|
|
|
DiscourseUpdates.stubs(:updated_at).returns(2.hours.ago)
|
2013-02-20 04:16:50 +08:00
|
|
|
DiscourseUpdates.stubs(:latest_version).returns("1.2.33")
|
2013-03-06 23:34:15 +08:00
|
|
|
DiscourseUpdates.stubs(:critical_updates_available?).returns(false)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2022-11-03 11:42:44 +08:00
|
|
|
describe "#show" do
|
|
|
|
shared_examples "version info accessible" do
|
2013-02-20 04:16:50 +08:00
|
|
|
it "should return the currently available version" do
|
2018-06-11 12:35:05 +08:00
|
|
|
get "/admin/version_check.json"
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
json = response.parsed_body
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json["latest_version"]).to eq("1.2.33")
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2013-02-20 04:16:50 +08:00
|
|
|
it "should return the installed version" do
|
2018-06-11 12:35:05 +08:00
|
|
|
get "/admin/version_check.json"
|
2020-05-07 23:04:12 +08:00
|
|
|
json = response.parsed_body
|
2018-06-11 12:35:05 +08:00
|
|
|
expect(response.status).to eq(200)
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json["installed_version"]).to eq(Discourse::VERSION::STRING)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
2022-11-03 11:42:44 +08:00
|
|
|
|
|
|
|
context "when logged in as admin" do
|
|
|
|
before { sign_in(admin) }
|
|
|
|
|
|
|
|
include_examples "version info accessible"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in as a moderator" do
|
|
|
|
before { sign_in(moderator) }
|
|
|
|
|
|
|
|
include_examples "version info accessible"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in as a non-staff user" do
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
|
|
|
it "denies access with a 404 response" do
|
|
|
|
get "/admin/version_check.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
|
|
|
expect(response.parsed_body["latest_version"]).to be_nil
|
|
|
|
expect(response.parsed_body["installed_version"]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-11-06 02:04:47 +08:00
|
|
|
end
|