From d4d987960c7a2c1f4ad1f8235fd8a0e93ae80df7 Mon Sep 17 00:00:00 2001 From: "David J. Brenes" Date: Wed, 8 Jun 2016 01:53:02 +0200 Subject: [PATCH] Removing static_files warnings in Rails 5 Issue #19 --- app/models/no_cms/blocks/block.rb | 23 ++++++++++++++++++++++- spec/dummy/config/environments/test.rb | 9 +++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/models/no_cms/blocks/block.rb b/app/models/no_cms/blocks/block.rb index 4701b4f..7e9f9d2 100644 --- a/app/models/no_cms/blocks/block.rb +++ b/app/models/no_cms/blocks/block.rb @@ -55,7 +55,28 @@ def fields_configuration ## # If we don't have a globalized model yet we return our temporary layout def layout - globalized_model.nil? ? @layout : globalized_model.layout + # Since respond_to_missing? has been reimplemented in + # NoCms::Blocks::Concerns::SerializingFields we need to first check that + # we have the foreign key to access the globalized_model association + # + # This is due to the empty translations Globalize creates sometimes that + # only have locale. + # + # If we don't check then we will throw a non defined attribute + # exception. + + # First we check wether we don't respond to the foreign key of the + # globalize model association + if !respond_to?(self.class.reflections.symbolize_keys[:globalized_model].foreign_key) || + globalized_model.nil? # and then that the globalized model is nil + + # In any of these cases we return our stored layout + @layout + else + # If we can access to the globalized_model, then we return its + # information + globalized_model.layout + end end include NoCms::Blocks::Concerns::SerializingFields diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 217bb3c..2dab429 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -13,8 +13,13 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + if Rails.version > "5" + config.public_file_server.enabled = true + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } + else + config.serve_static_files = true + config.static_cache_control = "public, max-age=3600" + end # Show full error reports and disable caching. config.consider_all_requests_local = true