Sha256: f5f66c218be29dc00af334856ae23bbe880c536eb521f15e7c883b67f9b6c42b

Contents?: true

Size: 1.17 KB

Versions: 24

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'

describe 'overriding virtus behavior' do

  before do
    module Examples
      class Article
        include Virtus

        attribute :title, String

        def title
          super || '<unknown>'
        end

        def title=(name)
          super unless self.title == "can't be changed"
        end
      end
    end
  end

  describe 'overriding an attribute getter' do
    specify 'calls the defined getter' do
      Examples::Article.new.title.should == '<unknown>'
    end

    specify 'super can be used to access the getter defined by virtus' do
      Examples::Article.new(:title => 'example article').title.should == 'example article'
    end
  end

  describe 'overriding an attribute setter' do
    specify 'calls the defined setter' do
      article = Examples::Article.new(:title => "can't be changed")
      article.title = 'this will never be assigned'
      article.title.should == "can't be changed"
    end

    specify 'super can be used to access the setter defined by virtus' do
      article = Examples::Article.new(:title => 'example article')
      article.title = 'my new title'
      article.title.should == 'my new title'
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
virtus-1.0.2 spec/integration/overriding_virtus_spec.rb
virtus-1.0.1 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.rc2 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.rc1 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.beta8 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.beta7 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.beta6 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.beta5 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.beta4 spec/integration/overriding_virtus_spec.rb
virtus-1.0.0.beta3 spec/integration/overriding_virtus_spec.rb
virtus-0.5.5 spec/integration/overriding_virtus_spec.rb
virtus-0.5.4 spec/integration/overriding_virtus_spec.rb
virtus-0.5.3 spec/integration/overriding_virtus_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/integration/overriding_virtus_spec.rb
virtus-0.5.2 spec/integration/overriding_virtus_spec.rb
virtus-0.5.1 spec/integration/overriding_virtus_spec.rb
virtus-0.5.0 spec/integration/overriding_virtus_spec.rb
virtus-0.4.2 spec/integration/overriding_virtus_spec.rb
virtus-0.4.1 spec/integration/overriding_virtus_spec.rb