Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes generation issues in Roda #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexeyMatskevich
Copy link
Contributor

@AlexeyMatskevich AlexeyMatskevich commented Oct 22, 2024

I recently created a new project on rails 8rc1 and installed Rodauth-rails. Rodauth-rails is an authorization framework based on Roda. When trying to generate an openapi spec from a simple test:

require 'rails_helper'

RSpec.describe "Auth::CreateAccounts", type: :request do
  describe "POST /create-account" do
    let(:password) { "Criptograf123!" }
    let(:email) { "[email protected]" }
    let(:params) { { email:, password: } }
    before { post "/create-account", params:, as: :json }

    it "create account" do
      expect(response).to have_http_status(200)
    end

    context "when email invalid" do
      let(:email) { "com" }

      it "NOT create account" do
        expect(response).to have_http_status(422)
      end
    end

    context "when email invalid" do
      let(:password) { "1234" }

      it "NOT create account" do
        expect(response).to have_http_status(422)
      end
    end
  end
end

I got the following problems:

Failure/Error: example.run
     
     RuntimeError:
       No route matched for POST /create-account
     # .../gems_bundle/ruby/3.3.0/gems/rspec-openapi-0.18.3/lib/rspec/openapi/extractors/rails.rb:15:in `request_attributes'
     # .../gems_bundle/ruby/3.3.0/gems/rspec-openapi-0.18.3/lib/rspec/openapi/record_builder.rb:15:in `build'
     # .../gems_bundle/ruby/3.3.0/gems/rspec-openapi-0.18.3/lib/rspec/openapi/rspec_hooks.rb:8:in `block in <main>'
     # ./spec/support/database_cleaner.rb:10:in `block (3 levels) in <main>'
     # .../gems_bundle/ruby/3.3.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/strategy.rb:30:in `cleaning'
     # .../gems_bundle/ruby/3.3.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:34:in `block (2 levels) in cleaning'
     # .../gems_bundle/ruby/3.3.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:35:in `cleaning'
     # ./spec/support/database_cleaner.rb:9:in `block (2 levels) in <main>'

This is an exception from raise "No route matched for #{fixed_request.request_method} #{fixed_request.path_info}" if route.nil? link

I noticed that if you swap line 15 and 17 of the code, everything works fine.

Perhaps additional checks are required for these cases, haven't had time to look into it, I'll get back to it as time permits if no one looks into it sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant