Force id to be proxied to the model

This commit is contained in:
Michael Fairley 2011-10-16 10:53:58 -07:00
parent f55962ddcb
commit 01c8de21c0
2 changed files with 6 additions and 1 deletions

View File

@ -5,7 +5,7 @@ module Draper
attr_accessor :context, :model
DEFAULT_DENIED = Object.new.methods << :method_missing
FORCED_PROXY = [:to_param]
FORCED_PROXY = [:to_param, :id]
FORCED_PROXY.each do |method|
define_method method do |*args, &block|
model.send method, *args, &block

View File

@ -74,6 +74,11 @@ describe Draper::Base do
Draper::Base.new(source).to_param.should == 1
end
it "should always proxy id" do
source.send :class_eval, "def id; 123456789; end"
Draper::Base.new(source).id.should == 123456789
end
it "should not copy the .class, .inspect, or other existing methods" do
source.class.should_not == subject.class
source.inspect.should_not == subject.inspect