Permalink
Browse files

spec to illustrate default values based on private attributes (#32)

  • Loading branch information...
1 parent 64c7eae commit abdce3998fb975efbe937116028bdc9c1bdfeff0 @senny committed Nov 14, 2011
Showing with 29 additions and 3 deletions.
  1. +29 −3 examples/default_values_spec.rb
@@ -3,9 +3,19 @@
class Page
include Virtus
- attribute :title, String
- attribute :slug, String, :default => lambda { |post, attribute| post.title.downcase.gsub(' ', '-') }
- attribute :view_count, Integer, :default => 0
+ attribute :title, String
+ attribute :slug, String, :default => lambda { |post, attribute| post.title.downcase.gsub(' ', '-') }
+ attribute :view_count, Integer, :default => 0
+ attribute :secret, Boolean
+
+ attribute :published, Boolean, :accessor => :private
+ attribute :editor_title, String, :default => lambda { |post, attribute|
+ post.published? ? post.title : "UNPUBLISHED: #{post.title}"
+ }
+
+ def initialize(published = false)
+ @published = published
+ end
end
describe Page do
@@ -18,4 +28,20 @@ class Page
describe '#views_count' do
its(:view_count) { should eql(0) }
end
+
+ describe '#editor_title' do
+ before { subject.title = 'Truly Awesome' }
+
+ context 'published page' do
+ subject { Page.new(true) }
+
+ its(:editor_title) { should eql('Truly Awesome') }
+ end
+
+ context 'unpublished page' do
+ subject { Page.new(false) }
+
+ its(:editor_title) { should eql('UNPUBLISHED: Truly Awesome') }
+ end
+ end
end

0 comments on commit abdce39

Please sign in to comment.