Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ RSpec/BeforeAfterAll:
RSpec/DescribeClass:
Enabled: false

RSpec/ExampleLength:
Max: 10

RSpec/ImplicitExpect:
EnforcedStyle: is_expected

Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/association/embedded/embeds_one/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def initialize(base, target, association)
bind_one
characterize_one(_target)
update_attributes_hash(_target)
_base._reset_memoized_descendants!
_target.save if persistable?
_base._reset_memoized_descendants!
end
end

Expand Down
31 changes: 25 additions & 6 deletions spec/integration/associations/embeds_one_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

describe 'embeds_one associations' do

context 're-associating the same object' do
context 'when re-associating the same object' do
context 'with dependent: destroy' do
let(:canvas) do
Canvas.create!(palette: Palette.new)
Expand All @@ -17,7 +15,7 @@
canvas.palette = canvas.palette
canvas.save!
canvas.reload
canvas.palette.should == palette
expect(canvas.palette).to eq palette
end
end
end
Expand All @@ -31,12 +29,33 @@
end

it 'loads the association correctly' do
expect { klass }.to_not raise_error
expect { klass.new.address }.to_not raise_error
expect { klass }.not_to raise_error
expect { klass.new.address }.not_to raise_error
instance = klass.new
address = Address.new
instance.address = address
expect(instance.address).to eq address
end
end

context 'when parent is persisted' do
let!(:person) do
Person.create!
end

context 'when assigning the new child' do
context 'when assigning an attribute to the child' do
before do
# person.reload
person.name = Name.new
person.name.first_name = 'Dmitry'
person.save!
end

it 'persists the child' do
expect(person.reload.name.first_name).to eq 'Dmitry'
end
end
end
end
end
Loading