From a80b23f5486d85d13c2cd0b2125198e3a57c9b94 Mon Sep 17 00:00:00 2001 From: Nikita Bulai Date: Mon, 11 Mar 2024 12:13:19 +0300 Subject: [PATCH] Test with Rails 7.1 --- .github/workflows/ci.yml | 3 ++- .../authorizations/form_post.html.erb | 2 +- gemfiles/rails_7_1.gemfile | 22 +++++++++++++++++++ .../application_metal_controller_spec.rb | 4 +++- .../applications_controller_spec.rb | 2 +- .../authorizations_controller_spec.rb | 20 +++++++++-------- .../protected_resources_controller_spec.rb | 2 ++ .../controllers/token_info_controller_spec.rb | 4 +++- spec/controllers/tokens_controller_spec.rb | 4 +++- 9 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 gemfiles/rails_7_1.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7770eb61..109be527c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,6 @@ jobs: matrix: os: [ ubuntu-latest ] ruby: - - 2.7 - '3.0' - '3.1' - '3.2' @@ -30,6 +29,7 @@ jobs: - gemfiles/rails_6_0.gemfile - gemfiles/rails_6_1.gemfile - gemfiles/rails_7_0.gemfile + - gemfiles/rails_7_1.gemfile steps: - name: Repo checkout uses: actions/checkout@v4 @@ -65,6 +65,7 @@ jobs: - gemfiles/rails_6_0.gemfile - gemfiles/rails_6_1.gemfile - gemfiles/rails_7_0.gemfile + - gemfiles/rails_7_1.gemfile runs-on: ubuntu-latest env: BUNDLE_GEMFILE: ${{ matrix.gemfile }} diff --git a/app/views/doorkeeper/authorizations/form_post.html.erb b/app/views/doorkeeper/authorizations/form_post.html.erb index 5e142a8a1..3dfcfadb6 100644 --- a/app/views/doorkeeper/authorizations/form_post.html.erb +++ b/app/views/doorkeeper/authorizations/form_post.html.erb @@ -3,7 +3,7 @@ <%= form_tag @pre_auth.redirect_uri, method: :post, name: :redirect_form, authenticity_token: false do %> - <% @authorize_response.body.compact.each do |key, value| %> + <% @authorize_response&.body&.compact&.each do |key, value| %> <%= hidden_field_tag key, value %> <% end %> <% end %> diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 000000000..22f7f98ba --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 7.1.0" +gem "rspec-core" +gem "rspec-expectations" +gem "rspec-mocks" +gem "rspec-rails", "~> 5.0" +gem "rspec-support" +gem "rubocop", "~> 1.4" +gem "rubocop-performance", require: false +gem "rubocop-rails", require: false +gem "rubocop-rspec", require: false +gem "bcrypt", "~> 3.1", require: false +gem "activerecord-jdbcsqlite3-adapter", platform: :jruby +gem "sprockets-rails" +gem "sqlite3", "~> 1.4", platform: [:ruby, :mswin, :mingw, :x64_mingw] +gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw] +gem "timecop" + +gemspec path: "../" diff --git a/spec/controllers/application_metal_controller_spec.rb b/spec/controllers/application_metal_controller_spec.rb index 81e057597..1e633cdd6 100644 --- a/spec/controllers/application_metal_controller_spec.rb +++ b/spec/controllers/application_metal_controller_spec.rb @@ -2,7 +2,9 @@ require "spec_helper_integration" -RSpec.describe Doorkeeper::ApplicationMetalController do +RSpec.describe Doorkeeper::ApplicationMetalController, type: :controller do + render_views + controller(described_class) do def index render json: {}, status: 200 diff --git a/spec/controllers/applications_controller_spec.rb b/spec/controllers/applications_controller_spec.rb index a24d42870..3d5e58aef 100644 --- a/spec/controllers/applications_controller_spec.rb +++ b/spec/controllers/applications_controller_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Doorkeeper::ApplicationsController do +RSpec.describe Doorkeeper::ApplicationsController, type: :controller do render_views context "when JSON API used" do diff --git a/spec/controllers/authorizations_controller_spec.rb b/spec/controllers/authorizations_controller_spec.rb index 4e32d05c0..f107b0711 100644 --- a/spec/controllers/authorizations_controller_spec.rb +++ b/spec/controllers/authorizations_controller_spec.rb @@ -5,6 +5,8 @@ RSpec.describe Doorkeeper::AuthorizationsController, type: :controller do include AuthorizationRequestHelper + render_views + class ActionDispatch::TestResponse def query_params @query_params ||= begin @@ -39,7 +41,7 @@ def query_params allow(Doorkeeper.config).to receive(:grant_flows).and_return(["implicit"]) allow(Doorkeeper.config).to receive(:authenticate_resource_owner).and_return(->(_) { authenticator_method }) - allow(controller).to receive(:authenticator_method).and_return(user) + allow(subject).to receive(:authenticator_method).and_return(user) end describe "POST #create" do @@ -50,7 +52,7 @@ def query_params it "redirects after authorization" do expect(response).to be_redirect - expect(controller).to receive(:authenticator_method).at_most(:once) + expect(subject).to receive(:authenticator_method).at_most(:once) end it "redirects to client redirect uri" do @@ -756,7 +758,7 @@ def query_params let(:confidential_client) { true } it "redirects immediately" do - expect(controller).not_to receive(:render) + expect(subject).not_to receive(:render) expect(response).to be_redirect expect(response.location).to match(/^#{client.redirect_uri}/) end @@ -771,7 +773,7 @@ def query_params it "renders the new view" do expect(response).to be_successful - expect(controller).to render_with :new + expect(subject).to render_with :new end it "doesn't issue a token" do @@ -1268,13 +1270,13 @@ def query_params describe "authorize response memoization" do it "memoizes the result of the authorization" do pre_auth = double(:pre_auth, authorizable?: true) - allow(controller).to receive(:pre_auth) { pre_auth } + allow(subject).to receive(:pre_auth) { pre_auth } strategy = double(:strategy, authorize: true) expect(strategy).to receive(:authorize).once - allow(controller).to receive(:strategy) { strategy } - allow(controller).to receive(:create) do - 2.times { controller.send :authorize_response } - controller.render json: {}, status: :ok + allow(subject).to receive(:strategy) { strategy } + allow(subject).to receive(:create) do + 2.times { subject.send :authorize_response } + subject.render json: {}, status: :ok end post :create diff --git a/spec/controllers/protected_resources_controller_spec.rb b/spec/controllers/protected_resources_controller_spec.rb index 9784b68d8..07ebebf99 100644 --- a/spec/controllers/protected_resources_controller_spec.rb +++ b/spec/controllers/protected_resources_controller_spec.rb @@ -17,6 +17,8 @@ def doorkeeper_forbidden_render_options(*); end end RSpec.describe "doorkeeper authorize filter" do + render_views + context "when accepts token code specified as" do controller do before_action :doorkeeper_authorize! diff --git a/spec/controllers/token_info_controller_spec.rb b/spec/controllers/token_info_controller_spec.rb index ba5da0792..66c27f172 100644 --- a/spec/controllers/token_info_controller_spec.rb +++ b/spec/controllers/token_info_controller_spec.rb @@ -2,7 +2,9 @@ require "spec_helper" -RSpec.describe Doorkeeper::TokenInfoController do +RSpec.describe Doorkeeper::TokenInfoController, type: :controller do + render_views + describe "when requesting token info with valid token" do let(:doorkeeper_token) { FactoryBot.create(:access_token) } diff --git a/spec/controllers/tokens_controller_spec.rb b/spec/controllers/tokens_controller_spec.rb index e82e0c61b..012c18622 100644 --- a/spec/controllers/tokens_controller_spec.rb +++ b/spec/controllers/tokens_controller_spec.rb @@ -2,7 +2,9 @@ require "spec_helper" -RSpec.describe Doorkeeper::TokensController do +RSpec.describe Doorkeeper::TokensController, type: :controller do + render_views + subject(:json) { JSON.parse(response.body) } let(:client) { FactoryBot.create :application }