spec/object_spec.rb in strong_json-0.5.0 vs spec/object_spec.rb in strong_json-0.6.0
- old
+ new
@@ -63,9 +63,21 @@
it "overrides field" do
ty2 = type.merge(a: StrongJSON::Type::Base.new(:prohibited))
expect{ ty2.coerce(a: 123) }.to raise_error(StrongJSON::Type::Error)
end
+
+ it "adds field via object" do
+ ty2 = type.merge(StrongJSON::Type::Object.new(b: StrongJSON::Type::Base.new(:string)))
+
+ expect(ty2.coerce(a: 123, b: "test")).to eq(a: 123, b: "test")
+ end
+
+ it "overrides field via object" do
+ ty2 = type.merge(StrongJSON::Type::Object.new(a: StrongJSON::Type::Base.new(:prohibited)))
+
+ expect{ ty2.coerce(a: 123) }.to raise_error(StrongJSON::Type::Error)
+ end
end
describe "#except" do
let (:type) { StrongJSON::Type::Object.new(a: StrongJSON::Type::Base.new(:numeric), b: StrongJSON::Type::Base.new(:string)) }