Skip to content

Commit ad58923

Browse files
authored
Fix specs on Rails 6 RC2 (#5109)
* 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]
1 parent df43a35 commit ad58923

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

test/orm/active_record.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
ActiveRecord::Base.include_root_in_json = true
66

77
migrate_path = File.expand_path("../../rails_app/db/migrate/", __FILE__)
8-
if Devise::Test.rails52_and_up?
8+
if Devise::Test.rails6?
9+
ActiveRecord::MigrationContext.new(migrate_path, ActiveRecord::SchemaMigration).migrate
10+
elsif Devise::Test.rails52_and_up?
911
ActiveRecord::MigrationContext.new(migrate_path).migrate
1012
else
1113
ActiveRecord::Migrator.migrate(migrate_path)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Welcome to "sessions/new" view!
2-
<%= render file: "devise/sessions/new" %>
2+
<%= render template: "devise/sessions/new" %>

test/rails_app/config/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Application < Rails::Application
4545
Devise::SessionsController.layout "application"
4646
end
4747

48-
# Remove this check once Rails 5.0 support is removed.
49-
if Devise::Test.rails52_and_up?
48+
# Remove the first check once Rails 5.0 support is removed.
49+
if Devise::Test.rails52_and_up? && !Devise::Test.rails6?
5050
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
5151
end
5252
end

test/rails_app/config/boot.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
module Devise
88
module Test
9-
# Detection for minor differences between Rails 4 and 5, 5.1, and 5.2 in tests.
9+
# Detection for minor differences between Rails versions in tests.
1010

11+
def self.rails6?
12+
Rails.version.start_with? '6'
13+
end
14+
1115
def self.rails52_and_up?
1216
Rails::VERSION::MAJOR > 5 || rails52?
1317
end

test/test/controller_helpers_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ def respond
102102

103103
test "returns the content type of a failure app" do
104104
get :index, params: { format: :xml }
105-
assert response.content_type.include?('application/xml')
105+
106+
if Devise::Test.rails6?
107+
assert response.media_type.include?('application/xml')
108+
else
109+
assert response.content_type.include?('application/xml')
110+
end
106111
end
107112

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

0 commit comments

Comments
 (0)