Skip to content

Commit

Permalink
Introduce Lotus::Controller.load! as loading framework entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Nov 21, 2014
1 parent 0796747 commit 0a18e44
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/lotus/action.rb
Expand Up @@ -75,7 +75,5 @@ def self.included(base)
# @see Lotus::Action::Cache
def finish
end


end
end
2 changes: 1 addition & 1 deletion lib/lotus/action/configurable.rb
Expand Up @@ -36,7 +36,7 @@ def self.included(base)
self.configuration = config
end

config.load!(base)
config.copy!(base)
end

private
Expand Down
5 changes: 5 additions & 0 deletions lib/lotus/controller.rb
Expand Up @@ -264,6 +264,11 @@ def self.included(base)
self.configuration = conf
end
end

# @since x.x.x
def self.load!
configuration.load!
end
end
end

14 changes: 11 additions & 3 deletions lib/lotus/controller/configuration.rb
Expand Up @@ -517,22 +517,30 @@ def reset!
@action_module = ::Lotus::Action
end

# Load the configuration for the given action
# Copy the configuration for the given action
#
# @param base [Class] the target action
#
# @return void
#
# @since 0.2.0
# @since x.x.x
# @api private
#
# @see Lotus::Controller::Configurable.included
def load!(base)
def copy!(base)
modules.each do |mod|
base.class_eval(&mod)
end
end

# Load the framework
#
# @since x.x.x
# @api private
def load!
freeze
end

protected

attr_accessor :handled_exceptions
Expand Down
2 changes: 2 additions & 0 deletions test/controller_test.rb
Expand Up @@ -3,6 +3,8 @@
describe Lotus::Controller do
describe '.configuration' do
before do
Lotus::Controller.unload!

module ConfigurationController
include Lotus::Controller
end
Expand Down
31 changes: 31 additions & 0 deletions test/integration/framework_freeze_test.rb
@@ -0,0 +1,31 @@
require 'test_helper'

describe 'Framework freeze' do
describe 'Lotus::Controller' do
before do
Lotus::Controller.load!
end

it 'freezes framework configuration' do
Lotus::Controller.configuration.must_be :frozen?
end

# it 'freezes action configuration' do
# CallAction.configuration.must_be :frozen?
# end
end

describe 'duplicated framework' do
before do
MusicPlayer::Controller.load!
end

it 'freezes framework configuration' do
MusicPlayer::Controller.configuration.must_be :frozen?
end

# it 'freezes action configuration' do
# MusicPlayer::Controllers::Artists::Index.configuration.must_be :frozen?
# end
end
end
7 changes: 7 additions & 0 deletions test/test_helper.rb
Expand Up @@ -23,6 +23,13 @@
require 'lotus/action/session'
require 'fixtures'

Lotus::Controller.class_eval do
def self.unload!
self.configuration = configuration.duplicate
configuration.reset!
end
end

Lotus::Controller::Configuration.class_eval do
def ==(other)
other.kind_of?(self.class) &&
Expand Down
2 changes: 1 addition & 1 deletion test/throw_test.rb
Expand Up @@ -2,7 +2,7 @@

describe Lotus::Action do
before do
Lotus::Controller.configuration.reset!
Lotus::Controller.unload!
end

describe '.handle_exception' do
Expand Down

0 comments on commit 0a18e44

Please sign in to comment.