Sha256: 34490d712a31a93d203868f98112767d865a0b73327937b4c297658ad5bbbdf9

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

require 'spec_helper'

describe "default values" do

  before do
    module Examples
      class Page
        include Virtus

        attribute :title,      String
        attribute :slug,       String,  :default => lambda { |post, attribute| post.title.downcase.gsub(' ', '-') }
        attribute :view_count, Integer, :default => 0
      end
    end
  end

  subject { Examples::Page.new }

  specify 'without a default the value is nil' do
    subject.title.should be_nil
  end

  specify 'can be supplied with the :default option' do
    subject.view_count.should == 0
  end

  specify "you can pass a 'callable-object' to the :default option" do
    subject.title = 'Example Blog Post'
    subject.slug.should == 'example-blog-post'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
virtus-0.2.0 spec/integration/default_values_spec.rb
virtus-0.1.0 spec/integration/default_values_spec.rb