File tree Expand file tree Collapse file tree 6 files changed +21
-1
lines changed
lib/active_record/fixture_set Expand file tree Collapse file tree 6 files changed +21
-1
lines changed Original file line number Diff line number Diff line change
1
+ * Load STI Models in fixtures
2
+
3
+ Data from Fixtures now loads based on the specific class for models with
4
+ Single Table Inheritance. This affects enums defined in subclasses, previously
5
+ the value of these fields was not parsed and remained ` nil `
6
+
7
+ * Andres Howard*
8
+
1
9
* ` #authenticate ` returns false when the password is blank instead of raising an error.
2
10
3
11
* Muhammad Muhammad Ibrahim*
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ def generate_primary_key
126
126
end
127
127
128
128
def resolve_enums
129
- model_class . defined_enums . each do |name , values |
129
+ reflection_class . defined_enums . each do |name , values |
130
130
if @row . include? ( name )
131
131
@row [ name ] = values . fetch ( @row [ name ] , @row [ name ] )
132
132
end
Original file line number Diff line number Diff line change @@ -1331,6 +1331,12 @@ def test_supports_sti_with_respective_files
1331
1331
assert_equal pirates ( :blackbeard ) , dead_parrots ( :deadbird ) . killer
1332
1332
end
1333
1333
1334
+ def test_resolves_enums_in_sti_subclasses
1335
+ assert_predicate parrots ( :george ) , :australian?
1336
+ assert_predicate parrots ( :louis ) , :african?
1337
+ assert_predicate parrots ( :frederick ) , :african?
1338
+ end
1339
+
1334
1340
def test_namespaced_models
1335
1341
assert_includes admin_accounts ( :signals37 ) . users , admin_users ( :david )
1336
1342
assert_equal 2 , admin_accounts ( :signals37 ) . users . size
Original file line number Diff line number Diff line change @@ -8,15 +8,18 @@ george:
8
8
name : " Curious George"
9
9
treasures : diamond, sapphire
10
10
parrot_sti_class : LiveParrot
11
+ breed : australian
11
12
12
13
louis :
13
14
name : " King Louis"
14
15
treasures : [diamond, sapphire]
15
16
parrot_sti_class : LiveParrot
17
+ breed : african
16
18
17
19
frederick :
18
20
name : $LABEL
19
21
parrot_sti_class : LiveParrot
22
+ breed : african
20
23
21
24
polly :
22
25
id : 4
28
31
DEFAULTS : &DEFAULTS
29
32
treasures : sapphire, ruby
30
33
parrot_sti_class : LiveParrot
34
+ breed : australian
31
35
32
36
davey :
33
37
*DEFAULTS
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ def self.delete_all(*)
29
29
end
30
30
31
31
class LiveParrot < Parrot
32
+ enum breed : { african : 0 , australian : 1 }
32
33
end
33
34
34
35
class DeadParrot < Parrot
Original file line number Diff line number Diff line change 734
734
disable_referential_integrity do
735
735
create_table :parrots , force : :cascade do |t |
736
736
t . string :name
737
+ t . integer :breed , default : 0
737
738
t . string :color
738
739
t . string :parrot_sti_class
739
740
t . integer :killer_id
You can’t perform that action at this time.
0 commit comments