Permalink
Browse files

Spec tidy-up

Removes some unneeded sample decorators and reorganises the samples
  • Loading branch information...
1 parent a869595 commit b8ca040653bcb4945bdb8fab79fea7ab2306904f @haines haines committed Nov 9, 2012
@@ -136,11 +136,11 @@
describe ".helpers" do
it "returns a HelperProxy" do
- Decorator.helpers.should be_a Draper::HelperProxy
+ subject.class.helpers.should be_a Draper::HelperProxy
end
it "is aliased to .h" do
- Decorator.h.should be Decorator.helpers
+ subject.class.h.should be subject.class.helpers
end
end
@@ -2,17 +2,17 @@
describe Draper::Decorator do
before { ApplicationController.new.view_context }
- subject { Decorator.new(source) }
- let(:source){ Product.new }
- let(:non_active_model_source){ NonActiveModelProduct.new }
+ subject { decorator_class.new(source) }
+ let(:decorator_class) { Draper::Decorator }
+ let(:source) { Product.new }
describe "#initialize" do
it "sets the source" do
subject.source.should be source
end
it "stores options" do
- decorator = Decorator.new(source, some: "options")
+ decorator = decorator_class.new(source, some: "options")
decorator.options.should == {some: "options"}
end
@@ -106,7 +106,7 @@
describe "#localize" do
before { subject.helpers.should_receive(:localize).with(:an_object, {some: "options"}) }
- it "delegates to helpers" do
+ it "delegates to #helpers" do
subject.localize(:an_object, some: "options")
end
@@ -117,16 +117,17 @@
describe ".helpers" do
it "returns a HelperProxy" do
- Decorator.helpers.should be_a Draper::HelperProxy
+ subject.class.helpers.should be_a Draper::HelperProxy
end
it "is aliased to .h" do
- Decorator.h.should be Decorator.helpers
+ subject.class.h.should be subject.class.helpers
end
end
describe ".decorates_association" do
- before { subject.class.decorates_association :similar_products, with: ProductDecorator }
+ let(:decorator_class) { Class.new(ProductDecorator) }
+ before { decorator_class.decorates_association :similar_products, with: ProductDecorator }
describe "overridden association method" do
let(:decorated_association) { ->{} }
@@ -151,7 +152,7 @@
end
describe ".decorates_associations" do
- subject { Decorator }
+ subject { decorator_class }
it "decorates each of the associations" do
subject.should_receive(:decorates_association).with(:similar_products, {})
@@ -225,7 +226,7 @@
end
describe "#respond_to?" do
- subject { Class.new(ProductDecorator).new(source) }
+ let(:decorator_class) { Class.new(ProductDecorator) }
it "returns true for its own methods" do
subject.should respond_to :awesome_title
@@ -270,7 +271,7 @@
end
describe "method proxying" do
- subject { Class.new(ProductDecorator).new(source) }
+ let(:decorator_class) { Class.new(ProductDecorator) }
it "does not proxy methods that are defined on the decorator" do
subject.overridable.should be :overridden
@@ -348,26 +349,26 @@
end
context "in a Rails application" do
- let(:decorator){ DecoratorWithApplicationHelper.decorate(Object.new) }
+ let(:decorator_class) { DecoratorWithApplicationHelper }
it "has access to ApplicationHelper helpers" do
- decorator.uses_hello_world.should == "Hello, World!"
+ subject.uses_hello_world.should == "Hello, World!"
end
it "is able to use the content_tag helper" do
- decorator.sample_content.to_s.should == "<span>Hello, World!</span>"
+ subject.sample_content.to_s.should == "<span>Hello, World!</span>"
end
it "is able to use the link_to helper" do
- decorator.sample_link.should == "<a href=\"/World\">Hello</a>"
+ subject.sample_link.should == "<a href=\"/World\">Hello</a>"
end
it "is able to use the truncate helper" do
- decorator.sample_truncate.should == "Once..."
+ subject.sample_truncate.should == "Once..."
end
it "is able to access html_escape, a private method" do
- decorator.sample_html_escaped_text.should == '&lt;script&gt;danger&lt;/script&gt;'
+ subject.sample_html_escaped_text.should == '&lt;script&gt;danger&lt;/script&gt;'
end
end
@@ -398,24 +399,28 @@
end
end
- context "with for: symbol" do
- it "sets the finder class" do
- FinderDecorator.has_finders for: :product
- FinderDecorator.finder_class.should be Product
+ context "with :for option" do
+ subject { Class.new(Draper::Decorator) }
+
+ context "with a symbol" do
+ it "sets the finder class" do
+ subject.has_finders for: :product
+ subject.finder_class.should be Product
+ end
end
- end
- context "with for: string" do
- it "sets the finder class" do
- FinderDecorator.has_finders for: "some_thing"
- FinderDecorator.finder_class.should be SomeThing
+ context "with a string" do
+ it "sets the finder class" do
+ subject.has_finders for: "some_thing"
+ subject.finder_class.should be SomeThing
+ end
end
- end
- context "with for: class" do
- it "sets the finder_class" do
- FinderDecorator.has_finders for: Namespace::Product
- FinderDecorator.finder_class.should be Namespace::Product
+ context "with a class" do
+ it "sets the finder_class" do
+ subject.has_finders for: Namespace::Product
+ subject.finder_class.should be Namespace::Product
+ end
end
end
end
View
@@ -3,49 +3,29 @@
require 'rails'
require 'action_view'
-Bundler.require
-
-require './spec/support/samples/active_record'
-require './spec/support/samples/decorator'
-require './spec/support/samples/decorator_with_application_helper'
-require './spec/support/samples/decorator_with_special_methods'
-require './spec/support/samples/finder_decorator'
-require './spec/support/samples/namespaced_product'
-require './spec/support/samples/namespaced_product_decorator'
-require './spec/support/samples/non_active_model_product'
-require './spec/support/samples/non_active_model_product_decorator'
-require './spec/support/samples/product'
-require './spec/support/samples/product_decorator'
-require './spec/support/samples/products_decorator'
-require './spec/support/samples/sequel_product'
-require './spec/support/samples/specific_product_decorator'
-require './spec/support/samples/some_thing'
-require './spec/support/samples/some_thing_decorator'
-require './spec/support/samples/uninferrable_decorator_model'
-require './spec/support/samples/widget'
-require './spec/support/samples/widget_decorator'
-
require 'action_controller'
require 'action_controller/test_case'
-module ActionController
- class Base
- Draper::System.setup_action_controller(self)
- end
-end
-
-module ActiveRecord
- class Relation
- end
-end
-
-class ApplicationController < ActionController::Base
- def hello_world
- "Hello, World!"
- end
- helper_method :hello_world
-end
+Bundler.require
+require './spec/support/active_record'
+require './spec/support/action_controller'
+
+require './spec/support/models/product'
+require './spec/support/models/namespaced_product'
+require './spec/support/models/non_active_model_product'
+require './spec/support/models/widget'
+require './spec/support/models/some_thing'
+require './spec/support/models/uninferrable_decorator_model'
+
+require './spec/support/decorators/product_decorator'
+require './spec/support/decorators/namespaced_product_decorator'
+require './spec/support/decorators/non_active_model_product_decorator'
+require './spec/support/decorators/widget_decorator'
+require './spec/support/decorators/specific_product_decorator'
+require './spec/support/decorators/products_decorator'
+require './spec/support/decorators/some_thing_decorator'
+require './spec/support/decorators/decorator_with_application_helper'
class << Rails
undef application # Avoid silly Rails bug: https://github.com/rails/rails/pull/6429
@@ -0,0 +1,12 @@
+module ActionController
+ class Base
+ Draper::System.setup_action_controller(self)
+ end
+end
+
+class ApplicationController < ActionController::Base
+ def hello_world
+ "Hello, World!"
+ end
+ helper_method :hello_world
+end
@@ -15,3 +15,8 @@ def self.limit
end
end
+
+module ActiveRecord
+ class Relation
+ end
+end
@@ -1,5 +1,3 @@
-require './spec/support/samples/namespaced_product'
-
module Namespace
class ProductDecorator < Draper::Decorator
has_finders
@@ -1,4 +1,2 @@
-require './spec/support/samples/product_decorator'
-
class SpecificProductDecorator < ProductDecorator
end
@@ -1,5 +1,3 @@
-require './spec/support/samples/product'
-
module Namespace
class Product < ActiveRecord::Base
include Draper::Decoratable
File renamed without changes.
File renamed without changes.
@@ -1,5 +0,0 @@
-class Decorator < Draper::Decorator
- def self.own_class_method
- "own class method"
- end
-end
@@ -1,13 +0,0 @@
-class DecoratorWithSpecialMethods < Draper::Decorator
- def to_param
- "foo"
- end
-
- def id
- 1337
- end
-
- def errors
- ["omg errors!"]
- end
-end
@@ -1,2 +0,0 @@
-class FinderDecorator < Draper::Decorator
-end
@@ -1,13 +0,0 @@
-module Sequel
- class Model
- def each
- end
- end
-end
-
-class SequelProduct < Sequel::Model
- def some_attribute
- "hello"
- end
-end
-

0 comments on commit b8ca040

Please sign in to comment.