discourse/spec/requests/admin/versions_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe Admin::VersionsController do
fab!(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:user) }
2013-02-05 14:16:51 -05:00
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)
2013-02-05 14:16:51 -05:00
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
2015-01-09 12:04:02 -05:00
expect(json["latest_version"]).to eq("1.2.33")
2013-02-05 14:16:51 -05:00
end
it "should return the installed version" do
get "/admin/version_check.json"
json = response.parsed_body
expect(response.status).to eq(200)
2015-01-09 12:04:02 -05:00
expect(json["installed_version"]).to eq(Discourse::VERSION::STRING)
2013-02-05 14:16:51 -05:00
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
2013-02-05 14:16:51 -05:00
end
2013-11-05 13:04:47 -05:00
end