spec/draper/base_spec.rb in draper-0.14.0 vs spec/draper/base_spec.rb in draper-0.15.0rc1

- old
+ new

@@ -152,10 +152,18 @@ it "causes the association to be decorated with the specified association" do subject.previous_version.should be_instance_of(SpecificProductDecorator) end end + context "with a scope specified" do + before(:each){ subject.class_eval{ decorates_association :thing, :scope => :foo } } + it "applies the scope before decoration" do + SomeThing.any_instance.should_receive(:foo).and_return(:bar) + subject.thing.model.should == :bar + end + end + context "for a polymorphic association" do before(:each){ subject.class_eval{ decorates_association :thing, :polymorphic => true } } it "causes the association to be decorated with the right decorator" do subject.thing.should be_instance_of(SomeThingDecorator) end @@ -701,22 +709,27 @@ decorator.helpers.should_receive(:localize).with(now) decorator.l now end end - describe "#method_missing" do - context "when #hello_world is called for the first time" do - it "hits method missing" do - subject.should_receive(:method_missing) - subject.hello_world + context "#method_missing" do + context "with an isolated decorator class" do + let(:decorator_class) { Class.new(Decorator) } + subject{ decorator_class.new(source) } + + context "when #hello_world is called again" do + it "proxies method directly after first hit" do + subject.methods.should_not include(:hello_world) + subject.hello_world + subject.methods.should include(:hello_world) + end end - end - context "when #hello_world is called again" do - before { subject.hello_world } - it "proxies method directly after first hit" do - subject.should_not_receive(:method_missing) - subject.hello_world + context "when #hello_world is called for the first time" do + it "hits method missing" do + subject.should_receive(:method_missing) + subject.hello_world + end end end context "when the delegated method calls a non-existant method" do it 'should not try to delegate to non-existant methods to not confuse Kernel#Array' do