Skip to content

Commit

Permalink
Fix loading fixtures for Rails 7
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed May 29, 2023
1 parent 8aa3a87 commit 1caeb71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions spec/finders/activerecord_test_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
require 'date'
require 'yaml'

# forward compatibility with Rails 7 (needed for time expressions within fixtures)
class Time
alias_method :to_fs, :to_s
end unless Time.new.respond_to?(:to_fs)

# monkeypatch needed for Ruby 3.1 & Rails 6.0
YAML.module_eval do
class << self
Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/replies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ witty_retort:
id: 1
topic_id: 1
content: Birdman is better!
created_at: <%= 6.hours.ago.utc.to_s(:db) %>
created_at: <%= 6.hours.ago.utc.to_fs(:db) %>

another:
id: 2
topic_id: 2
content: Nuh uh!
created_at: <%= 1.hour.ago.utc.to_s(:db) %>
created_at: <%= 1.hour.ago.utc.to_fs(:db) %>

spam:
id: 3
topic_id: 1
content: Nice site!
created_at: <%= 1.hour.ago.utc.to_s(:db) %>
created_at: <%= 1.hour.ago.utc.to_fs(:db) %>

decisive:
id: 4
topic_id: 4
content: "I'm getting to the bottom of this"
created_at: <%= 30.minutes.ago.utc.to_s(:db) %>
created_at: <%= 30.minutes.ago.utc.to_fs(:db) %>

brave:
id: 5
topic_id: 4
content: "AR doesn't scare me a bit"
created_at: <%= 10.minutes.ago.utc.to_s(:db) %>
created_at: <%= 10.minutes.ago.utc.to_fs(:db) %>
8 changes: 4 additions & 4 deletions spec/fixtures/topics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ futurama:
title: Isnt futurama awesome?
subtitle: It really is, isnt it.
content: I like futurama
created_at: <%= 1.day.ago.utc.to_s(:db) %>
created_at: <%= 1.day.ago.utc.to_fs(:db) %>
updated_at:

harvey_birdman:
id: 2
title: Harvey Birdman is the king of all men
subtitle: yup
content: He really is
created_at: <%= 2.hours.ago.utc.to_s(:db) %>
created_at: <%= 2.hours.ago.utc.to_fs(:db) %>
updated_at:

rails:
Expand All @@ -20,11 +20,11 @@ rails:
title: Rails is nice
subtitle: It makes me happy
content: except when I have to hack internals to fix pagination. even then really.
created_at: <%= 20.minutes.ago.utc.to_s(:db) %>
created_at: <%= 20.minutes.ago.utc.to_fs(:db) %>

ar:
id: 4
project_id: 1
title: ActiveRecord sometimes freaks me out
content: "I mean, what's the deal with eager loading?"
created_at: <%= 15.minutes.ago.utc.to_s(:db) %>
created_at: <%= 15.minutes.ago.utc.to_fs(:db) %>

0 comments on commit 1caeb71

Please sign in to comment.