Sha256: 0b5da3d2d2780df49a9795605669db8a562441f26a547923a5f407834d69158a

Contents?: true

Size: 939 Bytes

Versions: 18

Compression:

Stored size: 939 Bytes

Contents

require 'spec_helper'

describe "Defining a ValueObject with a custom constructor" do
  before do
    module Examples
      class Point
        include Virtus::ValueObject

        attribute :x, Integer
        attribute :y, Integer

        def initialize(attributes)
          if attributes.kind_of?(Array)
            self.x = attributes.first
            self.y = attributes.last
          else
            super
          end
        end
      end

      class Rectangle
        include Virtus

        attribute :top_left,     Point
        attribute :bottom_right, Point
      end
    end
  end

  subject do
    Examples::Rectangle.new(:top_left => [ 3, 4 ], :bottom_right => [ 5, 8 ])
  end

  specify "initialize a value object attribute with correct attributes" do
    subject.top_left.x.should be(3)
    subject.top_left.y.should be(4)

    subject.bottom_right.x.should be(5)
    subject.bottom_right.y.should be(8)
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

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