Skip to content

Commit

Permalink
5059
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Mar 31, 2021
1 parent cf762a1 commit a68089c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/mongoid-documents.txt
Expand Up @@ -292,7 +292,7 @@ Mongoid provides several ways of accessing field values.
.. note::

All of the access methods described below raise
``Mongoid::Errors::MissingAttributeError`` when the field being accessed is
``ActiveModel::MissingAttributeError`` when the field being accessed is
:ref:`projected out <projection>`, either by virtue of not being included in
:ref:`only <only>` or by virtue of being included in
:ref:`without <without>`. This applies to both reads and writes.
Expand Down
28 changes: 10 additions & 18 deletions spec/mongoid/persistable/settable_spec.rb
Expand Up @@ -523,30 +523,22 @@
end

context 'field exists in database' do
before do
agent.set(title: '008')
end

it "writes the value into the model instance" do
agent.title.should == '008'
end
it "raises MissingAttributeError" do
lambda do
agent.set(title: '008')
end.should raise_error(ActiveModel::MissingAttributeError)

it "writes the value into the database" do
expect(agent.reload.title).to eq '008'
expect(agent.reload.title).to eq 'Double-Oh Eight'
end
end

context 'field does not exist in database' do
before do
agent.set(number: '008')
end

it "writes the value into the model instance" do
agent.number.should == '008'
end
it "raises MissingAttributeError" do
lambda do
agent.set(number: '008')
end.should raise_error(ActiveModel::MissingAttributeError)

it "writes the value into the database" do
expect(agent.reload.number).to eq '008'
expect(agent.reload.read_attribute(:number)).to be nil
end
end
end
Expand Down

0 comments on commit a68089c

Please sign in to comment.