Permalink
Browse files

Merge branch 'master' into 98_hash_attributes_coercion

  • Loading branch information...
2 parents 01922f8 + d1d6bcc commit 4ec401034c6e06ff08a1399922e81b276750dfe1 @solnic committed Oct 1, 2012
@@ -15,6 +15,7 @@ class Attribute
class Array < Collection
primitive ::Array
coercion_method :to_array
+ default primitive.new
include Collection::MemberCoercion
@@ -7,7 +7,7 @@ class Attribute
# class Entity
# include Virtus
#
- # attribute :type, Class
+ # attribute :model, Class
# end
#
# post = Entity.new(:model => Model)
@@ -15,6 +15,7 @@ class Attribute
class Hash < Object
primitive ::Hash
coercion_method :to_hash
+ default primitive.new
# The type to which keys of this hash will be coerced
#
@@ -15,6 +15,7 @@ class Attribute
class Set < Collection
primitive ::Set
coercion_method :to_set
+ default primitive.new
include Collection::MemberCoercion
@@ -20,6 +20,9 @@ class Page
attribute :published, Boolean, :default => false, :accessor => :private
attribute :editor_title, String, :default => :default_editor_title
attribute :reference, String, :default => Reference.new
+ attribute :revisions, Array
+ attribute :index, Hash
+ attribute :authors, Set
def default_editor_title
published? ? title : "UNPUBLISHED: #{title}"
@@ -49,12 +52,29 @@ def default_editor_title
subject.editor_title.should == 'UNPUBLISHED: Top Secret'
end
- context 'with a ValueObject' do
- it 'should not duplicate the ValueObject' do
+ context 'a ValueObject' do
+ it 'does not duplicate the ValueObject' do
page1 = Examples::Page.new
page2 = Examples::Page.new
page1.reference.should equal(page2.reference)
end
end
+ context 'an Array' do
+ specify 'without a default the value is an empty Array' do
+ subject.revisions.should eql([])
+ end
+ end
+
+ context 'a Hash' do
+ specify 'without a default the value is an empty Hash' do
+ subject.index.should eql({})
+ end
+ end
+
+ context 'a Set' do
+ specify 'without a default the value is an empty Set' do
+ subject.authors.should eql(Set.new)
+ end
+ end
end
@@ -1,6 +1,6 @@
shared_examples_for 'a #freeze method' do
let(:sample_exception) do
- begin
+ begin
object.dup.freeze.instance_variable_set(:@foo,:bar)
rescue => exception
exception

0 comments on commit 4ec4010

Please sign in to comment.