From c702dfa1a6fbf8e90538b1c6a3251801cbc232cd Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Fri, 21 Nov 2014 11:10:59 +0100 Subject: [PATCH] Lotus::View.load! now freezes framework, views and layouts configurations --- lib/lotus/layout.rb | 1 + lib/lotus/view.rb | 1 + lib/lotus/view/configuration.rb | 1 + lib/lotus/view/dsl.rb | 1 + test/fixtures.rb | 4 ++ test/integration/framework_freeze_test.rb | 47 +++++++++++++++++++++++ test/test_helper.rb | 1 + 7 files changed, 56 insertions(+) create mode 100644 test/integration/framework_freeze_test.rb diff --git a/lib/lotus/layout.rb b/lib/lotus/layout.rb index d76d1f99..5e7e7bab 100644 --- a/lib/lotus/layout.rb +++ b/lib/lotus/layout.rb @@ -99,6 +99,7 @@ def suffix # @see Lotus::View.load! def load! registry.freeze + configuration.freeze end end diff --git a/lib/lotus/view.rb b/lib/lotus/view.rb index 4f3917c6..4ed81e21 100644 --- a/lib/lotus/view.rb +++ b/lib/lotus/view.rb @@ -287,6 +287,7 @@ def self.load! # @since 0.1.0 # @api private def self.unload! + self.configuration = configuration.duplicate configuration.unload! end end diff --git a/lib/lotus/view/configuration.rb b/lib/lotus/view/configuration.rb index 7f91e1e5..ba29d122 100644 --- a/lib/lotus/view/configuration.rb +++ b/lib/lotus/view/configuration.rb @@ -274,6 +274,7 @@ def duplicate def load! views.each { |v| v.__send__(:load!) } layouts.each { |l| l.__send__(:load!) } + freeze end # Reset all the values to the defaults diff --git a/lib/lotus/view/dsl.rb b/lib/lotus/view/dsl.rb index 374d1848..4e664cca 100644 --- a/lib/lotus/view/dsl.rb +++ b/lib/lotus/view/dsl.rb @@ -318,6 +318,7 @@ def load! v.format.freeze v.template.freeze v.layout#.freeze + v.configuration.freeze end end end diff --git a/test/fixtures.rb b/test/fixtures.rb index 285aa214..a97484d7 100644 --- a/test/fixtures.rb +++ b/test/fixtures.rb @@ -291,6 +291,10 @@ class Index template 'store/templates/home/index' layout :store end + + class JsonIndex < Index + format :json + end end end end diff --git a/test/integration/framework_freeze_test.rb b/test/integration/framework_freeze_test.rb new file mode 100644 index 00000000..97052ff6 --- /dev/null +++ b/test/integration/framework_freeze_test.rb @@ -0,0 +1,47 @@ +require 'test_helper' + +describe 'Framework freeze' do + describe 'Lotus::View' do + before do + Lotus::View.load! + end + + it 'freezes framework configuration' do + Lotus::View.configuration.must_be :frozen? + end + + it 'freezes view configuration' do + AppView.configuration.must_be :frozen? + end + + it 'freezes view subclass configuration' do + AppViewLayout.configuration.must_be :frozen? + end + + it 'freezes layout configuration' do + ApplicationLayout.configuration.must_be :frozen? + end + end + + describe 'duplicated framework' do + before do + Store::View.load! + end + + it 'freezes framework configuration' do + Store::View.configuration.must_be :frozen? + end + + it 'freezes view configuration' do + Store::Views::Home::Index.configuration.must_be :frozen? + end + + it 'freezes view subclass configuration' do + Store::Views::Home::JsonIndex.configuration.must_be :frozen? + end + + it 'freezes layout configuration' do + Store::Views::StoreLayout.configuration.must_be :frozen? + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index a066b878..1dad6f59 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,6 +25,7 @@ end require 'fixtures' +Lotus::View.load! Lotus::Utils::LoadPaths.class_eval do def include?(object)