Created
April 13, 2016 10:10
-
-
Save romanlehnert/e0a4b614fabdc89c4fbb2efd5b3181a0 to your computer and use it in GitHub Desktop.
Wrong reference of embedded document at after_save cb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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