Permalink
Browse files

Add more use cases to the using modules integration spec

  • Loading branch information...
1 parent 6f5924e commit 8f3c2a642fec1f07cbd23c61ceb942f8588d8b1a @solnic committed Jun 4, 2012
Showing with 12 additions and 6 deletions.
  1. +12 −6 spec/integration/using_modules_spec.rb
@@ -3,38 +3,44 @@
describe 'I can define attributes within a module' do
before do
module Examples
- module Base
+ module Name
include Virtus
attribute :name, String
+ end
+
+ module Age
+ include Virtus
+
attribute :age, Integer
end
class User
- include Base
+ include Name
end
- class Admin < User; end
+ class Admin < User
+ include Age
+ end
class Moderator; end
end
end
specify 'including a module with attributes into a class' do
Examples::User.attributes[:name].should be_instance_of(Virtus::Attribute::String)
- Examples::User.attributes[:age].should be_instance_of(Virtus::Attribute::Integer)
Examples::Admin.attributes[:name].should be_instance_of(Virtus::Attribute::String)
Examples::Admin.attributes[:age].should be_instance_of(Virtus::Attribute::Integer)
- user = Examples::User.new(:name => 'Piotr', :age => 29)
+ user = Examples::Admin.new(:name => 'Piotr', :age => 29)
user.name.should eql('Piotr')
user.age.should eql(29)
end
specify 'including a module with attributes into an instance' do
moderator = Examples::Moderator.new
- moderator.extend(Examples::Base)
+ moderator.extend(Examples::Name, Examples::Age)
moderator.attributes = { :name => 'John', :age => 21 }
moderator.name.should eql('John')

0 comments on commit 8f3c2a6

Please sign in to comment.