Skip to content

Commit

Permalink
Fix specs on Rails 6 RC2 (#5109)
Browse files Browse the repository at this point in the history
* Fix specs on Rails 6 RC2

`ActiveRecord::MigrationContext` now has a `schema_migration` attribute.
Ref: https://github.com/rails/rails/pull/36439/files#diff-8d3c44120f7b67ff79e2fbe6a40d0ad6R1018

* Use `media_type` instead of `content_type`

Before Rails 6 RC2, the `ActionDispatch::Response#content_type` method
would return only the media part of the `Content-Type` header, without any
other parts. Now the `#content_type` method returns the entire header -
as it is - and `#media_type` should be used instead to get the previous
behavior.

Ref:
- rails/rails#36034
- rails/rails#36854

* Use render template instead of render file

Render file will need the full path in order to avoid security breaches.
In this particular case, there's no need to use render file, it's ok to
use render template.

Ref: rails/rails#35688

* Don't set `represent_boolean_as_integer` on Rails 6

* Update comments [ci skip]
  • Loading branch information
tegon committed Aug 7, 2019
1 parent df43a35 commit ad58923
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion test/orm/active_record.rb
Expand Up @@ -5,7 +5,9 @@
ActiveRecord::Base.include_root_in_json = true

migrate_path = File.expand_path("../../rails_app/db/migrate/", __FILE__)
if Devise::Test.rails52_and_up?
if Devise::Test.rails6?
ActiveRecord::MigrationContext.new(migrate_path, ActiveRecord::SchemaMigration).migrate
elsif Devise::Test.rails52_and_up?
ActiveRecord::MigrationContext.new(migrate_path).migrate
else
ActiveRecord::Migrator.migrate(migrate_path)
Expand Down
2 changes: 1 addition & 1 deletion test/rails_app/app/views/admins/sessions/new.html.erb
@@ -1,2 +1,2 @@
Welcome to "sessions/new" view!
<%= render file: "devise/sessions/new" %>
<%= render template: "devise/sessions/new" %>
4 changes: 2 additions & 2 deletions test/rails_app/config/application.rb
Expand Up @@ -45,8 +45,8 @@ class Application < Rails::Application
Devise::SessionsController.layout "application"
end

# Remove this check once Rails 5.0 support is removed.
if Devise::Test.rails52_and_up?
# Remove the first check once Rails 5.0 support is removed.
if Devise::Test.rails52_and_up? && !Devise::Test.rails6?
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
end
end
Expand Down
6 changes: 5 additions & 1 deletion test/rails_app/config/boot.rb
Expand Up @@ -6,8 +6,12 @@

module Devise
module Test
# Detection for minor differences between Rails 4 and 5, 5.1, and 5.2 in tests.
# Detection for minor differences between Rails versions in tests.

def self.rails6?
Rails.version.start_with? '6'
end

def self.rails52_and_up?
Rails::VERSION::MAJOR > 5 || rails52?
end
Expand Down
7 changes: 6 additions & 1 deletion test/test/controller_helpers_test.rb
Expand Up @@ -102,7 +102,12 @@ def respond

test "returns the content type of a failure app" do
get :index, params: { format: :xml }
assert response.content_type.include?('application/xml')

if Devise::Test.rails6?
assert response.media_type.include?('application/xml')
else
assert response.content_type.include?('application/xml')
end
end

test "defined Warden after_authentication callback should not be called when sign_in is called" do
Expand Down

0 comments on commit ad58923

Please sign in to comment.