From 70115d20a36c760e1d5fb41e5e1164b21a33f17d Mon Sep 17 00:00:00 2001 From: Jack Kinsella Date: Fri, 27 Jul 2018 17:06:32 +0200 Subject: [PATCH] Stabilize order of records in YAML files Without this PR, some databases cause generated fixtures to appear in arbitrary order, which creates large diffs upon minor modifications to the fixture structure. --- lib/fixture_builder/builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fixture_builder/builder.rb b/lib/fixture_builder/builder.rb index f7d3741..83e5d9a 100644 --- a/lib/fixture_builder/builder.rb +++ b/lib/fixture_builder/builder.rb @@ -99,7 +99,7 @@ def dump_tables table_klass = table_name.classify.constantize rescue nil if table_klass && table_klass < ActiveRecord::Base rows = table_klass.unscoped do - table_klass.all.collect do |obj| + table_klass.order(:id).all.collect do |obj| attrs = obj.attributes.select { |attr_name| table_klass.column_names.include?(attr_name) } attrs.inject({}) do |hash, (attr_name, value)| hash[attr_name] = serialized_value_if_needed(table_klass, attr_name, value)