Skip to content

Instantly share code, notes, and snippets.

@serghost
Created November 30, 2020 14:38
Show Gist options
  • Save serghost/aaf698ec6667916d9055b0239da22e64 to your computer and use it in GitHub Desktop.
Save serghost/aaf698ec6667916d9055b0239da22e64 to your computer and use it in GitHub Desktop.
Rails 6+ postgres bug test script (useful for reproducing issues)
if ARGV.empty?
puts "You can specify the local git repository, i.e. `ruby script.rb ~/work/rails.git`"
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
#gem 'rails', git: '#{ARGV[0] || 'https://github.com/rails/rails.git'}', tag: 'v6.0.3.4'
gem 'rails', git: '#{ARGV[0] || 'https://github.com/rails/rails.git'}', tag: 'v6.1.0.rc1'
gem 'pg'
gem 'pry'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'pry'
require 'active_record'
require 'minitest/autorun'
require 'logger'
`createdb daterange_test_db`
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'daterange_test_db')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :bookings, if_not_exists: true do |t|
t.daterange :daterange
end
end
module Booking
end
class Booking::Base < ActiveRecord::Base
self.table_name = 'bookings'
attribute :daterange, range: true
end
class BugTest < Minitest::Test
def test_daterange_type
booking = Booking::Base.create(daterange: Date.new(2020,12,1)..Date.new(2020,12,12))
assert_equal '[2020-12-01,2020-12-13)', Booking::Base.last.daterange
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment