Skip to content

Instantly share code, notes, and snippets.

@westoque
Created December 22, 2013 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westoque/8089792 to your computer and use it in GitHub Desktop.
Save westoque/8089792 to your computer and use it in GitHub Desktop.
# Activate the gem you are reporting the issue against.
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'pg'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
USERNAME = ENV["USERNAME"]
PASSWORD = ENV["PASSWORD"]
DB = ENV["DB"]
ActiveRecord::Base.establish_connection("postgres://#{USERNAME}:#{PASSWORD}@localhost/#{DB}")
ActiveRecord::Base.logger = Logger.new(STDOUT)
unless ActiveRecord::Base.connection.table_exists? "products"
ActiveRecord::Schema.define do
create_table :products do |t|
t.json :data
end
end
end
class Product < ActiveRecord::Base
end
class BugTest < MiniTest::Unit::TestCase
def test_updating_json_column
Product.create!(:data => { :size => "Small" })
product = Product.last
product.data[:size] = "Large"
assert product.changed?, 'failed to detect json column change'
end
end
@JuanitoFatas
Copy link

When update or set something, a workaround is to manually call: attr_name_will_change!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment