From 2cd0460960f350d4bcb50505c12bd54a6ad29cb4 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sat, 29 Jun 2024 18:41:23 +0200 Subject: [PATCH] Yank SQL file loading If you need to test something like Marshal parsing between different Ruby/Rails versions, it's pretty easy to insert your SQL dump directly into your test case, like so: ```ruby setup do ActiveRecord::Base.connection.execute <<~SQL INSERT INTO users (name, email_address, created_at, updated_at) VALUES ('pagination.sql', 'pagination@example.com', TIME('NOW'), TIME('NOW')) SQL end ``` If the SQL is too long, users can use `file_fixture("sqls/pagination.sql").read` or similar to set it up. I don't think Oaken needs to ship a more complex wrapper around this. --- lib/oaken.rb | 13 ++++--------- test/dummy/db/seeds/test/cases/pagination.sql | 1 - test/dummy/test/integration/pagination_test.rb | 4 ---- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 test/dummy/db/seeds/test/cases/pagination.sql diff --git a/lib/oaken.rb b/lib/oaken.rb index 35fd1d0..70e255b 100644 --- a/lib/oaken.rb +++ b/lib/oaken.rb @@ -18,17 +18,12 @@ module Stored class Loader def initialize(path) - @entries = Pathname.glob("#{path}{,/**/*}.{rb,sql}").sort + @entries = Pathname.glob("#{path}{,/**/*}.rb").sort end - def load_onto(seeds) - @entries.each do |path| - ActiveRecord::Base.transaction do - case path.extname - when ".rb" then seeds.class_eval path.read, path.to_s - when ".sql" then ActiveRecord::Base.connection.execute path.read - end - end + def load_onto(seeds) = @entries.each do |path| + ActiveRecord::Base.transaction do + seeds.class_eval path.read, path.to_s end end end diff --git a/test/dummy/db/seeds/test/cases/pagination.sql b/test/dummy/db/seeds/test/cases/pagination.sql deleted file mode 100644 index c487636..0000000 --- a/test/dummy/db/seeds/test/cases/pagination.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO users (name, email_address, created_at, updated_at) VALUES ('pagination.sql', 'pagination@example.com', TIME('NOW'), TIME('NOW')) diff --git a/test/dummy/test/integration/pagination_test.rb b/test/dummy/test/integration/pagination_test.rb index a6aaef5..502174a 100644 --- a/test/dummy/test/integration/pagination_test.rb +++ b/test/dummy/test/integration/pagination_test.rb @@ -6,8 +6,4 @@ class PaginationTest < ActiveSupport::TestCase test "pagination sorta" do assert_operator Order.count, :>=, 100 end - - test "pagination loading from sql case" do - assert User.find_by(name: "pagination.sql") - end end