spec/mongoid/attributes/readonly_spec.rb in mongoid-7.3.5 vs spec/mongoid/attributes/readonly_spec.rb in mongoid-7.4.0
- old
+ new
@@ -1,7 +1,6 @@
# frozen_string_literal: true
-# encoding: utf-8
require "spec_helper"
describe Mongoid::Attributes::Readonly do
@@ -56,11 +55,11 @@
let(:attributes) do
[ :title, :terms, :aliased_timestamp ]
end
let(:person) do
- Person.create(title: "sir", terms: true, aliased_timestamp: Time.at(42))
+ Person.create!(title: "sir", terms: true, aliased_timestamp: Time.at(42))
end
it "sets the first readonly value" do
expect(person.title).to eq("sir")
end
@@ -91,44 +90,44 @@
let(:attributes) do
[ :title, :terms, :score, :aliased_timestamp ]
end
let(:person) do
- Person.create(title: "sir", terms: true, score: 1, aliased_timestamp: Time.at(42))
+ Person.create!(title: "sir", terms: true, score: 1, aliased_timestamp: Time.at(42))
end
context "when updating via the setter" do
it "does not update the first field" do
person.title = 'mr'
- person.save
+ person.save!
expect(person.reload.title).to eq("sir")
end
it "does not update the second field" do
person.aliased_timestamp = Time.at(43)
- person.save
+ person.save!
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
end
end
context "when updating via inc" do
context 'with single field operation' do
it "updates the field" do
person.inc(score: 1)
- person.save
+ person.save!
expect(person.reload.score).to eq(2)
end
end
context 'with multiple fields operation' do
it "updates the fields" do
person.inc(score: 1, age: 1)
- person.save
+ person.save!
expect(person.reload.score).to eq(2)
expect(person.reload.age).to eq(101)
end
end
end
@@ -137,82 +136,82 @@
context 'with single field operation' do
it "does the update" do
person.bit(score: { or: 13 })
- person.save
+ person.save!
expect(person.reload.score).to eq(13)
end
end
context 'with multiple fields operation' do
- it "udpates the attribute" do
+ it "updates the attribute" do
person.bit(age: {and: 13}, score: {or: 13})
- person.save
+ person.save!
expect(person.reload.score).to eq(13)
expect(person.reload.age).to eq(4)
end
end
end
context "when updating via []=" do
it "does not update the first field" do
person[:title] = "mr"
- person.save
+ person.save!
expect(person.reload.title).to eq("sir")
end
it "does not update the second field" do
person[:aliased_timestamp] = Time.at(43)
- person.save
+ person.save!
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
end
end
context "when updating via write_attribute" do
it "does not update the first field" do
person.write_attribute(:title, "mr")
- person.save
+ person.save!
expect(person.reload.title).to eq("sir")
end
it "does not update the second field" do
person.write_attribute(:aliased_timestamp, Time.at(43))
- person.save
+ person.save!
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
end
end
context "when updating via update_attributes" do
it "does not update the first field" do
- person.update_attributes(title: "mr", aliased_timestamp: Time.at(43))
- person.save
+ person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
+ person.save!
expect(person.reload.title).to eq("sir")
end
it "does not update the second field" do
- person.update_attributes(title: "mr", aliased_timestamp: Time.at(43))
- person.save
+ person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
+ person.save!
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
end
end
context "when updating via update_attributes!" do
it "does not update the first field" do
person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
- person.save
+ person.save!
expect(person.reload.title).to eq("sir")
end
it "does not update the second field" do
person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
- person.save
+ person.save!
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
end
end
context "when updating via update_attribute" do
@@ -241,15 +240,15 @@
end
context 'when the relation exists' do
let(:mother) do
- Person.create
+ Person.create!
end
let(:child) do
- Person.create(mother: mother)
+ Person.create!(mother: mother)
Person.find_by(mother: mother)
end
it 'the relation can still be accessed' do
expect(child.mother).to eq(mother)
@@ -257,10 +256,10 @@
end
context 'when the relation does not exist' do
let(:child) do
- Person.create
+ Person.create!
end
it 'the relation is nil' do
expect(child.mother).to be_nil
end