Repository: rails/solid_cache (Ruby)

Issue:
Solid Cache breaks assets:precompile in production
Trying to deploy a simple app build with Rails 8.0.2 that uses SolideQueue and SolidCache in separate SQLite databases, I get this error at the `assets:precompile` step (reproducable outside Docker build) :

```shell
❯ RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke environment (first_time)
** Execute environment
bin/rails aborted!
NoMethodError: undefined method 'map' for an instance of String (NoMethodError)

            { shards: databases.map(&:to_sym).index_with { |database| { writing: database } } }
                               ^^^^
Did you mean?  tap
/home/pierre/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/solid_cache-1.0.7/lib/solid_cache/configuration.rb:40:in 'SolidCache::Configuration#set_connects_to'
/home/pierre/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/solid_cache-1.0.7/lib/solid_cache/configuration.rb:14:in 'SolidCache::Configuration#initialize'
```

Don't really know what is relevant to share here so... here is my `database.yml`

```yaml
# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem "sqlite3"
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  primary:
    <<: *default
    database: storage/development.sqlite3
  cache:
    <<: *default
    database: storage/development_cache.sqlite3
    migrations_paths: db/cache_migrate    
  queue:
    <<: *default
    database: storage/development_queue.sqlite3
    migrations_paths: db/queue_migrate
  cable:
    <<: *default
    database: storage/development_cable.sqlite3
    migrations_paths: db/cable_migrate

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  primary:
    <<: *default
    database: storage/test.sqlite3
  cache:
    <<: *default
    database: storage/test_cache.sqlite3
    migrations_paths: db/cache_migrate
  queue:
    <<: *default
    database: storage/test_queue.sqlite3
    migrations_paths: db/queue_migrate
  cable:
    <<: *default
    database: storage/test_cable.sqlite3
    migrations_paths: db/cable_migrate

# Store production database in the storage/ directory, which by default
# is mounted as a persistent Docker volume in config/deploy.yml.
production:
  primary:
    <<: *default
    database: storage/production.sqlite3
  cache:
    <<: *default
    database: storage/production_cache.sqlite3
    migrations_paths: db/cache_migrate
  queue:
    <<: *default
    database: storage/production_queue.sqlite3
    migrations_paths: db/queue_migrate
  cable:
    <<: *default
    database: storage/production_cable.sqlite3
    migrations_paths: db/cable_migrate
```


Discussion:
Got it !

In my `config/cache.yml` there was :

```yaml
production: &production
  databases: cache # [production_cache1, production_cache2]
  store_options:
    <<: *default_store_options
    max_entries: <%= 1.gigabyte %>
```

As `database` contains only one database (`cache`) it should be written without the final `s` !

This makes `assets:precompile` work as expected.

```yaml
production: &production
  database: cache # [production_cache1, production_cache2]
  store_options:
    <<: *default_store_options
    max_entries: <%= 1.gigabyte %>
```

This looks a little weird error to be honnest :)



Patch:
diff --git a/lib/solid_cache/configuration.rb b/lib/solid_cache/configuration.rb
index 17efbaf..597f84a 100644
--- a/lib/solid_cache/configuration.rb
+++ b/lib/solid_cache/configuration.rb
@@ -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


Test patch:
diff --git a/test/unit/configuration_test.rb b/test/unit/configuration_test.rb
new file mode 100644
index 0000000..63e2bb5
--- /dev/null
+++ b/test/unit/configuration_test.rb
@@ -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