Skip to content

Instantly share code, notes, and snippets.

@jeffreygray
Created May 8, 2023 16:00
Show Gist options
  • Save jeffreygray/49b435f2b94b9f22ddf9a186173053ed to your computer and use it in GitHub Desktop.
Save jeffreygray/49b435f2b94b9f22ddf9a186173053ed to your computer and use it in GitHub Desktop.
bypass doorkeeper for rspec testing of controller
# Note: this test shows a context of after we authenticate
require "rails_helper"
RSpec.describe API::V1::Foobar, type: :controller do
let(:api_user) { create :api_user }
before do
allow(controller).to receive(:doorkeeper_token)
.and_return(instance_double("AccessToken", acceptable?: true, resource_owner_id: api_user.id))
end
describe "POST :create" do
context "without all params" do
it "Fails with a HTTP 400" do
post(:create, params: { program_enrollment: { some_attribute: "value" } })
expect(response.code.to_i).to eq(400)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment