Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created April 10, 2022 22:37
Show Gist options
  • Save maxcal/2d70b9a8ed088bd731404ec26d74851b to your computer and use it in GitHub Desktop.
Save maxcal/2d70b9a8ed088bd731404ec26d74851b to your computer and use it in GitHub Desktop.
Class attributes bug?
require 'active_support/all'
require 'minitest/autorun'
class A
class_attribute :x, default: {}
end
class B < A
end
class C < A
end
C.x[:y] = 1
class ClassAttributesBugTest < Minitest::Test
def test_subclasses_get_own_hash
refute_equal(B.x.object_id, C.x.object_id)
end
def test_modifying_classes
refute_equal(B.x[:y], 1)
end
def test_modifying_classes_effects_parent
refute_equal(A.x[:y], 1)
end
end
@maxcal
Copy link
Author

maxcal commented Apr 10, 2022

All three tests are failing.

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