File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
lib/active_record/fixture_set Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change
1
+ * Fixture configurations (` _fixture ` ) are now strictly validated.
2
+
3
+ If an error will be raised if that entry contains unknown keys while previously it
4
+ would silently have no effects.
5
+
6
+ * Jean Boussier*
7
+
1
8
* Add ` ActiveRecord::Base.update! ` that works like ` ActiveRecord::Base.update ` but raises exceptions.
2
9
3
10
This allows for the same behavior as the instance method ` #update! ` at a class level.
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def config_row
41
41
@config_row ||= begin
42
42
row = raw_rows . find { |fixture_name , _ | fixture_name == "_fixture" }
43
43
if row
44
- row . last
44
+ validate_config_row ( row . last )
45
45
else
46
46
{ 'model_class' : nil , 'ignore' : nil }
47
47
end
@@ -58,6 +58,20 @@ def raw_rows
58
58
end
59
59
end
60
60
61
+ def validate_config_row ( data )
62
+ unless Hash === data
63
+ raise Fixture ::FormatError , "Invalid `_fixture` section: `_fixture` must be a hash: #{ @file } "
64
+ end
65
+
66
+ begin
67
+ data . assert_valid_keys ( "model_class" , "ignore" )
68
+ rescue ArgumentError => error
69
+ raise Fixture ::FormatError , "Invalid `_fixture` section: #{ error . message } : #{ @file } "
70
+ end
71
+
72
+ data
73
+ end
74
+
61
75
# Validate our unmarshalled data.
62
76
def validate ( data )
63
77
unless Hash === data || YAML ::Omap === data
Original file line number Diff line number Diff line change @@ -70,6 +70,15 @@ def test_wrong_fixture_format_nested
70
70
end
71
71
end
72
72
73
+ def test_wrong_config_row
74
+ tmp_yaml [ "empty" , "yml" ] , { "_fixture" => { "class_name" => "Foo" } } . to_yaml do |t |
75
+ error = assert_raises ( ActiveRecord ::Fixture ::FormatError ) do
76
+ File . open ( t . path ) { |fh | fh . model_class }
77
+ end
78
+ assert_includes error . message , "Invalid `_fixture` section"
79
+ end
80
+ end
81
+
73
82
def test_render_context_helper
74
83
ActiveRecord ::FixtureSet . context_class . class_eval do
75
84
def fixture_helper
You can’t perform that action at this time.
0 commit comments