mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 22:33:54 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
58 lines
1.7 KiB
Ruby
58 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Admin::VersionsController do
|
|
fab!(:admin)
|
|
fab!(:moderator)
|
|
fab!(:user)
|
|
|
|
before do
|
|
Jobs::VersionCheck.any_instance.stubs(:execute).returns(true)
|
|
DiscourseUpdates.stubs(:updated_at).returns(2.hours.ago)
|
|
DiscourseUpdates.stubs(:latest_version).returns("1.2.33")
|
|
DiscourseUpdates.stubs(:critical_updates_available?).returns(false)
|
|
end
|
|
|
|
describe "#show" do
|
|
shared_examples "version info accessible" do
|
|
it "should return the currently available version" do
|
|
get "/admin/version_check.json"
|
|
expect(response.status).to eq(200)
|
|
json = response.parsed_body
|
|
expect(json["latest_version"]).to eq("1.2.33")
|
|
end
|
|
|
|
it "should return the installed version" do
|
|
get "/admin/version_check.json"
|
|
json = response.parsed_body
|
|
expect(response.status).to eq(200)
|
|
expect(json["installed_version"]).to eq(Discourse::VERSION::STRING)
|
|
end
|
|
end
|
|
|
|
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
|
|
end
|
|
end
|