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

Fix compatibility with Rack 2.x on Rails 7.0+, reinstating Rails appraisal tests #271

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

chadlwilson
Copy link
Contributor

@chadlwilson chadlwilson commented Jan 22, 2025

This PR makes a few important changes.

  • Requires Rack 2.x (as bundled), removing old Rack 1.x compatibility code which is very confusing to support (and likely doesn't work)
    • this makes no practical difference for rails since rack 2.0 is required from rails 5 anyway.
    • seems fine to me more widely given rack 1.6 was EOL 5 years ago.
  • fixes Session store @env is nil with Rails 7 #244 - using a Java servlet session store under Rails 7.0 was broken
  • Makes a few minor test fixes to the Rails "appraisal" tests to allow them to run with modern JRuby and modern Rails
    • Works around an issue with concurrent-ruby and Rails < 7.1 for tests
    • Corrects visibility on some mock methods
    • Adds workaround for frozen string literal issues with NameError handling on older JRuby/Rails versions.
  • Adds the appraisals to GitHub Actions as a second job, including Rails 5.0 -> 7.2 for now.
  • Updates README and History.md to reflect 1.2.x releases (assumes this will be in 1.2.3)

Commits should be logically chunked so can be reviewed independently if necessary.

This isn't as scary to review as it looks - almost all of the change chunk #s are from removing and adding appraisal Gemfile.locks 😛

Rack 2.x wraps the @env within @Req so previous overrides were not working correctly in all cases.
Only affects appraisals/rails tests right now it seems where the MockHttpSession is used.
@chadlwilson
Copy link
Contributor Author

Would appreciate review/input from @kares and @headius when you folks have time :-)

Comment on lines +1 to 11
appraise "rails50" do
gem "rails", "~> 5.0.0"
end

appraise "rails40" do
gem "rails", "~> 4.0.13"
appraise "rails52" do
gem "rails", "~> 5.2.0"
end

appraise "rails41" do
gem "rails", "~> 4.1.16"
appraise "rails60" do
gem "rails", "~> 6.0.0"
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider dropping tests for Rails 5.0 (EOL Apr 2018), 5.2 (EOL Jun 2022) and/or 6.0 (EOL Jun 2023) as well. I kept all versions that worked with JRuby 9.3+.

One reason to be a bit more relaxed with EOLs for JRuby stuff is some of the lag for JRuby itself to catch up with required Ruby versions. Dropping 5.0 is probably pretty reasonable now though.

Comment on lines -162 to -164
def current_session_id(env)
env[ENV_SESSION_OPTIONS_KEY][:id] # 1.5.0: env[ENV_SESSION_KEY].id
end if ::JRuby::Rack::Session::OptionsHash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptionsHash is gone from Rack 1.5+ so no longer needed.

@@ -101,7 +101,7 @@ public String getId() {
return this.id;
}

void setId(String id) {
public void setId(String id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not visible on modern JRuby otherwise.

@@ -256,7 +256,7 @@ public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode()) + this.attributes;
}

Map<String, Object> getAttributes() {
public Map<String, Object> getAttributes() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not visible on modern JRuby otherwise.

Comment on lines -35 to -38
it "should raise an error if the servlet request is not present" do
expect { @session_store.call({}) }.to raise_error(RuntimeError)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was too problematic to get to work reliably across all versions, and seemed to be relying on a lot of other code to get to the expected result from the entry point. Seems to be trying to get into the code below when there is no existing session. I made a call that I didn't think it was sufficiently important after trying to fix it and getting lost as to why it wasn't always raising an error.

def get_servlet_session(env, create = false)
servlet_session = env[ENV_SERVLET_SESSION_KEY]
invalid = false
begin
if servlet_session.nil? ||
( create && ( invalid || servlet_session.getCreationTime.nil? ) )
unless servlet_request = env['java.servlet_request']
raise "JavaServletStore expects a servlet request at env['java.servlet_request']"
end

@chadlwilson chadlwilson force-pushed the appraisals-tests branch 3 times, most recently from 277cbb4 to 3eeb902 Compare January 23, 2025 03:44
…fore railtie

Not sure if this is us, strictly speaking but we seem to need to require active_support before the railties or the issue at rails/rails#49495 (comment) occurs
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.

Session store @env is nil with Rails 7 [to-do] towards **1.2**
2 participants