Skip to content

Commit

Permalink
This fixes the following bug reported by robbevan
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxa committed May 7, 2012
1 parent ac974da commit d953594
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 20 deletions.
23 changes: 10 additions & 13 deletions lib/chanko/invoker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ def self.included(obj)
mattr_accessor :defined_blocks
attr_accessor :attached_unit_classes
attr_accessor :__current_function
end

define_once(:method_missing_with_shared_method) do
def method_missing_with_shared_method(method_symbol, *args)
if block = self.attached_unit_classes.try(:last).try(:shared_method, method_symbol)
self.instance_exec(*args, &block)
else
method_missing_without_shared_method(method_symbol, *args)
end
end
alias_method_chain :method_missing, :shared_method
end
end

def method_missing(method_symbol, *args)
if block = self.attached_unit_classes.try(:last).try(:shared_method, method_symbol)
self.instance_exec(*args, &block)
else
super(method_symbol, *args)
end
end

Expand All @@ -34,13 +32,12 @@ def view?
self.is_a?(ActionView::Base) && respond_to?("concat")
end

def method_missing_with_access_locals(method_symbol, *args)
def method_missing(method_symbol, *args)
if _has_local_val?(method_symbol, *args)
return _local_val(method_symbol)
end
method_missing_without_access_locals(method_symbol, *args)
super(method_symbol, *args)
end
alias_method_chain :method_missing, :access_locals

def _local_val(method_symbol)
current_locals[method_symbol]
Expand Down
2 changes: 1 addition & 1 deletion spec/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Application < Rails::Application
end
end

require 'app/route.rb'
require 'app/route'
require 'app/controller'


Expand Down
26 changes: 22 additions & 4 deletions spec/app/controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
class ApplicationController < ActionController::Base; end
ApplicationController.view_paths = File.dirname(__FILE__)
# helpers
module ApplicationHelper
include Chanko::Invoker
end

class ApplicationController < ActionController::Base
include Chanko::Invoker
include Rails.application.routes.url_helpers
def _routes() ::Rails.application.routes end
def controller() parent_controller end
end

ActionView::TestCase::TestController.class_eval do
include Chanko::Invoker
include Rails.application.routes.url_helpers
def _routes() ::Rails.application.routes end
def controller() parent_controller end
end

ApplicationController.view_paths = File.join(File.dirname(__FILE__), 'views')
ActionView::TestCase::TestController.view_paths = File.join(File.dirname(__FILE__), 'views')


class InvokeController < ApplicationController
layout 'application'
Expand All @@ -23,5 +43,3 @@ def content_for_hello
end
end

# helpers
Object.const_set(:ApplicationHelper, Module.new)
2 changes: 2 additions & 0 deletions spec/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class UsersController < ApplicationController
end
2 changes: 2 additions & 0 deletions spec/app/route.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Chanko::Application.routes.draw do
resources :users do
end
match '/:controller(/:action(/:id))'
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions spec/app/views/users/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= link_to 'index', users_path
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ def fixtures_path
# instead of true.
#config.use_transactional_fixtures = true

#config.include Rails.application.routes.url_helpers

config.before(:suite) do
$: << fixtures_path.join('lib')
path = fixtures_path.join('test_units')
Chanko::Loader.directories.unshift(path)
Chanko::ActiveIf.files = [fixtures_path.join('active_if', "main")]
ApplicationController.send(:include, Chanko::Invoker)
ActionView::Base.send(:include, Chanko::Invoker)
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
end

config.before do
Chanko::Helper.check_to_update_interval = 0
end
Expand Down
9 changes: 9 additions & 0 deletions spec/views/index.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# encoding: UTF-8
require 'spec_helper'

describe "users/index.html.haml" do
it "render users_path" do
render
rendered.should include(users_path)
end
end

0 comments on commit d953594

Please sign in to comment.