Skip to content

Instantly share code, notes, and snippets.

@palkan
Created August 5, 2015 14:36
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 palkan/7599122ed095c7000553 to your computer and use it in GitHub Desktop.
Save palkan/7599122ed095c7000553 to your computer and use it in GitHub Desktop.
Persistance#become bug
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 'arel', github: 'rails/arel'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
end
# Activate the gem you are reporting the issue against.
require 'active_record'
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
t.text :data, default: '{}'
t.string :type
end
end
class User < ActiveRecord::Base
store :data, coder: JSON
validates :name, presence: true
end
class Admin < User
store_accessor :data, :permissions
validates :permissions, presence: true
end
class BugTest < ActiveSupport::TestCase
def test_becomes_errors
user = User.new
assert_not user.valid?
admin = user.becomes(Admin)
admin.name = 'admin'
# This raises NoMethodError: undefined method `permissions' for ...
assert_not admin.valid?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment