问题 1 :
class < Action::Base
def current_user
...
end
end
class Home <
def index
current_user # 为什么 的方法还能在Home里面用?
end
end
问题 2:
require "spec_helper"
class < Action::Base
protect_from_forgery
def current_user
session[:user_id]
end
end
describe ApplicationController do
describe "current_user" do
it "should return nil if no one is logged in" do
subject.current_user.should be_nil
end
it "should return currently logged in user" do
hash = {user_id: "my_id"}
subject.should_receive(:session).and_return hash
subject.current_user.should == "my_id"
end
end
end
NoMethodError:: `current_user' called for #<? 为什么会在测试中找不到实例方法?