test/virtualbox/abstract_model/attributable_test.rb in virtualbox-0.6.0 vs test/virtualbox/abstract_model/attributable_test.rb in virtualbox-0.6.1
- old
+ new
@@ -25,9 +25,43 @@
assert attributes.has_key?(:bar)
assert attributes.has_key?(:baz)
end
end
+ context "attribute scopes" do
+ class AttributeScopeA < EmptyAttributeModel
+ attribute :foo
+ attribute_scope(:bar => 7) do
+ attribute :foo2
+
+ attribute_scope(:baz => 3) do
+ attribute :bazzed
+ end
+ end
+
+ attribute :foo3, :bar => 10
+ end
+
+ setup do
+ @klass = AttributeScopeA
+ end
+
+ should "use attribute scope" do
+ assert_equal 7, @klass.attributes[:foo2][:bar]
+ end
+
+ should "not use attribute scope outside of the block" do
+ assert !@klass.attributes[:foo].has_key?(:bar)
+ assert_equal 10, @klass.attributes[:foo3][:bar]
+ end
+
+ should "properly nest" do
+ bazzed = @klass.attributes[:bazzed]
+ assert_equal 3, bazzed[:baz]
+ assert_equal 7, bazzed[:bar]
+ end
+ end
+
context "attribute options" do
context "custom populate keys" do
class CustomPopulateModel < AttributeModel
attribute :foo, :populate_key => :foo_key
end
\ No newline at end of file