diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d3145b..9962d32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,3 @@ jobs: - name: Uncached tests run: bin/rails test working-directory: test/dummy - - - name: Cached tests - run: bin/rails test - working-directory: test/dummy diff --git a/lib/oaken/seeds.rb b/lib/oaken/seeds.rb index f934be1..8d82cc8 100644 --- a/lib/oaken/seeds.rb +++ b/lib/oaken/seeds.rb @@ -20,22 +20,47 @@ def self.register(type, key = nil) end def self.provider = Oaken::Stored::ActiveRecord - singleton_class.attr_reader :loader - delegate :entry, to: :loader - - module Loading + class << self + # Set up a general seed rule or perform a one-off seed for a test file. + # + # You can set up a general seed rule in `db/seeds.rb` like this: + # + # Oaken.prepare do + # seed :accounts # Seeds from `db/seeds/accounts/**/*.rb` and `db/seeds//accounts/**/*.rb` + # end + # + # Then if you need a test specific scenario, we recommend putting them in `db/seeds/test/cases`. + # + # Say you have `db/seeds/test/cases/pagination.rb`, you can load it like this: + # + # # test/integration/pagination_test.rb + # class PaginationTest < ActionDispatch::IntegrationTest + # setup { seed "cases/pagination" } + # end def seed(*directories) - Oaken.lookup_paths.each do |path| - directories.each do |directory| - @loader = Oaken::Loader.new Pathname(path).join(directory.to_s) - @loader.load_onto Oaken::Seeds - end + Oaken.lookup_paths.product(directories).each do |path, directory| + load_from Pathname(path).join(directory.to_s) end end + + private def load_from(path) + @loader = Oaken::Loader.new path + @loader.load_onto self + ensure + @loader = nil + end + def entry = @loader.entry end - extend Loading - def self.included(klass) - klass.extend Loading + # Call `seed` in tests to load individual case files: + # + # class PaginationTest < ActionDispatch::IntegrationTest + # setup do + # seed "cases/pagination" # Loads `db/seeds/{,test}/cases/pagination{,**/*}.rb` + # end + # end + def seed(...) + Oaken.store_path.rmtree # TODO: Remove after we yank the store stuff. + Oaken::Seeds.seed(...) end end diff --git a/test/dummy/test/integration/pagination_test.rb b/test/dummy/test/integration/pagination_test.rb index 27c655f..a6aaef5 100644 --- a/test/dummy/test/integration/pagination_test.rb +++ b/test/dummy/test/integration/pagination_test.rb @@ -1,7 +1,7 @@ require "test_helper" class PaginationTest < ActiveSupport::TestCase - seed "cases/pagination" + setup { seed "cases/pagination" } test "pagination sorta" do assert_operator Order.count, :>=, 100