spec/integration/default_values_spec.rb in virtus-0.5.2 vs spec/integration/default_values_spec.rb in virtus-0.5.3
- old
+ new
@@ -18,10 +18,13 @@
attribute :slug, String, :default => lambda { |post, attribute| post.title.downcase.gsub(' ', '-') }
attribute :view_count, Integer, :default => 0
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}"
end
end
@@ -47,14 +50,31 @@
specify 'you can set defaults for private attributes' do
subject.title = 'Top Secret'
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