Created
January 8, 2012 18:54
-
-
Save senny/1579301 to your computer and use it in GitHub Desktop.
example virtus integration spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'integration/spec_helper' | |
class Article | |
include Virtus | |
attribute :title, String | |
def title | |
super || '<unknown>' | |
end | |
def title=(name) | |
super unless self.title == "can't be changed" | |
end | |
end | |
describe 'overriding an attribute getter' do | |
specify 'calls the defined getter' do | |
Article.new.title.should == '<unknown>' | |
end | |
specify 'super can be used to access the getter defined by virtus' do | |
Article.new(:title => 'example article').author.should == 'example article' | |
end | |
end | |
describe 'overriding an attribute setter' do | |
specify 'calls the defined setter' do | |
article = Article.new(:title => "can't be changed") | |
subject.title = 'this will never be assigned' | |
subject.title.should == "can't be changed" | |
end | |
specify 'super can be used to access the setter defined by virtus' do | |
article = Article.new(:title => 'example article') | |
article.title = 'my new title' | |
article.title.should == 'my new title' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment