Skip to content

Commit

Permalink
Drop Rails 5.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Dec 4, 2024
1 parent d032d12 commit 4853c7d
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 114 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,22 @@ jobs:
fail-fast: false
matrix:
ruby: ["ruby-2.6", "ruby-2.7", "ruby-3.0", "ruby-3.1", "ruby-3.2", "ruby-3.3", "jruby-9.4"]
gemfile: ["rails-5.0", "rails-5.1", "rails-5.2", "rails-6.0", "rails-6.1", "rails-7.0", "rails-7.1", "rails-7.2", "rails-8.0"]
gemfile: ["rails-5.1", "rails-5.2", "rails-6.0", "rails-6.1", "rails-7.0", "rails-7.1", "rails-7.2", "rails-8.0"]
exclude:
- ruby: "ruby-3.3"
gemfile: "rails-5.2"
- ruby: "ruby-3.3"
gemfile: "rails-5.1"
- ruby: "ruby-3.3"
gemfile: "rails-5.0"
- ruby: "ruby-3.2"
gemfile: "rails-5.2"
- ruby: "ruby-3.2"
gemfile: "rails-5.1"
- ruby: "ruby-3.2"
gemfile: "rails-5.0"
- ruby: "ruby-3.1"
gemfile: "rails-8.0"
- ruby: "ruby-3.1"
gemfile: "rails-5.2"
- ruby: "ruby-3.1"
gemfile: "rails-5.1"
- ruby: "ruby-3.1"
gemfile: "rails-5.0"
- ruby: "ruby-3.0"
gemfile: "rails-8.0"
- ruby: "ruby-3.0"
Expand All @@ -46,8 +40,6 @@ jobs:
gemfile: "rails-5.2"
- ruby: "ruby-3.0"
gemfile: "rails-5.1"
- ruby: "ruby-3.0"
gemfile: "rails-5.0"
- ruby: "ruby-2.7"
gemfile: "rails-8.0"
- ruby: "ruby-2.7"
Expand All @@ -62,8 +54,6 @@ jobs:
gemfile: "rails-5.2"
- ruby: "jruby-9.4"
gemfile: "rails-5.1"
- ruby: "jruby-9.4"
gemfile: "rails-5.0"
- ruby: "ruby-2.6"
gemfile: "rails-8.0"
- ruby: "ruby-2.6"
Expand Down
16 changes: 0 additions & 16 deletions gemfiles/Gemfile.rails-5.0

This file was deleted.

6 changes: 1 addition & 5 deletions lib/generators/rodauth/migration_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ def primary_key_type(key = :id)
end

def default_primary_key_type
if ActiveRecord.version >= Gem::Version.new("5.1") && activerecord_adapter != "sqlite3"
:bigint
else
:integer
end
activerecord_adapter == "sqlite3" ? :integer : :bigint
end

# Active Record 7+ sets default precision to 6 for timestamp columns,
Expand Down
11 changes: 0 additions & 11 deletions lib/generators/rodauth/views_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def create_views
copy_file view_location(view), "app/views/#{directory}/#{view}.html.erb" do |content|
content = content.gsub("rodauth.", "rodauth(:#{configuration_name}).") if configuration_name
content = content.gsub("rodauth/", "#{directory}/")
content = form_helpers_compatibility(content) if ActionView.version < Gem::Version.new("5.1")
content
end
end
Expand Down Expand Up @@ -103,16 +102,6 @@ def configuration_name
options[:name]&.to_sym
end

# We need to use the *_tag helpers on versions lower than Rails 5.1.
def form_helpers_compatibility(content)
content
.gsub(/form_with url: (.+) do \|form\|/, 'form_tag \1 do')
.gsub(/form\.(label|submit)/, '\1_tag')
.gsub(/form\.(email|password|text|telephone|hidden)_field (\S+), value:/, '\1_field_tag \2,')
.gsub(/form\.radio_button (\S+), (\S+),/, 'radio_button_tag \1, \2, false,')
.gsub(/form\.check_box (\S+), (.+) /, 'check_box_tag \1, "t", false, \2 ')
end

def view_location(view)
if tailwind?
"app/views/rodauth/tailwind/#{view}.html.erb"
Expand Down
66 changes: 1 addition & 65 deletions test/generators/views_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
</div>
<% end %>
ERB
end if ActionView.version >= Gem::Version.new("5.1")
end

test "interpolating directory name" do
run_generator %w[recovery_codes]
Expand All @@ -100,70 +100,6 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
<%= render template: "admin/rodauth/recovery_codes", layout: false %>
<% end %>
ERB
end if ActionView.version >= Gem::Version.new("5.1")

if ActionView.version < Gem::Version.new("5.1")
test "form helpers compatibility" do
run_generator %w[close_account remember logout]

assert_file "app/views/rodauth/close_account.html.erb", <<~ERB
<%= form_tag rodauth.close_account_path, method: :post, data: { turbo: false } do %>
<% if rodauth.close_account_requires_password? %>
<div class="form-group mb-3">
<%= label_tag "password", rodauth.password_label, class: "form-label" %>
<%= password_field_tag rodauth.password_param, "", id: "password", autocomplete: rodauth.password_field_autocomplete_value, required: true, class: "form-control \#{"is-invalid" if rodauth.field_error(rodauth.password_param)}", aria: ({ invalid: true, describedby: "password_error_message" } if rodauth.field_error(rodauth.password_param)) %>
<%= content_tag(:span, rodauth.field_error(rodauth.password_param), class: "invalid-feedback", id: "password_error_message") if rodauth.field_error(rodauth.password_param) %>
</div>
<% end %>
<div class="form-group mb-3">
<%= submit_tag rodauth.close_account_button, class: "btn btn-danger" %>
</div>
<% end %>
ERB

assert_file "app/views/rodauth/remember.html.erb", <<~ERB
<%= form_tag rodauth.remember_path, method: :post, data: { turbo: false } do %>
<fieldset class="form-group mb-3">
<div class="form-check">
<%= radio_button_tag rodauth.remember_param, rodauth.remember_remember_param_value, false, id: "remember-remember", class: "form-check-input" %>
<%= label_tag "remember-remember", rodauth.remember_remember_label, class: "form-check-label" %>
</div>
<div class="form-check">
<%= radio_button_tag rodauth.remember_param, rodauth.remember_forget_param_value, false, id: "remember-forget", class: "form-check-input" %>
<%= label_tag "remember-forget", rodauth.remember_forget_label, class: "form-check-label" %>
</div>
<div class="form-check">
<%= radio_button_tag rodauth.remember_param, rodauth.remember_disable_param_value, false, id: "remember-disable", class: "form-check-input" %>
<%= label_tag "remember-disable", rodauth.remember_disable_label, class: "form-check-label" %>
</div>
</fieldset>
<div class="form-group mb-3">
<%= submit_tag rodauth.remember_button, class: "btn btn-primary" %>
</div>
<% end %>
ERB

assert_file "app/views/rodauth/logout.html.erb", <<~ERB
<%= form_tag rodauth.logout_path, method: :post, data: { turbo: false } do %>
<% if rodauth.features.include?(:active_sessions) %>
<div class="form-group mb-3">
<div class="form-check">
<%= check_box_tag rodauth.global_logout_param, "t", false, id: "global-logout", class: "form-check-input", include_hidden: false %>
<%= label_tag "global-logout", rodauth.global_logout_label, class: "form-check-label" %>
</div>
</div>
<% end %>
<div class="form-group mb-3">
<%= submit_tag rodauth.logout_button, class: "btn btn-warning" %>
</div>
<% end %>
ERB
end
end

test "specifying configuration with no controller" do
Expand Down
2 changes: 1 addition & 1 deletion test/integration/headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ class HeadersTest < IntegrationTest

assert_match "Authenticated as user@example.com", page.text
assert_match "_remember", Array(page.response_headers["Set-Cookie"]).join(";") # remember deadline extended
end if Gem::Version.new(Rack::Test::VERSION) >= Gem::Version.new("1.0")
end
end
2 changes: 1 addition & 1 deletion test/rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Application < Rails::Application
config.secret_key_base = "a8457c8003e83577e92708bd56e19bdc4442c689f458f483a30e580611c578a3"
config.logger = Logger.new(nil)
config.eager_load = true
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}" if Rails.gem_version >= Gem::Version.new("5.1")
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
config.action_dispatch.show_exceptions = Rails.gem_version >= Gem::Version.new("7.1") ? :none : false
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { host: "example.com", protocol: "https" }
Expand Down
4 changes: 2 additions & 2 deletions test/rodauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class RodauthTest < UnitTest
test "retrieves secret_key_base from env variable, credentials, or secrets" do
Rails.env = "production"

if Rails.gem_version < Gem::Version.new("7.1.0")
if Rails.gem_version < Gem::Version.new("7.1")
Rails.application.secrets.secret_key_base = "secret"
assert_equal "secret", Rodauth::Rails.secret_key_base
end

if Rails.gem_version >= Gem::Version.new("5.2.0")
if Rails.gem_version >= Gem::Version.new("5.2")
Rails.application.credentials.secret_key_base = "credential"
reset_secret_key_base do
assert_equal "credential", Rodauth::Rails.secret_key_base
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module TestSetupTeardown
def setup
super
if ActiveRecord.version >= Gem::Version.new("7.2.0.alpha")
if ActiveRecord.version >= Gem::Version.new("7.2")
ActiveRecord::Base.connection_pool.migration_context.up
elsif ActiveRecord.version >= Gem::Version.new("5.2")
ActiveRecord::Base.connection.migration_context.up
Expand All @@ -29,7 +29,7 @@ def setup

def teardown
super
if ActiveRecord.version >= Gem::Version.new("7.2.0.alpha")
if ActiveRecord.version >= Gem::Version.new("7.2")
ActiveRecord::Base.connection_pool.migration_context.up
elsif ActiveRecord.version >= Gem::Version.new("5.2")
ActiveRecord::Base.connection.migration_context.down
Expand Down

0 comments on commit 4853c7d

Please sign in to comment.