Skip to content

Instantly share code, notes, and snippets.

@utilum
Created November 30, 2016 23:16
Show Gist options
  • Save utilum/a0a96132f3342e04209d66046996009b to your computer and use it in GitHub Desktop.
Save utilum/a0a96132f3342e04209d66046996009b to your computer and use it in GitHub Desktop.
Rails 4.2 ActiveRecord coerces String values to nil for jsonb fields #27236
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", "4.2.7"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "activerecord_unittest")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :foos, force: true do |t|
t.jsonb :bar
end
end
class Foo < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_association_stuff
foo = Foo.new
foo.bar = "test string"
assert_equal "test string", foo.bar
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment