Skip to content

Commit

Permalink
Yank SQL file loading (#81)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaspth authored Jun 30, 2024
1 parent 997fe8f commit 5691526
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
13 changes: 4 additions & 9 deletions lib/oaken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/dummy/db/seeds/test/cases/pagination.sql

This file was deleted.

4 changes: 0 additions & 4 deletions test/dummy/test/integration/pagination_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5691526

Please sign in to comment.