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

Merged
merged 3 commits into from
Feb 6, 2025

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.

@exoego exoego added the bug Something isn't working label Feb 6, 2025
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.09%. Comparing base (7c0476d) to head (de23b55).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #239   +/-   ##
=======================================
  Coverage   97.08%   97.09%           
=======================================
  Files          20       20           
  Lines         618      619    +1     
  Branches      139      140    +1     
=======================================
+ Hits          600      601    +1     
  Misses         18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@exoego exoego merged commit f3a44e7 into exoego:master Feb 6, 2025
13 checks passed
@exoego
Copy link
Owner

exoego commented Feb 6, 2025

Thanks!

@exoego exoego added this to the vnext milestone Feb 6, 2025
@exoego
Copy link
Owner

exoego commented Feb 6, 2025

@AlexeyMatskevich Thanks for the PR. This was released in https://rubygems.org/gems/rspec-openapi/versions/0.18.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants