Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/solid_cache/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def set_connects_to(database:, databases:, connects_to:)
when database
{ shards: { database.to_sym => { writing: database.to_sym } } }
when databases
{ shards: databases.map(&:to_sym).index_with { |database| { writing: database } } }
{ shards: Array(databases).map(&:to_sym).index_with { |database| { writing: database } } }
when connects_to
connects_to
else
Expand Down
37 changes: 37 additions & 0 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require "test_helper"

class SolidCache::ConfigurationTest < ActiveSupport::TestCase
test "databases option accepts a single database name as a string" do
config = SolidCache::Configuration.new(databases: "cache")
assert_equal({ shards: { cache: { writing: :cache } } }, config.connects_to)
end

test "databases option accepts a single database name as a symbol" do
config = SolidCache::Configuration.new(databases: :cache)
assert_equal({ shards: { cache: { writing: :cache } } }, config.connects_to)
end

test "databases option accepts an array of database names" do
config = SolidCache::Configuration.new(databases: [:cache1, :cache2])
assert_equal({
shards: {
cache1: { writing: :cache1 },
cache2: { writing: :cache2 }
}
}, config.connects_to)
end

test "database option accepts a single database name" do
config = SolidCache::Configuration.new(database: :cache)
assert_equal({ shards: { cache: { writing: :cache } } }, config.connects_to)
end

test "raises ArgumentError when multiple connection options are provided" do
error = assert_raises(ArgumentError) do
SolidCache::Configuration.new(database: :cache, databases: [:cache1])
end
assert_equal "You can only specify one of :database, :databases, or :connects_to", error.message
end
end