Fix minor decorated association context bug

If the context of the owner decorator changes, the default context
of the decorated association should change too.
This commit is contained in:
Andrew Haines 2013-02-06 23:49:50 +00:00
parent a6a60bcf92
commit c6ca04fedd
2 changed files with 10 additions and 5 deletions

View File

@ -9,7 +9,7 @@ module Draper
@association = association
@scope = options[:scope]
@context = options.fetch(:context, owner.context)
@context = options.fetch(:context, ->(context){ context })
@factory = Draper::Factory.new(options.slice(:with))
end

View File

@ -104,10 +104,8 @@ module Draper
describe "#context" do
let(:owner_context) { {some: "context"} }
let(:options) { {} }
let(:decorated_association) do
owner = double(context: owner_context)
DecoratedAssociation.new(owner, :association, options)
end
let(:owner) { double(context: owner_context) }
let(:decorated_association) { DecoratedAssociation.new(owner, :association, options) }
context "when :context option was given" do
let(:options) { {context: context} }
@ -138,6 +136,13 @@ module Draper
it "returns the owner's context" do
expect(decorated_association.context).to be owner_context
end
it "returns the new context if the owner's context changes" do
new_context = {other: "context"}
owner.stub context: new_context
expect(decorated_association.context).to be new_context
end
end
end