From c09a4fd23d7d52552132edde7ad155f366c560b8 Mon Sep 17 00:00:00 2001 From: Tongfei Gao Date: Sat, 18 May 2019 20:58:22 +0800 Subject: Allow specify fixtures to be ignored Allow specifying what fixtures can be ignored by setting `ignore` in fixtures YAML file: # users.yml _fixture: ignore: - base base: &base admin: false introduction: "This is a default description" admin: <<: *base admin: true visitor: <<: *base In the above example, "base" fixture will be ignored when creating users fixture. This is helpful when you want to inherit attributes and it makes your fixtures more "DRY". --- activerecord/lib/active_record/fixture_set/file.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/fixture_set/file.rb') diff --git a/activerecord/lib/active_record/fixture_set/file.rb b/activerecord/lib/active_record/fixture_set/file.rb index f1ea0e022f..b2030a5bb9 100644 --- a/activerecord/lib/active_record/fixture_set/file.rb +++ b/activerecord/lib/active_record/fixture_set/file.rb @@ -29,6 +29,10 @@ module ActiveRecord config_row["model_class"] end + def ignored_fixtures + config_row["ignore"] + end + private def rows @rows ||= raw_rows.reject { |fixture_name, _| fixture_name == "_fixture" } @@ -40,7 +44,7 @@ module ActiveRecord if row row.last else - { 'model_class': nil } + { 'model_class': nil, 'ignore': nil } end end end -- cgit v1.2.3