Permalink
Browse files

fixed bug where units with a plural name would not be reloaded

  • Loading branch information...
eudoxa committed Jun 21, 2012
1 parent dbab0f8 commit c06a85f62bf60113387af26c2e40c7aef1078604
Showing with 23 additions and 5 deletions.
  1. +2 −2 lib/chanko/loader.rb
  2. +4 −0 spec/fixtures/test_units/load_units/load_units.rb
  3. +16 −2 spec/lib/loader_spec.rb
  4. +1 −1 spec/spec_helper.rb
View
@@ -109,8 +109,8 @@ def load_expander(unit_name)
def load_core(unit_name, options={})
Chanko::Loader.directories.each do |directory|
Pathname.glob(directory.join("#{unit_name}/#{unit_name}.rb")).sort.each do |filename|
- if require_or_updating_load("#{filename.dirname}/#{filename.basename}")
- Chanko::Unit.clear_function_cache(unit_name.to_s.classify)
+ if result = require_or_updating_load("#{filename.dirname}/#{filename.basename}")
+ Chanko::Unit.clear_function_cache(unit_name.to_s.camelize)
end
end
end
@@ -0,0 +1,4 @@
+module LoadUnits
+ include Chanko::Unit
+end
+
View
@@ -71,13 +71,27 @@
end
describe 'load' do
- it 'should load unit from file' do
+ around(:each) do |example|
+ ActiveSupport::Dependencies.reset_timestamps_and_defined_classes
+ example.run
+ end
+
+ it 'should load singular name unit via file' do
+ Chanko::Unit.should_receive(:clear_function_cache).with('LoadUnit')
Chanko::Loader.load_unit(:load_unit)
Chanko::Loader.size.should == 1
- Object.constants.map(&:to_s).include?(LoadUnit)
+ Object.constants.map(&:to_s).should be_include('LoadUnit')
LoadUnit.ancestors.should be_include(Chanko::Unit)
end
+ it 'should load plural name unit via file' do
+ Chanko::Unit.should_receive(:clear_function_cache).with('LoadUnits')
+ Chanko::Loader.load_unit(:load_units)
+ Chanko::Loader.size.should == 1
+ Object.constants.map(&:to_s).should be_include('LoadUnits')
+ LoadUnits.ancestors.should be_include(Chanko::Unit)
+ end
+
it 'should not notify load error when skip_raise is true' do
Chanko::ExceptionNotifier.should_receive(:notify).exactly(1)
Chanko::Loader.load_unit(:missing_unit, :skip_raise => true)
View
@@ -56,7 +56,7 @@ def fixtures_path
Chanko::Helper.check_to_update_interval = 0
end
- config.after do
+ config.before do
Chanko::Loader.clear_cache!
Chanko::Helper.reset
end

0 comments on commit c06a85f

Please sign in to comment.