Sha256: d40cefa9a804abd8bcfb84207b26719db0a8c8f55e78e074976a022363fbd9ea

Contents?: true

Size: 814 Bytes

Versions: 2

Compression:

Stored size: 814 Bytes

Contents

require 'integration_spec_helper'

describe ActiverecordToPoro::MetadataEnabledAr do
  subject{
    User.send(:include, ActiverecordToPoro::MetadataEnabledAr)
    User
  }

  let(:ar_object){
    User.create!(name: 'my name', email: 'my_name@example.com')
  }

  let(:metadata){
    ActiverecordToPoro::Metadata.new.tap do |meta|
      meta.initialize_from_ar(ar_object)
    end
  }

  describe '._from_attrs_with_metadata' do
    it 'loads a record from db' do
      new_user = subject._from_attrs_with_metadata({_set_metadata_to_ar: metadata })
      expect(new_user.new_record?).to be_falsy
    end

    it 'uses a precreated object' do
      new_user = subject._from_attrs_with_metadata({_set_metadata_to_ar: metadata }, ar_object)
      expect(new_user.object_id).to eq ar_object.object_id
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord_to_poro-0.0.9 spec/integration/lib/activerecord_to_poro/metadata_enabled_ar_spec.rb
activerecord_to_poro-0.0.8 spec/integration/lib/activerecord_to_poro/metadata_enabled_ar_spec.rb