Skip to content

Commit

Permalink
Merge pull request #156 from rails/install-config-solid-cache-yml
Browse files Browse the repository at this point in the history
Include config/solid_cache.yml when installing
  • Loading branch information
djmb authored Feb 28, 2024
2 parents 61b565c + 3d138a6 commit 41b8b85
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/generators/solid_cache/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class SolidCache::InstallGenerator < Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

class_option :skip_migrations, type: :boolean, default: nil,
desc: "Skip migrations"

Expand All @@ -12,6 +14,10 @@ def add_rails_cache
end
end

def create_config_solid_cache_yml
template "config/solid_cache.yml"
end

def create_migrations
unless options[:skip_migrations]
rails_command "railties:install:migrations FROM=solid_cache", inline: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
default: &default
database: <%%= Rails.env %>
store_options:
max_age: <%%= 1.week.to_i %>
max_size: <%%= 256.megabytes %>
namespace: <%%= Rails.env %>

development:
<<: *default

test:
<<: *default

production:
<<: *default
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module SolidCache
class SolidCache::InstallGeneratorTest < Rails::Generators::TestCase
tests SolidCache::InstallGenerator

destination File.expand_path("../../../../fixtures/tmp", __dir__)
destination File.expand_path("../../../../../tmp", __dir__)
setup :prepare_destination

setup do
Expand All @@ -18,10 +18,32 @@ class SolidCache::InstallGeneratorTest < Rails::Generators::TestCase

test "generator updates environment config" do
run_generator [ "--skip-migrations" ]
assert_file "#{destination_root}/config/solid_cache.yml", expected_config
assert_file "#{destination_root}/config/environments/development.rb", /config.cache_store = :solid_cache_store\n/
assert_file "#{destination_root}/config/environments/development.rb", /config.cache_store = :null_store\n/
assert_file "#{destination_root}/config/environments/test.rb", /config.cache_store = :null_store\n/
assert_file "#{destination_root}/config/environments/production.rb", /config.cache_store = :solid_cache_store\n/
end

private
def expected_config
<<~YAML
default: &default
database: <%= Rails.env %>
store_options:
max_age: <%= 1.week.to_i %>
max_size: <%= 256.megabytes %>
namespace: <%= Rails.env %>
development:
<<: *default
test:
<<: *default
production:
<<: *default
YAML
end
end
end

0 comments on commit 41b8b85

Please sign in to comment.