# frozen_string_literal: true require 'spec_helper' RSpec.describe 'Updating existing objects with .parse and #parse', type: :feature do let(:root) { ParseInstanceSpec::Root.parse(parse_instance_initial_xml) } let(:parse_instance_initial_xml) do %( initial initial initial initial initial initial ) end let(:parse_instance_updated_xml) do %( updated updated updated updated updated updated ) end module ParseInstanceSpec class SubItem include HappyMapper tag 'subitem' attribute :attr1, String element :name, String end class Item include HappyMapper tag 'item' attribute :attr1, String element :description, String has_many :sub_items, SubItem end class Root include HappyMapper tag 'root' attribute :attr1, String has_many :items, Item end end def item_is_correctly_defined(item, value = 'initial') expect(item.attr1).to eq value expect(item.description).to eq value expect(item.sub_items[0].attr1).to eq value expect(item.sub_items[0].name).to eq value expect(item.sub_items[1].attr1).to eq value expect(item.sub_items[1].name).to eq value end it 'initial values are correct' do aggregate_failures do expect(root.attr1).to eq('initial') item_is_correctly_defined(root.items[0]) item_is_correctly_defined(root.items[1]) end end describe '.parse', 'specifying an existing object to update' do it 'all fields are correct' do ParseInstanceSpec::Root.parse(parse_instance_updated_xml, update: root) aggregate_failures do expect(root.attr1).to eq 'updated' item_is_correctly_defined(root.items[0], 'updated') item_is_correctly_defined(root.items[1], 'updated') end end end describe '#parse' do it 'all fields are correct' do root.parse(parse_instance_updated_xml) aggregate_failures do expect(root.attr1).to eq 'updated' item_is_correctly_defined(root.items[0], 'updated') item_is_correctly_defined(root.items[1], 'updated') end end end end