Sha256: a91e6329297703c25164a7fdf95951968e7ef464653dcf267924c2d1287d69cd

Contents?: true

Size: 1011 Bytes

Versions: 22

Compression:

Stored size: 1011 Bytes

Contents

require 'spec_helper'

describe "mass assignment with accessors" do

  before do
    module Examples
      class Product
        include Virtus

        attribute :id,          Integer
        attribute :category,    String
        attribute :subcategory, String

        def categories=(categories)
          self.category = categories.first
          self.subcategory = categories.last
        end

      private

        def _id=(value)
          self.id = value
        end
      end
    end
  end

  subject { Examples::Product.new(:categories => ['Office', 'Printers'], :_id => 100) }

  specify 'works uppon instantiation' do
    subject.category.should == 'Office'
    subject.subcategory.should == 'Printers'
  end

  specify 'can be set with #attributes=' do
    subject.attributes = {:categories => ['Home', 'Furniture']}
    subject.category.should == 'Home'
    subject.subcategory.should == 'Furniture'
  end

  specify 'respects accessor visibility' do
    subject.id.should_not == 100
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

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