spec/struct_spec.rb in paradocs-1.1.3 vs spec/struct_spec.rb in paradocs-1.1.4
- old
+ new
@@ -14,17 +14,17 @@
klass = Class.new do
include Paradocs::Struct
schema do
- field(:title).type(:string).present
+ field(:title).type(:string).present.as(:example_title)
field(:friends).type(:array).default([]).schema friend_class
end
end
new_instance = klass.new
- expect(new_instance.title).to eq ''
+ expect(new_instance.example_title).to eq ''
expect(new_instance.friends).to eq []
expect(new_instance.valid?).to be false
expect(new_instance.errors['$.title']).not_to be_nil
instance = klass.new({
@@ -33,11 +33,11 @@
{name: 'Ismael', age: 40},
{name: 'Joe', age: 39},
]
})
- expect(instance.title).to eq 'foo'
+ expect(instance.example_title).to eq 'foo'
expect(instance.friends.size).to eq 2
expect(instance.friends.first.name).to eq 'Ismael'
expect(instance.friends.first).to be_a friend_class
invalid_instance = klass.new({
@@ -152,11 +152,11 @@
include Paradocs::Struct
schema do
field(:title).type(:string).present
field(:friends).type(:array).schema do
- field(:name).type(:string)
+ field(:name).type(:string).as(:person_name)
field(:age).type(:integer).default(20)
end
end
end
@@ -169,12 +169,12 @@
})
expect(instance.to_h).to eq({
title: 'foo',
friends: [
- {name: 'Jane', age: 20},
- {name: 'Joe', age: 39},
+ {person_name: 'Jane', age: 20},
+ {person_name: 'Joe', age: 39},
]
})
new_instance = klass.new(instance.to_h)
expect(new_instance.title).to eq 'foo'
@@ -188,11 +188,11 @@
it 'works with inheritance' do
klass = Class.new do
include Paradocs::Struct
schema do
- field(:title).type(:string).present
+ field(:title).type(:string).present.as(:example_title)
field(:friends).type(:array).schema do
field(:name).type(:string)
field(:age).type(:integer).default(20)
end
end
@@ -211,10 +211,10 @@
{name: 'Jane', age: 20},
{name: 'Joe', age: 39},
]
)
- expect(instance.title).to eq 'foo'
+ expect(instance.example_title).to eq 'foo'
expect(instance.email).to eq 'email@me.com'
expect(instance.friends.size).to eq 2
end
it 'implements deep struct equality' do