Skip to content

Commit

Permalink
Lotus::View.load! now freezes framework, views and layouts configurat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
jodosha committed Nov 21, 2014
1 parent 7bedd52 commit c702dfa
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/lotus/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def suffix
# @see Lotus::View.load!
def load!
registry.freeze
configuration.freeze
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/lotus/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def self.load!
# @since 0.1.0
# @api private
def self.unload!
self.configuration = configuration.duplicate
configuration.unload!
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/lotus/view/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/lotus/view/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def load!
v.format.freeze
v.template.freeze
v.layout#.freeze
v.configuration.freeze
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ class Index
template 'store/templates/home/index'
layout :store
end

class JsonIndex < Index
format :json
end
end
end
end
Expand Down
47 changes: 47 additions & 0 deletions test/integration/framework_freeze_test.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
end

require 'fixtures'
Lotus::View.load!

Lotus::Utils::LoadPaths.class_eval do
def include?(object)
Expand Down

0 comments on commit c702dfa

Please sign in to comment.