Added .source / .to_source both to Base and DecoratedEnumerableProxy.

This commit is contained in:
Mario Uher 2012-01-27 20:40:49 +01:00
parent d154059572
commit 1af010c105
3 changed files with 26 additions and 1 deletions

View File

@ -220,12 +220,18 @@ module Draper
def context
options.fetch(:context, {})
end
def context=(input)
options[:context] = input
end
def source
model
end
alias_method :to_source, :model
private
def allow?(method)
(!allowed? || allowed.include?(method) || FORCED_PROXY.include?(method)) && !denied.include?(method)
end

View File

@ -38,5 +38,10 @@ module Draper
def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
end
def source
@wrapped_collection
end
alias_method :to_source, :source
end
end

View File

@ -119,6 +119,13 @@ describe Draper::Base do
end
end
context(".source / .to_source") do
it "should return the wrapped object" do
subject.to_source == source
subject.source == source
end
end
context("selecting methods") do
it "echos the methods of the wrapped class except default exclusions" do
source.methods.each do |method|
@ -438,6 +445,13 @@ describe Draper::Base do
collection.first.context.should == :admin
end
end
context(".source / .to_source") do
it "should return the wrapped object" do
subject.to_source == source
subject.source == source
end
end
end
describe "a sample usage with denies" do