Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Unit never run when once aborts.

  • Loading branch information...
commit ef7db9b1eb0065df4583cb7d3312fb0869d3924a 1 parent 333aaa2
@eudoxa eudoxa authored
View
1  .gitignore
@@ -2,3 +2,4 @@ log/*
tmp/*
Gemfile.lock
webrat.log
+*.log
View
1  lib/chanko/function.rb
@@ -54,6 +54,7 @@ def invoke!(scope, options={})
result
end
rescue ::Exception => e
+ Chanko::Loader.aborted(unit.unit_name)
Chanko::ExceptionNotifier.notify("raise exception #{unit.name}##{@label} => #{e.message}", self.unit.default?,
:exception => e, :backtrace => e.backtrace[0..20], :key => "#{unit.name}_exception", :context => scope)
return Chanko::Aborted
View
12 lib/chanko/invoker.rb
@@ -95,14 +95,10 @@ def invoke(*args, &block)
unit_locals.pop
end
- def array(obj)
- obj.is_a?(Array) ? obj : [obj]
- end
- private :array
def validate_depend_on_units(depended_units, options={})
return true unless depended_units
- array(depended_units).each do |unit_name|
+ Array.wrap(depended_units).each do |unit_name|
return false unless unit = Chanko::Loader.fetch(unit_name)
return false unless unit.enabled?(self, options)
end
@@ -110,10 +106,16 @@ def validate_depend_on_units(depended_units, options={})
end
private :validate_depend_on_units
+ def aborted?(unit)
+ Chanko::Loader.aborted_units.include?(unit.unit_name)
+ end
+ private :aborted?
+
def get_functions(requests, depend_on, active_if_options, options={})
return [] unless validate_depend_on_units(depend_on, active_if_options)
requests.each do |unit_name, label|
next unless unit = Chanko::Loader.fetch(unit_name)
+ next if aborted?(unit)
functions = unit.functions(self, label, active_if_options, options)
next if functions.blank?
Chanko::Loader.invoked(unit_name)
View
32 lib/chanko/loader.rb
@@ -5,8 +5,9 @@ module Loader
mattr_accessor :units
mattr_accessor :loaded
mattr_accessor :current_scopes
- mattr_accessor :__invoked_units
- mattr_accessor :__requested_units
+ mattr_accessor :__invoked
+ mattr_accessor :__requested
+ mattr_accessor :__aborted
self.units = ::HashWithIndifferentAccess.new
class<<self
@@ -24,9 +25,9 @@ def reset!
end
self.current_scopes = []
- self.__invoked_units = []
- self.__requested_units = []
-
+ self.__invoked = []
+ self.__requested = []
+ self.__aborted = []
end
def paths(name)
@@ -46,13 +47,15 @@ def clear_cache!
end
def invoked(unit_names)
- self.__invoked_units.concat(Array.wrap(unit_names).map(&:to_s))
+ self.__invoked.concat(Array.wrap(unit_names).map(&:to_s))
end
def requested(unit_names)
- unit_names = [unit_names] unless unit_names.is_a?(Array)
- unit_names = unit_names.map(&:to_s)
- self.__requested_units.concat(unit_names)
+ self.__requested.concat(Array.wrap(unit_names).map(&:to_s))
+ end
+
+ def aborted(unit_names)
+ self.__aborted.concat(Array.wrap(unit_names).map(&:to_s))
end
def fetch(unit_name)
@@ -76,13 +79,18 @@ def current_scope
end
def invoked_units
- self.__invoked_units.uniq
+ self.__invoked.uniq
end
def requested_units
- self.__requested_units.uniq
+ self.__requested.uniq
end
- #don't expand models when unit_name receive nil
+
+ def aborted_units
+ self.__aborted.uniq
+ end
+
+
def load_expander(unit_name)
%w(models helpers).each do |targets|
Chanko::Loader.directories.each do |directory|
View
41 spec/lib/invoker_spec.rb
@@ -4,7 +4,7 @@
shared_examples_for 'invoker' do
let(:invoker) { Chanko::Test::Invoker.new }
- it 'should run my scoped unit methods' do
+ it 'run my scoped unit methods' do
raise_chanko_exception
mock_unit("RunTest", Chanko::Test::Invoker, {:hoge => 1})
invoker.invoke(:run_test, :hoge)
@@ -13,7 +13,7 @@
describe 'locals' do
context 'cant find' do
- it 'should raise' do
+ it 'raise' do
mock_unit("LocalVariableTest")
LocalVariableTest.class_eval do
scope(Chanko::Test::Invoker) do
@@ -25,7 +25,7 @@
}.to raise_error(NameError)
end
- it 'should not raise when raising is repressed' do
+ it 'not raise when raising is repressed' do
no_raise_chanko_exception
mock_unit("LocalVariableTest")
LocalVariableTest.class_eval do
@@ -39,7 +39,7 @@
end
end
- it 'should skip default' do
+ it 'skip default' do
mock_unit("SkipDefault", Chanko::Test::Invoker, {:hoge => {:value => 1}})
invoker.invoke(:skip_default, :hoge) { @fuga = 1 }
invoker.instance_eval do
@@ -49,7 +49,7 @@
end
- it 'should run first enabled unit' do
+ it 'run first enabled unit' do
mock_unit("FirstTest", Chanko::Test::Invoker, :hello => { :value => Proc.new { run_default; @hello = "hello"} })
mock_unit("SecondTest", Chanko::Test::Invoker, :goodbye => { :value => "goodbye" })
invoker.invoke([:first_test, :hello], [:second_test, :hello]) { @default1 = 1 }
@@ -70,14 +70,14 @@
end
end
- it 'should run other context function' do
+ it 'run other context function' do
mock_unit("SecondTest", :controller, :hello => { :value => "hello" })
invoker.invoke(:second_test, :hello, :as => :controller)
invoker.instance_eval { @hello.should == "hello" }
end
- it 'should run function when depend on unit was enabled' do
+ it 'run function when depend on unit was enabled' do
raise_chanko_exception
mock_unit("DependOnUnit", Chanko::Test::Invoker, { :hello => "hello" })
mock_unit("EnabledUnit", Chanko::Test::Invoker, { :hello => "hello2"})
@@ -85,7 +85,7 @@
invoker.instance_eval { @hello.should == "hello" }
end
- it 'should not run function if depend on unit is disabled' do
+ it 'not run function if depend on unit is disabled' do
no_raise_chanko_exception
mock_unit("DependOnUnit", Chanko::Test::Invoker, { :hello => "hello" })
mock_unit("DisabledUnit", Chanko::Test::Invoker, { :hello => {:value => "hello2"}}, :disable => true)
@@ -93,14 +93,14 @@
invoker.instance_eval { @hello.should == nil }
end
- it 'should not run function if depend on unit is missing' do
+ it 'not run function if depend on unit is missing' do
no_raise_chanko_exception
mock_unit("DependOnUnit", Chanko::Test::Invoker, { :hello => "hello" })
invoker.invoke(:depend_on_unit, :hello, :if => :missing_unit)
invoker.instance_eval { @hello.should == nil }
end
- it 'should access locals' do
+ it 'access locals' do
mock_unit("LocalVariableTest", self.class, {:hoge => 1})
LocalVariableTest.class_eval do
scope(Chanko::Test::Invoker) do
@@ -113,7 +113,7 @@
end
end
- it 'should access nested locals' do
+ it 'access nested function locals' do
mock_unit("LocalVariableTest", self.class, {:hoge => 1})
mock_unit("NestedLocalVariableTest", self.class, {:hoge => 1})
@@ -144,7 +144,7 @@
end
end
- it 'should acceed to active_if symbols' do
+ it 'accede to active_if symbols' do
no_raise_chanko_exception
mock_unit("SymbolActiveIfTest", Chanko::Test::Invoker, { :hello => "hello" })
SymbolActiveIfTest.class_eval { active_if :always_false }
@@ -168,13 +168,9 @@
invoker.invoke(:symbol_active_if_test, :hello)
invoker.instance_eval { @hello.should == nil }
- #FIXME
- #::ErrorLog.count.should == 0
SymbolActiveIfTest.class_eval { active_if :always_true, :nondefined_symbol }
invoker.invoke(:symbol_active_if_test, :hello)
invoker.instance_eval { @hello.should == nil }
- #FIXME
- #::ErrorLog.count.should == 1
SymbolActiveIfTest.class_eval { active_if :always_true do; true; end }
invoker.invoke(:symbol_active_if_test, :hello)
@@ -196,13 +192,24 @@
end
- it 'should set current function' do
+ it 'set current function' do
mock_unit("CurrentFunctionTest", Chanko::Test::Invoker, { :set_current_function => {:value => Proc.new { @current_function = __current_function} }})
invoker.invoke(:current_function_test, :set_current_function)
invoker.instance_eval { @current_function.unit.name.should == "CurrentFunctionTest"}
invoker.instance_eval { @current_function.label.should == :set_current_function}
invoker.__current_function.should be_nil
end
+
+ it 'neve run function when once function aborts' do
+ no_raise_chanko_exception
+ mock_unit("NotRunFunctionTest", Chanko::Test::Invoker,
+ :raise => {:value => Proc.new { raise } },
+ :success => {:value => Proc.new { @success = true} })
+
+ invoker.invoke(:not_run_function_test, :raise)
+ invoker.invoke(:not_run_function_test, :success)
+ invoker.instance_eval { @success.should == nil }
+ end
end
context 'with cache_classes' do
View
19 spec/lib/loader_spec.rb
@@ -6,18 +6,25 @@
describe 'store requested unit names' do
before do
- mock_unit("Invoked", Chanko::Test::Invoker, { :hello => "hello" })
- mock_unit("Requested", Chanko::Test::Invoker, { :hello => {:value => "hello"}}, :disable => true)
- invoker.invoke(:invoked, :hello)
- invoker.invoke(:requested, :hello)
+ no_raise_chanko_exception
+ mock_unit("Invoke", Chanko::Test::Invoker, { :hello => "hello" })
+ mock_unit("Request", Chanko::Test::Invoker, { :hello => {:value => "hello"}}, :disable => true)
+ mock_unit("Abort", Chanko::Test::Invoker, { :hello => {:value => Proc.new { raise }} })
+ invoker.invoke(:invoke, :hello)
+ invoker.invoke(:request, :hello)
+ invoker.invoke(:abort, :hello)
end
it 'get requested unit names' do
- Chanko::Loader.requested_units.should == ["invoked", "requested"]
+ Chanko::Loader.requested_units.should == ["invoke", "request", "abort"]
end
it 'get invoked unit names' do
- Chanko::Loader.invoked_units.should == ["invoked"]
+ Chanko::Loader.invoked_units.should == ["invoke", "abort"]
+ end
+
+ it 'get aborted unit names' do
+ Chanko::Loader.aborted_units.should == ["abort"]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.