From 1a83a7ee5c9099b902a93bd0c4de29eeb2d40e16 Mon Sep 17 00:00:00 2001 From: luciano Date: Mon, 28 Oct 2024 10:53:48 -0300 Subject: [PATCH] Fix for single column tables --- lib/evil_seed/relation_dumper.rb | 1 + test/db/models.rb | 3 +++ test/db/schema.rb | 2 ++ test/db/seeds.rb | 5 +++++ test/evil_seed_test.rb | 1 + 5 files changed, 12 insertions(+) diff --git a/lib/evil_seed/relation_dumper.rb b/lib/evil_seed/relation_dumper.rb index 07443c4..fb61cc9 100644 --- a/lib/evil_seed/relation_dumper.rb +++ b/lib/evil_seed/relation_dumper.rb @@ -148,6 +148,7 @@ def dump_has_many_associations! # @return [Array String, Integer, Float, Boolean, nil}>] def fetch_attributes(relation) relation.pluck(*model_class.column_names).map do |row| + row = [row] if model_class.column_names.size == 1 Hash[model_class.column_names.zip(row)] end end diff --git a/test/db/models.rb b/test/db/models.rb index a71ffc6..768ff4d 100644 --- a/test/db/models.rb +++ b/test/db/models.rb @@ -61,3 +61,6 @@ class Vote < ActiveRecord::Base belongs_to :votable, polymorphic: true belongs_to :user end + +class Version < ActiveRecord::Base +end \ No newline at end of file diff --git a/test/db/schema.rb b/test/db/schema.rb index 308bc29..efd1a56 100644 --- a/test/db/schema.rb +++ b/test/db/schema.rb @@ -64,5 +64,7 @@ def create_schema! t.references :role, foreign_key: { on_delete: :cascade } t.index %i[user_id role_id], unique: true end + + create_table :versions end end diff --git a/test/db/seeds.rb b/test/db/seeds.rb index 25b8a64..c98f09f 100644 --- a/test/db/seeds.rb +++ b/test/db/seeds.rb @@ -59,3 +59,8 @@ { user: users[1], name: "Profile for user 1", title: "Title for user 1" }, { user: users[2], name: "Profile for user 2", title: "Title for user 2" }, ]) + +Version.create!([ + { id: 1}, + { id: 2}, +]) \ No newline at end of file diff --git a/test/evil_seed_test.rb b/test/evil_seed_test.rb index 3db523e..5ec8faa 100644 --- a/test/evil_seed_test.rb +++ b/test/evil_seed_test.rb @@ -17,6 +17,7 @@ def setup config.root('Role') do |root| root.exclude(/\Arole\.(?!roles_users\z)/) # Take only join table and nothing more end + config.root('Version') config.ignore_columns("Profile", :name) end