Skip to content

Commit

Permalink
Fix CI - Update workflow, setup, specs, and more (#998)
Browse files Browse the repository at this point in the history
Context:

In #995, a PR to add support for Rails 7.1, CI was failing.
The thing causing this first failure was issue number 1
below. Each additional fix here was yet another thing
CI failed on.

Things in this commit:

1. Split dummy:db:reset to dummy:db:drop and dummy:set:up
2. Replace outdated use of "MiniTest" with "Minitest"
3. Update session_spec.rb `.serialize_cookies` to handle old and
  new versions of Rack's handling of headers
4. Remove deprecated active record handling in application.rb
5. Update request_with_remember_token.rb `remember_token_cookies`
  handling of headers.

---

1. Setup & Github Workflow - Split dummy:db:reset to
  dummy:db:drop and dummy:set:up

This issue was discovered in #995. 

I'm still looking into why exactly this is happening, but solution has
been consistent for me.

To reproduce the issue for yourself:
When CI runs for each version, it does so using
the specific Gemfile for the version.
Running
`BUNDLE_GEMFILE=gemfiles/rails_7.1.gemfile RAILS_ENV=test
bundle exec rake dummy:db:reset`
and then
`bundle exec appraisal rake`
the Users table will not be found, because it is not created from this
command.

This issue only exists with the 7.1 gemfile that I've found.

Splitting the command dummy:db:reset to its component parts of dummy:db:drop and
dummy:db:setup on separate lines works - for all version. Using them on a
single line does not work, though.

2. Replace outdated use of "MiniTest" with "Minitest"

Use of "MiniTest" (vs modern "Minitest") was removed in version 5.19.0.
CI runs using version 5.20 of Minitest and was failing.

https://my.diffend.io/gems/minitest/5.18.1/5.19.0

3. Update session_spec.rb `.serialize_cookies` to handle old and
new versions of Rack's handling of headers

The way `Rack::Utils.set_cookie_header!` works in rack 3.0.8
is different than previous versions.
Rack downcases keys at the class level now. This update supports both
versions of the method.

rack/rack@95d2f64

Also updating spec/support/cookies.rb and
spec/support/request_with_remember_token.rb for this.

4. Remove deprecated active record handling in application.rb

Rails 6.0 no longer uses `config.activerecord.sqlite3.represent_boolean_as_integer`
as it is always true now.
rails/rails@f59b081

As well, `config.active_record.legacy_connection_handling` has been
deprecated since Rails 7.0 and throws errors if used.

rails/rails#45835

5. Update request_with_remember_token.rb `remember_token_cookies`
handling of headers.

The value might be a string or an array.

Co-authored-by: Samuel Giddins <segiddins@segiddins.me>
  • Loading branch information
sej3506 and segiddins authored Dec 12, 2023
1 parent 8d663ad commit ab34dae
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:
bundler-cache: true

- name: "Reset app database"
run: bundle exec rake dummy:db:reset
run: |
bundle exec rake dummy:db:drop
bundle exec rake dummy:db:setup
- name: "Run tests"
run: bundle exec rake
3 changes: 2 additions & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ if [ -z "$CI" ]; then
fi

# Set up database for the application that Clearance tests against
RAILS_ENV=test bundle exec rake dummy:db:reset
RAILS_ENV=test bundle exec rake dummy:db:drop
RAILS_ENV=test bundle exec rake dummy:db:setup
2 changes: 1 addition & 1 deletion lib/clearance/testing/deny_access_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def redirects_to_url?
@failure_message_when_negated <<
"Didn't expect to redirect to #{@url}."
true
rescue MiniTest::Assertion, ::Test::Unit::AssertionFailedError
rescue Minitest::Assertion, ::Test::Unit::AssertionFailedError
@failure_message << "Expected to redirect to #{@url} but did not."
false
end
Expand Down
3 changes: 2 additions & 1 deletion spec/clearance/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ def serialize_cookies(hash)
Rack::Utils.set_cookie_header! header, key, value
end

header['Set-Cookie']
cookie = header["set-cookie"] || header["Set-Cookie"]
cookie
end

def have_been_called
Expand Down
6 changes: 0 additions & 6 deletions spec/dummy/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class Application < Rails::Application
config.paths["log"] = "tmp/log/development.log"
config.paths.add "config/routes.rb", with: "#{APP_ROOT}/config/routes.rb"

if Rails.version.match?(/^6.0/)
config.active_record.sqlite3.represent_boolean_as_integer = true
else
config.active_record.legacy_connection_handling = false
end

def require_environment!
initialize!
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/cookie_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it { should_have_one_remember_token }

it "should have the httponly flag set" do
expect(remember_token_cookies.last).to match(/HttpOnly/)
expect(remember_token_cookies.last.downcase).to match(/httponly/)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def expectation
end

def extract_cookies
@cookie_headers = @headers['Set-Cookie'] || []
@cookie_headers = @headers["Set-Cookie"] || @headers["set-cookie"] || []
@cookie_headers = [@cookie_headers] if @cookie_headers.respond_to?(:to_str)
end

Expand Down
3 changes: 2 additions & 1 deletion spec/support/request_with_remember_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def request_without_remember_token
end

def remember_token_cookies
cookie_lines = headers["Set-Cookie"].lines.map(&:chomp)
set_cookie_header = headers["Set-Cookie"] || headers["set-cookie"]
cookie_lines = Array(set_cookie_header).join("\n").lines.map(&:chomp)
cookie_lines.select { |name| name =~ /^remember_token/ }
end
end
Expand Down

0 comments on commit ab34dae

Please sign in to comment.