Files
Christophe Bliard a885fef2bd Conform to RSpecRails/HaveHttpStatus cop
With a hack to get `have_http_status` to work with `Rack::MockResponse`.
2024-06-24 17:50:57 +02:00

51 lines
1.1 KiB
Ruby

require "spec_helper"
RSpec.describe Recaptcha::AdminController do
let(:user) { build_stubbed(:admin) }
before do
login_as user
end
describe "as non admin" do
let(:user) { build_stubbed(:user) }
it "does not allow access" do
get :show
expect(response).to have_http_status :forbidden
post :update
expect(response).to have_http_status :forbidden
end
end
describe "show" do
it "renders show" do
get :show
expect(response).to be_successful
expect(response).to render_template "recaptcha/admin/show"
end
end
describe "#update" do
it "fails if invalid param" do
post :update, params: { recaptcha_type: :unknown }
expect(response).to be_redirect
expect(flash[:error]).to be_present
end
it "succeeds" do
expected = { recaptcha_type: "v2", website_key: "B", secret_key: "A" }
expect(Setting)
.to receive(:plugin_openproject_recaptcha=)
.with(expected)
post :update, params: expected
expect(response).to be_redirect
expect(flash[:error]).to be_nil
expect(flash[:notice]).to be_present
end
end
end