spec/schema_spec.rb in parametric-0.2.18 vs spec/schema_spec.rb in parametric-0.2.19

- old
+ new

@@ -305,9 +305,32 @@ result = schema.resolve(type: 'user', sub: { name: 'Joe', age: 30 }) expect(result.valid?).to be true expect(result.output).to eq({ type: 'user', sub: { name: 'Joe', age: 30 } }) end + + specify '#structure' do + user_or_company = Parametric::TaggedOneOf.new do |sub| + sub.on('user', user_schema) + sub.on('company', company_schema) + end + + schema = described_class.new do |sc, _| + sc.field(:type).type(:string) + sc.field(:sub).type(:object).tagged_one_of(user_or_company.index_by(:type)) + end + + structure = schema.structure + structure.dig(:sub).tap do |sub| + expect(sub[:type]).to eq :object + expect(sub[:one_of][0][:name][:type]).to eq :string + expect(sub[:one_of][0][:name][:required]).to be true + expect(sub[:one_of][0][:name][:present]).to be true + expect(sub[:one_of][0][:age][:type]).to eq :integer + + expect(sub[:one_of][1][:company_code][:type]).to eq :string + end + end end describe "#ignore" do it "ignores fields" do s1 = described_class.new.ignore(:title, :status) do