Skip to content

Instantly share code, notes, and snippets.

@romanlehnert
Created April 13, 2016 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanlehnert/e0a4b614fabdc89c4fbb2efd5b3181a0 to your computer and use it in GitHub Desktop.
Save romanlehnert/e0a4b614fabdc89c4fbb2efd5b3181a0 to your computer and use it in GitHub Desktop.
Wrong reference of embedded document at after_save cb
require 'mongoid'
require 'rspec'
Mongoid.configure.connect_to('mongoid_test')
class Syncer
def self.perform(address); end
end
class Customer
include Mongoid::Document
embeds_one :address
def address_changed
Syncer.perform(address)
end
end
class Address
include Mongoid::Document
embedded_in :customer
after_save { customer.address_changed }
end
describe 'set the address via address=(address)' do
it 'knows about the new address' do
customer = Customer.create
address = Address.new
expect(Syncer).to receive(:perform).with(address).once
customer.address = address
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment