Created
December 22, 2013 23:44
-
-
Save westoque/8089792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When update or set something, a workaround is to manually call:
attr_name_will_change!
.