draper 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/CHANGELOG.txt +4 -0
- data/Readme.markdown +20 -0
- data/draper.gemspec +2 -3
- data/lib/draper/active_model_support.rb +2 -4
- data/lib/draper/base.rb +0 -2
- data/lib/draper/decorated_enumerable_proxy.rb +1 -5
- data/lib/draper/railtie.rb +8 -1
- data/lib/draper/version.rb +1 -1
- data/spec/draper/base_spec.rb +55 -55
- data/spec/draper/model_support_spec.rb +4 -4
- data/spec/spec_helper.rb +0 -1
- metadata +42 -57
    
        data/.gitignore
    CHANGED
    
    
    
        data/CHANGELOG.txt
    CHANGED
    
    
    
        data/Readme.markdown
    CHANGED
    
    | @@ -357,6 +357,26 @@ Now when you call the association it will use a decorator. | |
| 357 357 | 
             
            <%= @article.author.fancy_name %>
         | 
| 358 358 | 
             
            ```
         | 
| 359 359 |  | 
| 360 | 
            +
            ### A note on Rails configuration
         | 
| 361 | 
            +
             | 
| 362 | 
            +
            Draper loads your application's decorators when Rails start. This may lead to an issue with configuring I18n, whereby the settings you provide in `./config/application.rb` are ignored. This happens when you use the `I18n` constant at the class-level in one of the models that have a decorator, as in the following example:
         | 
| 363 | 
            +
             | 
| 364 | 
            +
            ```ruby
         | 
| 365 | 
            +
            # app/models/user.rb
         | 
| 366 | 
            +
            class User < ActiveRecord::Base
         | 
| 367 | 
            +
              validates :email, presence: { message: I18n.t('invalid_email') }
         | 
| 368 | 
            +
            end
         | 
| 369 | 
            +
             | 
| 370 | 
            +
            # app/decorators/user_decorator.rb
         | 
| 371 | 
            +
            class UserDecorator < ApplicationDecorator
         | 
| 372 | 
            +
              decorates :user
         | 
| 373 | 
            +
            end
         | 
| 374 | 
            +
            ```
         | 
| 375 | 
            +
             | 
| 376 | 
            +
            Note how the `validates` line is executed when the `User` class is loaded, triggering the initialization of the I18n framework _before_ Rails had a chance to apply its configuration.
         | 
| 377 | 
            +
             | 
| 378 | 
            +
            Using `I18n` directly in your model definition **is an antipattern**. The preferred solution would be to not override the `message` option in your `validates` macro, but provide the `activerecord.errors.models.attributes.user.email.presence` key in your translation files.
         | 
| 379 | 
            +
             | 
| 360 380 | 
             
            ## Contributing
         | 
| 361 381 |  | 
| 362 382 | 
             
            1. Fork it.
         | 
    
        data/draper.gemspec
    CHANGED
    
    | @@ -16,9 +16,6 @@ Gem::Specification.new do |s| | |
| 16 16 | 
             
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 17 17 | 
             
              s.require_paths = ["lib"]
         | 
| 18 18 |  | 
| 19 | 
            -
              s.add_dependency 'activesupport', '~> 3.2'
         | 
| 20 | 
            -
              s.add_dependency 'rake', '~> 0.9.2'
         | 
| 21 | 
            -
              s.add_dependency 'rspec', '~> 2.10'
         | 
| 22 19 | 
             
              s.add_dependency 'activesupport', '~> 3.2'
         | 
| 23 20 | 
             
              s.add_dependency 'actionpack', '~> 3.2'
         | 
| 24 21 |  | 
| @@ -26,5 +23,7 @@ Gem::Specification.new do |s| | |
| 26 23 | 
             
              s.add_development_dependency 'guard'
         | 
| 27 24 | 
             
              s.add_development_dependency 'guard-rspec'
         | 
| 28 25 | 
             
              s.add_development_dependency 'launchy'
         | 
| 26 | 
            +
              s.add_development_dependency 'rake', '~> 0.9.2'
         | 
| 27 | 
            +
              s.add_development_dependency 'rspec', '~> 2.10'
         | 
| 29 28 | 
             
              s.add_development_dependency 'yard'
         | 
| 30 29 | 
             
            end
         | 
| @@ -10,11 +10,9 @@ module Draper::ActiveModelSupport | |
| 10 10 |  | 
| 11 11 | 
             
                  proxies.each do |method_name, dependency|
         | 
| 12 12 | 
             
                    if base.model.kind_of?(dependency) || dependency.nil?
         | 
| 13 | 
            -
                       | 
| 14 | 
            -
                        self
         | 
| 15 | 
            -
                      end.class_eval do
         | 
| 13 | 
            +
                      base.singleton_class.class_eval do
         | 
| 16 14 | 
             
                        if !base.class.instance_methods.include?(method_name) || base.class.instance_method(method_name).owner === Draper::Base
         | 
| 17 | 
            -
                           | 
| 15 | 
            +
                          define_method(method_name) do |*args, &block|
         | 
| 18 16 | 
             
                            model.send(method_name, *args, &block)
         | 
| 19 17 | 
             
                          end
         | 
| 20 18 | 
             
                        end
         | 
    
        data/lib/draper/base.rb
    CHANGED
    
    | @@ -11,8 +11,6 @@ module Draper | |
| 11 11 | 
             
                self.denied = DEFAULT_DENIED
         | 
| 12 12 | 
             
                self.allowed = DEFAULT_ALLOWED
         | 
| 13 13 |  | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 14 | 
             
                # Initialize a new decorator instance by passing in
         | 
| 17 15 | 
             
                # an instance of the source class. Pass in an optional
         | 
| 18 16 | 
             
                # context inside the options hash is stored for later use.
         | 
| @@ -30,14 +30,10 @@ module Draper | |
| 30 30 | 
             
                  @wrapped_collection == other
         | 
| 31 31 | 
             
                end
         | 
| 32 32 |  | 
| 33 | 
            -
                def [](index)
         | 
| 34 | 
            -
                  @klass.new(@wrapped_collection[index], @options)
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 33 | 
             
                def to_s
         | 
| 38 34 | 
             
                  "#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
         | 
| 39 35 | 
             
                end
         | 
| 40 | 
            -
             | 
| 36 | 
            +
             | 
| 41 37 | 
             
                def context=(input)
         | 
| 42 38 | 
             
                  self.map { |member| member.context = input }
         | 
| 43 39 | 
             
                end
         | 
    
        data/lib/draper/railtie.rb
    CHANGED
    
    | @@ -30,7 +30,7 @@ module Draper | |
| 30 30 | 
             
                # This is the standard "Rails Way" to add paths from which constants
         | 
| 31 31 | 
             
                # can be loaded.
         | 
| 32 32 | 
             
                #
         | 
| 33 | 
            -
                config. | 
| 33 | 
            +
                config.after_initialize do |app|
         | 
| 34 34 | 
             
                  app.config.paths.add 'app/decorators', :eager_load => true
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| @@ -46,5 +46,12 @@ module Draper | |
| 46 46 | 
             
                  end
         | 
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 | 
            +
                console do
         | 
| 50 | 
            +
                  require 'action_controller/test_case'
         | 
| 51 | 
            +
                  ApplicationController.new.set_current_view_context
         | 
| 52 | 
            +
                  Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new
         | 
| 53 | 
            +
                  Draper::ViewContext.current.request            ||= Draper::ViewContext.current.controller.request
         | 
| 54 | 
            +
                  Draper::ViewContext.current.params             ||= {}
         | 
| 55 | 
            +
                end
         | 
| 49 56 | 
             
              end
         | 
| 50 57 | 
             
            end
         | 
    
        data/lib/draper/version.rb
    CHANGED
    
    
    
        data/spec/draper/base_spec.rb
    CHANGED
    
    | @@ -7,35 +7,35 @@ describe Draper::Base do | |
| 7 7 | 
             
              let(:non_active_model_source){ NonActiveModelProduct.new }
         | 
| 8 8 |  | 
| 9 9 | 
             
              context("proxying class methods") do
         | 
| 10 | 
            -
                it " | 
| 10 | 
            +
                it "pass missing class method calls on to the wrapped class" do
         | 
| 11 11 | 
             
                  subject.class.sample_class_method.should == "sample class method"
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 | 
            -
                it " | 
| 14 | 
            +
                it "respond_to a wrapped class method" do
         | 
| 15 15 | 
             
                  subject.class.should respond_to(:sample_class_method)
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 | 
            -
                it " | 
| 18 | 
            +
                it "still respond_to its own class methods" do
         | 
| 19 19 | 
             
                  subject.class.should respond_to(:own_class_method)
         | 
| 20 20 | 
             
                end
         | 
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 23 | 
             
              context(".helpers") do
         | 
| 24 | 
            -
                it " | 
| 24 | 
            +
                it "have a valid view_context" do
         | 
| 25 25 | 
             
                  subject.helpers.should be
         | 
| 26 26 | 
             
                end
         | 
| 27 27 |  | 
| 28 | 
            -
                it " | 
| 28 | 
            +
                it "is aliased to .h" do
         | 
| 29 29 | 
             
                  subject.h.should == subject.helpers
         | 
| 30 30 | 
             
                end
         | 
| 31 31 | 
             
              end
         | 
| 32 32 |  | 
| 33 33 | 
             
              context("#helpers") do
         | 
| 34 | 
            -
                it " | 
| 34 | 
            +
                it "have a valid view_context" do
         | 
| 35 35 | 
             
                  Decorator.helpers.should be
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| 38 | 
            -
                it " | 
| 38 | 
            +
                it "is aliased to #h" do
         | 
| 39 39 | 
             
                  Decorator.h.should == Decorator.helpers
         | 
| 40 40 | 
             
                end
         | 
| 41 41 | 
             
              end
         | 
| @@ -50,7 +50,7 @@ describe Draper::Base do | |
| 50 50 | 
             
                  ProductDecorator.new(product_decorator).model.should be_instance_of Product
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 | 
            -
                it " | 
| 53 | 
            +
                it "handle plural-like words properly'" do
         | 
| 54 54 | 
             
                  class Business; end
         | 
| 55 55 | 
             
                  expect do
         | 
| 56 56 | 
             
                    class BusinessDecorator < Draper::Base
         | 
| @@ -183,13 +183,13 @@ describe Draper::Base do | |
| 183 183 | 
             
              end
         | 
| 184 184 |  | 
| 185 185 | 
             
              context(".wrapped_object") do
         | 
| 186 | 
            -
                it " | 
| 186 | 
            +
                it "return the wrapped object" do
         | 
| 187 187 | 
             
                  subject.wrapped_object.should == source
         | 
| 188 188 | 
             
                end
         | 
| 189 189 | 
             
              end
         | 
| 190 190 |  | 
| 191 191 | 
             
              context(".source / .to_source") do
         | 
| 192 | 
            -
                it " | 
| 192 | 
            +
                it "return the wrapped object" do
         | 
| 193 193 | 
             
                  subject.to_source == source
         | 
| 194 194 | 
             
                  subject.source == source
         | 
| 195 195 | 
             
                end
         | 
| @@ -204,42 +204,42 @@ describe Draper::Base do | |
| 204 204 | 
             
                  end
         | 
| 205 205 | 
             
                end
         | 
| 206 206 |  | 
| 207 | 
            -
                it " | 
| 207 | 
            +
                it "not override a defined method with a source method" do
         | 
| 208 208 | 
             
                  DecoratorWithApplicationHelper.new(source).length.should == "overridden"
         | 
| 209 209 | 
             
                end
         | 
| 210 210 |  | 
| 211 | 
            -
                it " | 
| 211 | 
            +
                it "not copy the .class, .inspect, or other existing methods" do
         | 
| 212 212 | 
             
                  source.class.should_not == subject.class
         | 
| 213 213 | 
             
                  source.inspect.should_not == subject.inspect
         | 
| 214 214 | 
             
                  source.to_s.should_not == subject.to_s
         | 
| 215 215 | 
             
                end
         | 
| 216 216 |  | 
| 217 217 | 
             
                context "when an ActiveModel descendant" do
         | 
| 218 | 
            -
                  it " | 
| 218 | 
            +
                  it "always proxy to_param if it is not defined on the decorator itself" do
         | 
| 219 219 | 
             
                    source.stub(:to_param).and_return(1)
         | 
| 220 220 | 
             
                    Draper::Base.new(source).to_param.should == 1
         | 
| 221 221 | 
             
                  end
         | 
| 222 222 |  | 
| 223 | 
            -
                  it " | 
| 223 | 
            +
                  it "always proxy id if it is not defined on the decorator itself" do
         | 
| 224 224 | 
             
                    source.stub(:id).and_return(123456789)
         | 
| 225 225 | 
             
                    Draper::Base.new(source).id.should == 123456789
         | 
| 226 226 | 
             
                  end
         | 
| 227 227 |  | 
| 228 | 
            -
                  it " | 
| 228 | 
            +
                  it "always proxy errors if it is not defined on the decorator itself" do
         | 
| 229 229 | 
             
                    Draper::Base.new(source).errors.should be_an_instance_of ActiveModel::Errors
         | 
| 230 230 | 
             
                  end
         | 
| 231 231 |  | 
| 232 | 
            -
                  it " | 
| 232 | 
            +
                  it "never proxy to_param if it is defined on the decorator itself" do
         | 
| 233 233 | 
             
                    source.stub(:to_param).and_return(1)
         | 
| 234 234 | 
             
                    DecoratorWithSpecialMethods.new(source).to_param.should == "foo"
         | 
| 235 235 | 
             
                  end
         | 
| 236 236 |  | 
| 237 | 
            -
                  it " | 
| 237 | 
            +
                  it "never proxy id if it is defined on the decorator itself" do
         | 
| 238 238 | 
             
                    source.stub(:id).and_return(123456789)
         | 
| 239 239 | 
             
                    DecoratorWithSpecialMethods.new(source).id.should == 1337
         | 
| 240 240 | 
             
                  end
         | 
| 241 241 |  | 
| 242 | 
            -
                  it " | 
| 242 | 
            +
                  it "never proxy errors if it is defined on the decorator itself" do
         | 
| 243 243 | 
             
                    DecoratorWithSpecialMethods.new(source).errors.should be_an_instance_of Array
         | 
| 244 244 | 
             
                  end
         | 
| 245 245 | 
             
                end
         | 
| @@ -266,24 +266,24 @@ describe Draper::Base do | |
| 266 266 | 
             
                end
         | 
| 267 267 | 
             
              end
         | 
| 268 268 |  | 
| 269 | 
            -
              it " | 
| 269 | 
            +
              it "wrap source methods so they still accept blocks" do
         | 
| 270 270 | 
             
                subject.block{"marker"}.should == "marker"
         | 
| 271 271 | 
             
              end
         | 
| 272 272 |  | 
| 273 273 | 
             
              context ".find" do
         | 
| 274 | 
            -
                it " | 
| 274 | 
            +
                it "lookup the associated model when passed an integer" do
         | 
| 275 275 | 
             
                  pd = ProductDecorator.find(1)
         | 
| 276 276 | 
             
                  pd.should be_instance_of(ProductDecorator)
         | 
| 277 277 | 
             
                  pd.model.should be_instance_of(Product)
         | 
| 278 278 | 
             
                end
         | 
| 279 279 |  | 
| 280 | 
            -
                it " | 
| 280 | 
            +
                it "lookup the associated model when passed a string" do
         | 
| 281 281 | 
             
                  pd = ProductDecorator.find("1")
         | 
| 282 282 | 
             
                  pd.should be_instance_of(ProductDecorator)
         | 
| 283 283 | 
             
                  pd.model.should be_instance_of(Product)
         | 
| 284 284 | 
             
                end
         | 
| 285 285 |  | 
| 286 | 
            -
                it " | 
| 286 | 
            +
                it "accept and store a context" do
         | 
| 287 287 | 
             
                  pd = ProductDecorator.find(1, :context => :admin)
         | 
| 288 288 | 
             
                  pd.context.should == :admin
         | 
| 289 289 | 
             
                end
         | 
| @@ -453,14 +453,14 @@ describe Draper::Base do | |
| 453 453 | 
             
              end
         | 
| 454 454 |  | 
| 455 455 | 
             
              context('.==') do
         | 
| 456 | 
            -
                it " | 
| 456 | 
            +
                it "compare the decorated models" do
         | 
| 457 457 | 
             
                  other = Draper::Base.new(source)
         | 
| 458 458 | 
             
                  subject.should == other
         | 
| 459 459 | 
             
                end
         | 
| 460 460 | 
             
              end
         | 
| 461 461 |  | 
| 462 462 | 
             
              context ".respond_to?" do
         | 
| 463 | 
            -
                it " | 
| 463 | 
            +
                it "delegate respond_to? to the decorated model" do
         | 
| 464 464 | 
             
                  other = Draper::Base.new(source)
         | 
| 465 465 | 
             
                  source.should_receive(:respond_to?).with(:whatever, true)
         | 
| 466 466 | 
             
                  subject.respond_to?(:whatever, true)
         | 
| @@ -470,15 +470,15 @@ describe Draper::Base do | |
| 470 470 | 
             
              context 'position accessors' do
         | 
| 471 471 | 
             
                [:first, :last].each do |method|
         | 
| 472 472 | 
             
                  context "##{method}" do
         | 
| 473 | 
            -
                    it " | 
| 473 | 
            +
                    it "return a decorated instance" do
         | 
| 474 474 | 
             
                      ProductDecorator.send(method).should be_instance_of ProductDecorator
         | 
| 475 475 | 
             
                    end
         | 
| 476 476 |  | 
| 477 | 
            -
                    it " | 
| 477 | 
            +
                    it "return the #{method} instance of the wrapped class" do
         | 
| 478 478 | 
             
                      ProductDecorator.send(method).model.should == Product.send(method)
         | 
| 479 479 | 
             
                    end
         | 
| 480 480 |  | 
| 481 | 
            -
                    it " | 
| 481 | 
            +
                    it "accept an optional context" do
         | 
| 482 482 | 
             
                      ProductDecorator.send(method, :context => :admin).context.should == :admin
         | 
| 483 483 | 
             
                    end
         | 
| 484 484 | 
             
                  end
         | 
| @@ -499,32 +499,32 @@ describe Draper::Base do | |
| 499 499 | 
             
                let(:empty_collection) { [] }
         | 
| 500 500 | 
             
                subject { ProductDecorator.decorate(paged_array) }
         | 
| 501 501 |  | 
| 502 | 
            -
                it " | 
| 502 | 
            +
                it "proxy all calls to decorated collection" do
         | 
| 503 503 | 
             
                  paged_array.page_number.should == "magic_value"
         | 
| 504 504 | 
             
                  subject.page_number.should == "magic_value"
         | 
| 505 505 | 
             
                end
         | 
| 506 506 |  | 
| 507 | 
            -
                it " | 
| 507 | 
            +
                it "support Rails partial lookup for a collection" do
         | 
| 508 508 | 
             
                  # to support Rails render @collection the returned collection
         | 
| 509 509 | 
             
                  # (or its proxy) should implement #to_ary.
         | 
| 510 510 | 
             
                  subject.respond_to?(:to_ary).should be true
         | 
| 511 511 | 
             
                  subject.to_ary.first.should == ProductDecorator.decorate(paged_array.first)
         | 
| 512 512 | 
             
                end
         | 
| 513 513 |  | 
| 514 | 
            -
                it " | 
| 514 | 
            +
                it "delegate respond_to? to the wrapped collection" do
         | 
| 515 515 | 
             
                  decorator = ProductDecorator.decorate(paged_array)
         | 
| 516 516 | 
             
                  paged_array.should_receive(:respond_to?).with(:whatever, true)
         | 
| 517 517 | 
             
                  decorator.respond_to?(:whatever, true)
         | 
| 518 518 | 
             
                end
         | 
| 519 519 |  | 
| 520 | 
            -
                it " | 
| 520 | 
            +
                it "return blank for a decorated empty collection" do
         | 
| 521 521 | 
             
                  # This tests that respond_to? is defined for the DecoratedEnumerableProxy
         | 
| 522 522 | 
             
                  # since activesupport calls respond_to?(:empty) in #blank
         | 
| 523 523 | 
             
                  decorator = ProductDecorator.decorate(empty_collection)
         | 
| 524 524 | 
             
                  decorator.should be_blank
         | 
| 525 525 | 
             
                end
         | 
| 526 526 |  | 
| 527 | 
            -
                it " | 
| 527 | 
            +
                it "return whether the member is in the array for a decorated wrapped collection" do
         | 
| 528 528 | 
             
                  # This tests that include? is defined for the DecoratedEnumerableProxy
         | 
| 529 529 | 
             
                  member = paged_array.first
         | 
| 530 530 | 
             
                  subject.respond_to?(:include?)
         | 
| @@ -533,20 +533,20 @@ describe Draper::Base do | |
| 533 533 | 
             
                  subject.include?(Product.new).should == false
         | 
| 534 534 | 
             
                end
         | 
| 535 535 |  | 
| 536 | 
            -
                it " | 
| 536 | 
            +
                it "equal each other when decorating the same collection" do
         | 
| 537 537 | 
             
                  subject_one = ProductDecorator.decorate(paged_array)
         | 
| 538 538 | 
             
                  subject_two = ProductDecorator.decorate(paged_array)
         | 
| 539 539 | 
             
                  subject_one.should == subject_two
         | 
| 540 540 | 
             
                end
         | 
| 541 541 |  | 
| 542 | 
            -
                it " | 
| 542 | 
            +
                it "not equal each other when decorating different collections" do
         | 
| 543 543 | 
             
                  subject_one = ProductDecorator.decorate(paged_array)
         | 
| 544 544 | 
             
                  new_paged_array = paged_array + [Product.new]
         | 
| 545 545 | 
             
                  subject_two = ProductDecorator.decorate(new_paged_array)
         | 
| 546 546 | 
             
                  subject_one.should_not == subject_two
         | 
| 547 547 | 
             
                end
         | 
| 548 548 |  | 
| 549 | 
            -
                it " | 
| 549 | 
            +
                it "allow decorated access by index" do
         | 
| 550 550 | 
             
                  subject = ProductDecorator.decorate(paged_array)
         | 
| 551 551 | 
             
                  subject[0].should be_instance_of ProductDecorator
         | 
| 552 552 | 
             
                end
         | 
| @@ -572,18 +572,18 @@ describe Draper::Base do | |
| 572 572 | 
             
                end
         | 
| 573 573 |  | 
| 574 574 | 
             
                context '#all' do
         | 
| 575 | 
            -
                  it " | 
| 575 | 
            +
                  it "return a decorated collection" do
         | 
| 576 576 | 
             
                    ProductDecorator.all.first.should be_instance_of ProductDecorator
         | 
| 577 577 | 
             
                  end
         | 
| 578 578 |  | 
| 579 | 
            -
                  it " | 
| 579 | 
            +
                  it "accept a context" do
         | 
| 580 580 | 
             
                    collection = ProductDecorator.all(:context => :admin)
         | 
| 581 581 | 
             
                    collection.first.context.should == :admin
         | 
| 582 582 | 
             
                  end
         | 
| 583 583 | 
             
                end
         | 
| 584 584 |  | 
| 585 585 | 
             
                context(".source / .to_source") do
         | 
| 586 | 
            -
                  it " | 
| 586 | 
            +
                  it "return the wrapped object" do
         | 
| 587 587 | 
             
                    subject.to_source == source
         | 
| 588 588 | 
             
                    subject.source == source
         | 
| 589 589 | 
             
                  end
         | 
| @@ -593,19 +593,19 @@ describe Draper::Base do | |
| 593 593 | 
             
              describe "a sample usage with denies" do
         | 
| 594 594 | 
             
                let(:subject_with_denies){ DecoratorWithDenies.new(source) }
         | 
| 595 595 |  | 
| 596 | 
            -
                it " | 
| 596 | 
            +
                it "proxy methods not listed in denies" do
         | 
| 597 597 | 
             
                  subject_with_denies.should respond_to(:hello_world)
         | 
| 598 598 | 
             
                end
         | 
| 599 599 |  | 
| 600 | 
            -
                it " | 
| 600 | 
            +
                it "not echo methods specified with denies" do
         | 
| 601 601 | 
             
                  subject_with_denies.should_not respond_to(:goodnight_moon)
         | 
| 602 602 | 
             
                end
         | 
| 603 603 |  | 
| 604 | 
            -
                it " | 
| 604 | 
            +
                it "not clobber other decorators' methods" do
         | 
| 605 605 | 
             
                  subject.should respond_to(:hello_world)
         | 
| 606 606 | 
             
                end
         | 
| 607 607 |  | 
| 608 | 
            -
                it " | 
| 608 | 
            +
                it "not allow method_missing to circumvent a deny" do
         | 
| 609 609 | 
             
                  expect{subject_with_denies.title}.to raise_error(NoMethodError)
         | 
| 610 610 | 
             
                end
         | 
| 611 611 | 
             
              end
         | 
| @@ -615,20 +615,20 @@ describe Draper::Base do | |
| 615 615 |  | 
| 616 616 | 
             
                let(:subject_with_multiple_allows){ DecoratorWithMultipleAllows.new(source) }
         | 
| 617 617 |  | 
| 618 | 
            -
                it " | 
| 618 | 
            +
                it "echo the allowed method" do
         | 
| 619 619 | 
             
                  subject_with_allows.should respond_to(:goodnight_moon)
         | 
| 620 620 | 
             
                end
         | 
| 621 621 |  | 
| 622 | 
            -
                it " | 
| 622 | 
            +
                it "echo _only_ the allowed method" do
         | 
| 623 623 | 
             
                  subject_with_allows.should_not respond_to(:hello_world)
         | 
| 624 624 | 
             
                end
         | 
| 625 625 |  | 
| 626 | 
            -
                it " | 
| 626 | 
            +
                it "echo the combined allowed methods" do
         | 
| 627 627 | 
             
                  subject_with_multiple_allows.should respond_to(:goodnight_moon)
         | 
| 628 628 | 
             
                  subject_with_multiple_allows.should respond_to(:hello_world)
         | 
| 629 629 | 
             
                end
         | 
| 630 630 |  | 
| 631 | 
            -
                it " | 
| 631 | 
            +
                it "echo _only_ the combined allowed methods" do
         | 
| 632 632 | 
             
                  subject_with_multiple_allows.should_not respond_to(:title)
         | 
| 633 633 | 
             
                end
         | 
| 634 634 | 
             
              end
         | 
| @@ -660,19 +660,19 @@ describe Draper::Base do | |
| 660 660 | 
             
                  end
         | 
| 661 661 | 
             
                }
         | 
| 662 662 |  | 
| 663 | 
            -
                it " | 
| 663 | 
            +
                it "raise an exception for a blank allows" do
         | 
| 664 664 | 
             
                  expect {blank_allows}.should raise_error(ArgumentError)
         | 
| 665 665 | 
             
                end
         | 
| 666 666 |  | 
| 667 | 
            -
                it " | 
| 667 | 
            +
                it "raise an exception for a blank denies" do
         | 
| 668 668 | 
             
                  expect {blank_denies}.should raise_error(ArgumentError)
         | 
| 669 669 | 
             
                end
         | 
| 670 670 |  | 
| 671 | 
            -
                it " | 
| 671 | 
            +
                it "raise an exception for calling allows then denies" do
         | 
| 672 672 | 
             
                  expect {using_allows_then_denies}.should raise_error(ArgumentError)
         | 
| 673 673 | 
             
                end
         | 
| 674 674 |  | 
| 675 | 
            -
                it " | 
| 675 | 
            +
                it "raise an exception for calling denies then allows" do
         | 
| 676 676 | 
             
                  expect {using_denies_then_allows}.should raise_error(ArgumentError)
         | 
| 677 677 | 
             
                end
         | 
| 678 678 | 
             
              end
         | 
| @@ -680,23 +680,23 @@ describe Draper::Base do | |
| 680 680 | 
             
              context "in a Rails application" do
         | 
| 681 681 | 
             
                let(:decorator){ DecoratorWithApplicationHelper.decorate(Object.new) }
         | 
| 682 682 |  | 
| 683 | 
            -
                it " | 
| 683 | 
            +
                it "have access to ApplicationHelper helpers" do
         | 
| 684 684 | 
             
                  decorator.uses_hello_world == "Hello, World!"
         | 
| 685 685 | 
             
                end
         | 
| 686 686 |  | 
| 687 | 
            -
                it " | 
| 687 | 
            +
                it "is able to use the content_tag helper" do
         | 
| 688 688 | 
             
                  decorator.sample_content.to_s.should == "<span>Hello, World!</span>"
         | 
| 689 689 | 
             
                end
         | 
| 690 690 |  | 
| 691 | 
            -
                it " | 
| 691 | 
            +
                it "is able to use the link_to helper" do
         | 
| 692 692 | 
             
                  decorator.sample_link.should == "<a href=\"/World\">Hello</a>"
         | 
| 693 693 | 
             
                end
         | 
| 694 694 |  | 
| 695 | 
            -
                it " | 
| 695 | 
            +
                it "is able to use the pluralize helper" do
         | 
| 696 696 | 
             
                  decorator.sample_truncate.should == "Once..."
         | 
| 697 697 | 
             
                end
         | 
| 698 698 |  | 
| 699 | 
            -
                it " | 
| 699 | 
            +
                it "is able to use l rather than helpers.l" do
         | 
| 700 700 | 
             
                  now = Time.now
         | 
| 701 701 | 
             
                  decorator.helpers.should_receive(:localize).with(now)
         | 
| 702 702 | 
             
                  decorator.l now
         | 
| @@ -7,12 +7,12 @@ describe Draper::ActiveModelSupport do | |
| 7 7 | 
             
                its(:decorator) { should be_kind_of(ProductDecorator) }
         | 
| 8 8 | 
             
                its(:decorator) { should be(subject.decorator) }
         | 
| 9 9 |  | 
| 10 | 
            -
                it ' | 
| 10 | 
            +
                it 'have abillity to pass block' do
         | 
| 11 11 | 
             
                  a = Product.new.decorator { |d| d.awesome_title }
         | 
| 12 12 | 
             
                  a.should eql "Awesome Title"
         | 
| 13 13 | 
             
                end
         | 
| 14 14 |  | 
| 15 | 
            -
                it ' | 
| 15 | 
            +
                it 'is aliased to .decorate' do
         | 
| 16 16 | 
             
                  subject.decorator.model.should == subject.decorate.model
         | 
| 17 17 | 
             
                end
         | 
| 18 18 | 
             
              end
         | 
| @@ -23,12 +23,12 @@ describe Draper::ActiveModelSupport do | |
| 23 23 |  | 
| 24 24 | 
             
                  its(:decorate) { should be_kind_of(Draper::DecoratedEnumerableProxy) }
         | 
| 25 25 |  | 
| 26 | 
            -
                  it " | 
| 26 | 
            +
                  it "decorate the collection" do
         | 
| 27 27 | 
             
                    subject.decorate.size.should == 1
         | 
| 28 28 | 
             
                    subject.decorate.to_ary[0].model.should be_a(klass)
         | 
| 29 29 | 
             
                  end
         | 
| 30 30 |  | 
| 31 | 
            -
                  it " | 
| 31 | 
            +
                  it "return a new instance each time it is called" do
         | 
| 32 32 | 
             
                    subject.decorate.should_not == subject.decorate
         | 
| 33 33 | 
             
                  end
         | 
| 34 34 | 
             
                end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: draper
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 39
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 | 
            -
              -  | 
| 8 | 
            +
              - 14
         | 
| 9 9 | 
             
              - 0
         | 
| 10 | 
            -
              version: 0. | 
| 10 | 
            +
              version: 0.14.0
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Jeff Casimir
         | 
| @@ -16,7 +16,7 @@ autorequire: | |
| 16 16 | 
             
            bindir: bin
         | 
| 17 17 | 
             
            cert_chain: []
         | 
| 18 18 |  | 
| 19 | 
            -
            date: 2012-05- | 
| 19 | 
            +
            date: 2012-05-17 00:00:00 Z
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 22 22 | 
             
              name: activesupport
         | 
| @@ -34,112 +34,111 @@ dependencies: | |
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              version_requirements: *id001
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 37 | 
            -
              name:  | 
| 37 | 
            +
              name: actionpack
         | 
| 38 38 | 
             
              prerelease: false
         | 
| 39 39 | 
             
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 40 40 | 
             
                none: false
         | 
| 41 41 | 
             
                requirements: 
         | 
| 42 42 | 
             
                - - ~>
         | 
| 43 43 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 44 | 
            -
                    hash:  | 
| 44 | 
            +
                    hash: 3
         | 
| 45 45 | 
             
                    segments: 
         | 
| 46 | 
            -
                    -  | 
| 47 | 
            -
                    - 9
         | 
| 46 | 
            +
                    - 3
         | 
| 48 47 | 
             
                    - 2
         | 
| 49 | 
            -
                    version:  | 
| 48 | 
            +
                    version: "3.2"
         | 
| 50 49 | 
             
              type: :runtime
         | 
| 51 50 | 
             
              version_requirements: *id002
         | 
| 52 51 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 53 | 
            -
              name:  | 
| 52 | 
            +
              name: ammeter
         | 
| 54 53 | 
             
              prerelease: false
         | 
| 55 54 | 
             
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 56 55 | 
             
                none: false
         | 
| 57 56 | 
             
                requirements: 
         | 
| 58 57 | 
             
                - - ~>
         | 
| 59 58 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 60 | 
            -
                    hash:  | 
| 59 | 
            +
                    hash: 19
         | 
| 61 60 | 
             
                    segments: 
         | 
| 61 | 
            +
                    - 0
         | 
| 62 62 | 
             
                    - 2
         | 
| 63 | 
            -
                    -  | 
| 64 | 
            -
                    version:  | 
| 65 | 
            -
              type: : | 
| 63 | 
            +
                    - 2
         | 
| 64 | 
            +
                    version: 0.2.2
         | 
| 65 | 
            +
              type: :development
         | 
| 66 66 | 
             
              version_requirements: *id003
         | 
| 67 67 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 68 | 
            -
              name:  | 
| 68 | 
            +
              name: guard
         | 
| 69 69 | 
             
              prerelease: false
         | 
| 70 70 | 
             
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 71 71 | 
             
                none: false
         | 
| 72 72 | 
             
                requirements: 
         | 
| 73 | 
            -
                - -  | 
| 73 | 
            +
                - - ">="
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 75 75 | 
             
                    hash: 3
         | 
| 76 76 | 
             
                    segments: 
         | 
| 77 | 
            -
                    -  | 
| 78 | 
            -
                     | 
| 79 | 
            -
             | 
| 80 | 
            -
              type: :runtime
         | 
| 77 | 
            +
                    - 0
         | 
| 78 | 
            +
                    version: "0"
         | 
| 79 | 
            +
              type: :development
         | 
| 81 80 | 
             
              version_requirements: *id004
         | 
| 82 81 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 83 | 
            -
              name:  | 
| 82 | 
            +
              name: guard-rspec
         | 
| 84 83 | 
             
              prerelease: false
         | 
| 85 84 | 
             
              requirement: &id005 !ruby/object:Gem::Requirement 
         | 
| 86 85 | 
             
                none: false
         | 
| 87 86 | 
             
                requirements: 
         | 
| 88 | 
            -
                - -  | 
| 87 | 
            +
                - - ">="
         | 
| 89 88 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 90 89 | 
             
                    hash: 3
         | 
| 91 90 | 
             
                    segments: 
         | 
| 92 | 
            -
                    -  | 
| 93 | 
            -
                     | 
| 94 | 
            -
             | 
| 95 | 
            -
              type: :runtime
         | 
| 91 | 
            +
                    - 0
         | 
| 92 | 
            +
                    version: "0"
         | 
| 93 | 
            +
              type: :development
         | 
| 96 94 | 
             
              version_requirements: *id005
         | 
| 97 95 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 98 | 
            -
              name:  | 
| 96 | 
            +
              name: launchy
         | 
| 99 97 | 
             
              prerelease: false
         | 
| 100 98 | 
             
              requirement: &id006 !ruby/object:Gem::Requirement 
         | 
| 101 99 | 
             
                none: false
         | 
| 102 100 | 
             
                requirements: 
         | 
| 103 | 
            -
                - -  | 
| 101 | 
            +
                - - ">="
         | 
| 104 102 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 105 | 
            -
                    hash:  | 
| 103 | 
            +
                    hash: 3
         | 
| 106 104 | 
             
                    segments: 
         | 
| 107 105 | 
             
                    - 0
         | 
| 108 | 
            -
                     | 
| 109 | 
            -
                    - 2
         | 
| 110 | 
            -
                    version: 0.2.2
         | 
| 106 | 
            +
                    version: "0"
         | 
| 111 107 | 
             
              type: :development
         | 
| 112 108 | 
             
              version_requirements: *id006
         | 
| 113 109 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 114 | 
            -
              name:  | 
| 110 | 
            +
              name: rake
         | 
| 115 111 | 
             
              prerelease: false
         | 
| 116 112 | 
             
              requirement: &id007 !ruby/object:Gem::Requirement 
         | 
| 117 113 | 
             
                none: false
         | 
| 118 114 | 
             
                requirements: 
         | 
| 119 | 
            -
                - -  | 
| 115 | 
            +
                - - ~>
         | 
| 120 116 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 121 | 
            -
                    hash:  | 
| 117 | 
            +
                    hash: 63
         | 
| 122 118 | 
             
                    segments: 
         | 
| 123 119 | 
             
                    - 0
         | 
| 124 | 
            -
                     | 
| 120 | 
            +
                    - 9
         | 
| 121 | 
            +
                    - 2
         | 
| 122 | 
            +
                    version: 0.9.2
         | 
| 125 123 | 
             
              type: :development
         | 
| 126 124 | 
             
              version_requirements: *id007
         | 
| 127 125 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 128 | 
            -
              name:  | 
| 126 | 
            +
              name: rspec
         | 
| 129 127 | 
             
              prerelease: false
         | 
| 130 128 | 
             
              requirement: &id008 !ruby/object:Gem::Requirement 
         | 
| 131 129 | 
             
                none: false
         | 
| 132 130 | 
             
                requirements: 
         | 
| 133 | 
            -
                - -  | 
| 131 | 
            +
                - - ~>
         | 
| 134 132 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 135 | 
            -
                    hash:  | 
| 133 | 
            +
                    hash: 23
         | 
| 136 134 | 
             
                    segments: 
         | 
| 137 | 
            -
                    -  | 
| 138 | 
            -
                     | 
| 135 | 
            +
                    - 2
         | 
| 136 | 
            +
                    - 10
         | 
| 137 | 
            +
                    version: "2.10"
         | 
| 139 138 | 
             
              type: :development
         | 
| 140 139 | 
             
              version_requirements: *id008
         | 
| 141 140 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 142 | 
            -
              name:  | 
| 141 | 
            +
              name: yard
         | 
| 143 142 | 
             
              prerelease: false
         | 
| 144 143 | 
             
              requirement: &id009 !ruby/object:Gem::Requirement 
         | 
| 145 144 | 
             
                none: false
         | 
| @@ -152,20 +151,6 @@ dependencies: | |
| 152 151 | 
             
                    version: "0"
         | 
| 153 152 | 
             
              type: :development
         | 
| 154 153 | 
             
              version_requirements: *id009
         | 
| 155 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 156 | 
            -
              name: yard
         | 
| 157 | 
            -
              prerelease: false
         | 
| 158 | 
            -
              requirement: &id010 !ruby/object:Gem::Requirement 
         | 
| 159 | 
            -
                none: false
         | 
| 160 | 
            -
                requirements: 
         | 
| 161 | 
            -
                - - ">="
         | 
| 162 | 
            -
                  - !ruby/object:Gem::Version 
         | 
| 163 | 
            -
                    hash: 3
         | 
| 164 | 
            -
                    segments: 
         | 
| 165 | 
            -
                    - 0
         | 
| 166 | 
            -
                    version: "0"
         | 
| 167 | 
            -
              type: :development
         | 
| 168 | 
            -
              version_requirements: *id010
         | 
| 169 154 | 
             
            description: Draper implements a decorator or presenter pattern for Rails applications.
         | 
| 170 155 | 
             
            email: 
         | 
| 171 156 | 
             
            - jeff@casimircreative.com
         | 
| @@ -286,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 286 271 | 
             
            requirements: []
         | 
| 287 272 |  | 
| 288 273 | 
             
            rubyforge_project: draper
         | 
| 289 | 
            -
            rubygems_version: 1.8. | 
| 274 | 
            +
            rubygems_version: 1.8.15
         | 
| 290 275 | 
             
            signing_key: 
         | 
| 291 276 | 
             
            specification_version: 3
         | 
| 292 277 | 
             
            summary: Decorator pattern implementation for Rails.
         |