Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from senny/make_attribute_methods_overridable
allow to override attribute setters/getters
- Loading branch information
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require './spec/spec_helper' | ||
|
||
class Article | ||
include Virtus | ||
|
||
attribute :author, String | ||
|
||
def author | ||
super || '<unknown>' | ||
end | ||
|
||
def author=(name) | ||
super unless name == 'Brad' | ||
end | ||
|
||
end | ||
|
||
describe Article, 'override' do | ||
|
||
it 'Alice is an allowed author' do | ||
Article.new(:author => 'Alice').author.should == 'Alice' | ||
end | ||
|
||
it 'Brad isn not an allowed author' do | ||
Article.new(:author => 'Brad').author.should == '<unknown>' | ||
end | ||
|
||
context 'with author' do | ||
subject { Article.new(:author => 'John') } | ||
|
||
its(:author) { should == 'John' } | ||
end | ||
|
||
context 'without author' do | ||
subject { Article.new } | ||
|
||
its(:author) { should == '<unknown>' } | ||
end | ||
|
||
end |
This file contains 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