File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ module ClassMethods
75
75
# store_listing.price_in_cents # => 1000
76
76
def property ( name , cast_type , options = { } )
77
77
name = name . to_s
78
- clear_properties_cache
78
+ clear_caches_calculated_from_columns
79
79
# Assign a new hash to ensure that subclasses do not share a hash
80
80
self . user_provided_columns = user_provided_columns . merge ( name => connection . new_column ( name , options [ :default ] , cast_type ) )
81
81
end
@@ -92,7 +92,7 @@ def columns_hash
92
92
93
93
def reset_column_information # :nodoc:
94
94
super
95
- clear_properties_cache
95
+ clear_caches_calculated_from_columns
96
96
end
97
97
98
98
private
@@ -108,9 +108,13 @@ def add_user_provided_columns(schema_columns)
108
108
existing_columns + new_columns
109
109
end
110
110
111
- def clear_properties_cache
111
+ def clear_caches_calculated_from_columns
112
112
@columns = nil
113
113
@columns_hash = nil
114
+ @column_types = nil
115
+ @column_defaults = nil
116
+ @column_names = nil
117
+ @content_columns = nil
114
118
end
115
119
end
116
120
end
Original file line number Diff line number Diff line change @@ -87,5 +87,25 @@ def test_overloading_properties_does_not_change_column_order
87
87
column_names = OverloadedType . column_names
88
88
assert_equal %w( id overloaded_float unoverloaded_float overloaded_string_with_limit string_with_default non_existent_decimal ) , column_names
89
89
end
90
+
91
+ def test_caches_are_cleared
92
+ klass = Class . new ( OverloadedType )
93
+
94
+ assert_equal 6 , klass . columns . length
95
+ assert_not klass . columns_hash . key? ( 'wibble' )
96
+ assert_equal 6 , klass . column_types . length
97
+ assert_equal 6 , klass . column_defaults . length
98
+ assert_not klass . column_names . include? ( 'wibble' )
99
+ assert_equal 5 , klass . content_columns . length
100
+
101
+ klass . property :wibble , Type ::Value . new
102
+
103
+ assert_equal 7 , klass . columns . length
104
+ assert klass . columns_hash . key? ( 'wibble' )
105
+ assert_equal 7 , klass . column_types . length
106
+ assert_equal 7 , klass . column_defaults . length
107
+ assert klass . column_names . include? ( 'wibble' )
108
+ assert_equal 6 , klass . content_columns . length
109
+ end
90
110
end
91
111
end
You can’t perform that action at this time.
0 commit comments