[rspec-devel] [ rspec-Patches-15597 ] [PATCH] Reverse loading of ActionView::Base helper modules

noreply at rubyforge.org noreply at rubyforge.org
Mon Nov 12 22:06:32 EST 2007


Patches item #15597, was opened at 2007-11-12 22:06
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=15597&group_id=797

Category: rails plugin
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Mark Van Holstyn (lotswholetime)
Assigned to: Nobody (None)
Summary: [PATCH] Reverse loading of ActionView::Base helper modules

Initial Comment:
I have one application which aliases some view helpers. The code works fine, but the specs fail with this error...

~/application/vendor/rails/activesupport/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `expand_javascript_sources' for class `Spec::Rails::DSL::HelperExample' (NameError)
    from ~/application/vendor/rails/activesupport/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain'
    from ~/application/vendor/plugins/dhtml_calendar/lib/helpers/calendar.rb:59:in `included'
    from ~/application/vendor/plugins/dhtml_calendar/lib/helpers/calendar.rb:58:in `class_eval'
    from ~/application/vendor/plugins/dhtml_calendar/lib/helpers/calendar.rb:58:in `included'
    from ~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:37:in `include'
    from ~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:37
    from ~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:36:in `each'
    from ~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:36
     ... 51 levels...
    from ~/application/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:13:in `load_files'
    from ~/application/vendor/plugins/rspec/lib/spec/runner/options.rb:73:in `run_examples'
    from ~/application/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run'
    from ~/application/vendor/plugins/rspec/bin/spec:3

Looking at the code, I notice this:

ActionView::Base.included_modules.each do |mod|
  include mod if mod.parents.include?(ActionView::Helpers)
end

The problem is that "included_modules" returns the included modules in the reverse order that they were included.

>> ActionView::Base.included_modules
=> [#<Module:0x192cca4>, ActionController::Routing::Helpers, ActionController::PolymorphicRoutes, WillPaginate::ViewHelpers, FileColumnHelper, ActionView::Helpers::DhtmlCalendarHelper, ActionView::Helpers::UrlHelper, ActionView::Helpers::TextHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::ScriptaculousHelper, ActionView::Helpers::SanitizeHelper, ActionView::Helpers::RecordTagHelper, ActionView::Helpers::RecordIdentificationHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::PrototypeHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormHelper, ActionView::Helpers::DebugHelper, ActionView::Helpers::DateHelper, ActionView::Helpers::CaptureHelper, ActionView::Helpers::CacheHelper, ActionView::Helpers::BenchmarkHelper, ActionView::Helpers::AtomFeedHelper, ActionView::Helpers::AssetTagHelper, ActionView::Helpers::ActiveRecordHelper, ActionView::Partials, ActionView::Base::CompiledTemplates, ERB::Util, InstanceExecMethods, Base64::Deprecated, Base64, PP::ObjectMixin, Kernel]

My module is now included BEFORE any of the modules provided by rails, so the alias call fails. This patch changes the HelperExample definition to  reverse the array returned from included_modules so that they are included in the proper order.


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=15597&group_id=797


More information about the rspec-devel mailing list