Merge pull request #1274 from paper-trail-gem/dummy_app_load_defaults

Tests: Various updates to `dummy_app`, in preparation for rails 6.1
This commit is contained in:
Jared Beck 2020-12-15 11:44:40 -05:00 committed by GitHub
commit 68522182af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 36 deletions

View File

@ -8,13 +8,14 @@
# > appraisal. If something is specified in both the Gemfile and an appraisal,
# > the version from the appraisal takes precedence.
# > https://github.com/thoughtbot/appraisal
#
#
appraise "ar-5.2" do
gem "activerecord", "~> 5.2.4"
gem "rails", "~> 5.2.4"
gem "rails-controller-testing", "~> 1.0.2"
end
appraise "ar-6.0" do
gem "activerecord", "~> 6.0.3"
gem "rails", "~> 6.0.3"
gem "rails-controller-testing", "~> 1.0.3"
end

View File

@ -2,7 +2,7 @@
source "https://rubygems.org"
gem "activerecord", "~> 5.2.4"
gem "rails", "~> 5.2.4"
gem "rails-controller-testing", "~> 1.0.2"
gemspec path: "../"

View File

@ -2,7 +2,7 @@
source "https://rubygems.org"
gem "activerecord", "~> 6.0.3"
gem "rails", "~> 6.0.3"
gem "rails-controller-testing", "~> 1.0.3"
gemspec path: "../"

View File

@ -31,7 +31,7 @@ has been destroyed.
# https://www.ruby-lang.org/en/news/2019/10/02/ruby-2-4-9-released/
s.required_ruby_version = ">= 2.4.0"
# We no longer specify a maximum rails version.
# We no longer specify a maximum activerecord version.
# See discussion in paper_trail/compatibility.rb
s.add_dependency "activerecord", ::PaperTrail::Compatibility::ACTIVERECORD_GTE
s.add_dependency "request_store", "~> 1.1"
@ -41,6 +41,12 @@ has been destroyed.
s.add_development_dependency "ffaker", "~> 2.11"
s.add_development_dependency "generator_spec", "~> 0.9.4"
s.add_development_dependency "memory_profiler", "~> 0.9.14"
# For `spec/dummy_app`. Technically, we only need `actionpack` (as of 2020).
# However, that might change in the future, and the advantages of specifying a
# subset (e.g. actionpack only) are unclear.
s.add_development_dependency "rails", ::PaperTrail::Compatibility::ACTIVERECORD_GTE
s.add_development_dependency "rake", "~> 13.0"
s.add_development_dependency "rspec-rails", "~> 4.0"
s.add_development_dependency "rubocop", "~> 0.89.1"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
module Family
class CelebrityFamily < Family::Family
class CelebrityFamily < ::Family::Family
end
end

View File

@ -11,38 +11,14 @@ require "paper_trail"
module Dummy
class Application < Rails::Application
config.load_defaults(::Rails.gem_version.segments.take(2).join("."))
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_support.test_order = :sorted
# Disable assets in rails 4.2. In rails 5, config does not respond to
# assets, probably because it was moved out of railties to some other gem,
# and we only have dev. dependencies on railties, not all of rails. When
# we drop support for rails 4.2, we can remove this whole conditional.
if config.respond_to?(:assets)
config.assets.enabled = false
end
config.secret_key_base = "A fox regularly kicked the screaming pile of biscuits."
# `raise_in_transactional_callbacks` was added in rails 4, then deprecated
# in rails 5. Oh, how fickle are the gods.
if ActiveRecord.respond_to?(:gem_version)
v = ActiveRecord.gem_version
if v >= Gem::Version.new("4.2") && v < Gem::Version.new("5.0.0.beta1")
config.active_record.raise_in_transactional_callbacks = true
end
if v >= Gem::Version.new("5.0.0.beta1") && v < Gem::Version.new("5.1")
config.active_record.belongs_to_required_by_default = true
config.active_record.time_zone_aware_types = [:datetime]
end
if v >= Gem::Version.new("5.1")
config.load_defaults "5.1"
config.active_record.time_zone_aware_types = [:datetime]
end
end
# In rails >= 6.0, "`.represent_boolean_as_integer=` is now always true,
# so setting this is deprecated and will be removed in Rails 6.1."
if ::ENV["DB"] == "sqlite" &&

View File

@ -335,8 +335,9 @@ RSpec.describe(::PaperTrail, versioning: true) do
expect(previous_widget.a_datetime.to_time.utc.to_i).to(eq(t0.to_time.utc.to_i))
end
it "handle times" do
expect(previous_widget.a_time.utc.to_i).to(eq(t0.utc.to_i))
it "handle times (time only, no date)" do
format = ->(t) { t.utc.strftime "%H:%M:%S" }
expect(format[previous_widget.a_time]).to eq(format[t0])
end
it "handle dates" do
@ -362,7 +363,8 @@ RSpec.describe(::PaperTrail, versioning: true) do
assert_in_delta(153.01, reified.a_float, 0.001)
assert_in_delta(2.7183, reified.a_decimal, 0.0001)
expect(reified.a_datetime.to_time.utc.to_i).to(eq(t0.to_time.utc.to_i))
expect(reified.a_time.utc.to_i).to(eq(t0.utc.to_i))
format = ->(t) { t.utc.strftime "%H:%M:%S" }
expect(format[reified.a_time]).to eq(format[t0])
expect(reified.a_date).to(eq(d0))
expect(reified.a_boolean).to(be_truthy)
end