spec/unit/virtus/model_spec.rb in virtus-1.0.0.beta8 vs spec/unit/virtus/model_spec.rb in virtus-1.0.0.rc1
- old
+ new
@@ -8,11 +8,11 @@
end
end
share_examples_for 'a model with mass-assignment' do
let(:attributes) do
- { :name => 'Jane' }
+ { :name => 'Jane', :something => nil }
end
before do
instance.attributes = attributes
end
@@ -30,31 +30,63 @@
context 'with default configuration' do
let(:mod) { Virtus.model }
context 'with a class' do
- subject { Class.new }
+ let(:model) { Class.new }
+ subject { model }
+
before do
subject.send(:include, mod)
- subject.attribute :name
+ subject.attribute :name, String, :default => 'Jane'
+ subject.attribute :something
end
it_behaves_like 'a model with constructor'
it_behaves_like 'a model with strict mode turned off'
it_behaves_like 'a model with mass-assignment' do
let(:instance) { subject.new }
end
+
+ it 'defaults to Object for attribute type' do
+ expect(model.attribute_set[:something].type).to be(Axiom::Types::Object)
+ end
+
+ context 'with a sub-class' do
+ subject { Class.new(model) }
+
+ before do
+ subject.attribute :age, Integer
+ end
+
+ it_behaves_like 'a model with constructor'
+
+ it_behaves_like 'a model with strict mode turned off'
+
+ it_behaves_like 'a model with mass-assignment' do
+ let(:instance) { subject.new }
+
+ let(:attributes) {
+ { :name => 'Jane', :something => nil, :age => 23 }
+ }
+ end
+
+ it 'has its own attributes' do
+ expect(subject.attribute_set[:age]).to be_kind_of(Virtus::Attribute)
+ end
+ end
end
context 'with an instance' do
subject { Class.new.new }
before do
subject.extend(mod)
subject.attribute :name, String
+ subject.attribute :something
end
it_behaves_like 'a model with strict mode turned off'
it_behaves_like 'a model with mass-assignment' do