Skip to content

Commit

Permalink
Structure tests a bit better still
Browse files Browse the repository at this point in the history
  • Loading branch information
julik committed Feb 27, 2024
1 parent 3bf20ae commit 9061099
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions test/adapters/adapter_test_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ def test_prune
end

def test_create_tables
# All we are testing for is that the adapter responds to that method and accepts an argument
adapter.create_tables(nil)
raise "This has to either be a no-op in your test (if your adapter doesn't need any tables) or needs to be written"
end

def xtest_should_accept_threadsafe_conditional_fillups
Expand Down
2 changes: 2 additions & 0 deletions test/adapters/memory_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ class MemoryAdapterTest < ActiveSupport::TestCase
def create_adapter
Pecorino::Adapters::MemoryAdapter.new
end

undef :test_create_tables
end
2 changes: 2 additions & 0 deletions test/adapters/redis_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ def delete_created_keys
r = Redis.new
r.del(r.keys(key_prefix + "*"))
end

undef :test_create_tables
end
12 changes: 12 additions & 0 deletions test/adapters/sqlite_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ def test_db_filename
def create_adapter
Pecorino::Adapters::SqliteAdapter.new(ActiveRecord::Base)
end

def test_create_tables
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute("DROP TABLE pecorino_leaky_buckets")
ActiveRecord::Base.connection.execute("DROP TABLE pecorino_blocks")
# The adapter has to be in a variable as the schema definition is scoped to the migrator, not self
retained_adapter = create_adapter # the schema define block is run via instance_exec so it does not retain scope
ActiveRecord::Schema.define(version: 1) do |via_definer|
retained_adapter.create_tables(via_definer)
end
end
end
end

0 comments on commit 9061099

Please sign in to comment.