cleaned up the spec

This commit is contained in:
sankaranarayanan 2012-09-24 22:55:04 +05:30
parent c12592a1de
commit 12bf16f051
2 changed files with 30 additions and 43 deletions

View File

@ -1,4 +1,3 @@
require 'pry'
module Draper
module ViewContext
def self.current

View File

@ -1,57 +1,45 @@
require 'spec_helper'
describe Draper::DecoratedEnumerableProxy do
describe "View context" do
before(:each){ ApplicationController.new.view_context }
subject{ ProductsDecorator.new(source, ProductDecorator) }
let(:source){ Product.new }
let(:non_active_model_source){ NonActiveModelProduct.new }
before(:each){ ApplicationController.new.view_context }
subject{ ProductsDecorator.new(source, ProductDecorator) }
let(:source){ Product.new }
let(:non_active_model_source){ NonActiveModelProduct.new }
context(".helpers") do
it "have a valid view_context" do
subject.helpers.should be
end
it "is aliased to .h" do
subject.h.should == subject.helpers
end
context(".helpers") do
it "have a valid view_context" do
subject.helpers.should be
end
context(".decorates") do
it "sets the model for the decorated" do
EnumerableProxy.new([source], ProductDecorator).first.model.should == source
end
it "is aliased to .h" do
subject.h.should == subject.helpers
end
it "decorates an empty array with the klass" do
EnumerableProxy.decorates([], klass: ProductDecorator).should be
end
it "discerns collection items decorator by the name of the decorator" do
ProductsDecorator.decorates([]).should be
end
it "methods in decorated empty array should work" do
ProductsDecorator.decorates([]).some_method.should == "some method works"
end
it "raises when decorates an empty array without the klass" do
lambda{EnumerableProxy.decorates([])}.should raise_error
end
it "build a new view context" do
Thread.current[:current_view_context] = nil
subject.helpers.should be
end
end
describe "No View Context" do
subject{ ProductsDecorator.new(source, ProductDecorator) }
let(:source){ Product.new }
context(".decorates") do
it "sets the model for the decorated" do
EnumerableProxy.new([source], ProductDecorator).first.model.should == source
end
context(".helpers") do
it "have a valid view_context" do
subject.helpers.should be
end
it "decorates an empty array with the klass" do
EnumerableProxy.decorates([], klass: ProductDecorator).should be
end
it "is aliased to .h" do
subject.h.should == subject.helpers
end
it "discerns collection items decorator by the name of the decorator" do
ProductsDecorator.decorates([]).should be
end
it "methods in decorated empty array should work" do
ProductsDecorator.decorates([]).some_method.should == "some method works"
end
it "raises when decorates an empty array without the klass" do
lambda{EnumerableProxy.decorates([])}.should raise_error
end
end
end