spec/mongoid/contextual/atomic_spec.rb in mongoid-5.4.1 vs spec/mongoid/contextual/atomic_spec.rb in mongoid-6.0.0.beta
- old
+ new
@@ -71,33 +71,10 @@
it "adds to non initialized fields" do
expect(smiths.reload.members).to eq([ "Dave" ])
end
end
-
- context 'when the criteria has a collation', if: collation_supported? do
-
- let(:criteria) do
- Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.add_to_set(members: "Dave", genres: "Electro")
- end
-
- it "does not add duplicates" do
- expect(depeche_mode.reload.members).to eq([ "Dave" ])
- end
-
- it "adds multiple operations" do
- expect(depeche_mode.reload.genres).to eq([ "Electro" ])
- end
- end
end
describe "#bit" do
let!(:depeche_mode) do
@@ -142,33 +119,10 @@
it "performs the bitwise operation on initialized fields" do
expect(depeche_mode.reload.likes).to eq(14)
end
end
-
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ], likes: 60)
- end
-
- let(:criteria) do
- Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.bit(likes: { and: 13, or: 10 })
- end
-
- it "performs the bitwise operation on initialized fields" do
- expect(depeche_mode.reload.likes).to eq(14)
- end
- end
end
describe "#inc" do
let!(:depeche_mode) do
@@ -221,33 +175,10 @@
it "incs the value and read from field" do
expect(beatles.reload.y).to eq(3)
end
end
-
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
-
- let(:criteria) do
- Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.inc(years: 1)
- end
-
- it "incs the value and read from alias" do
- expect(depeche_mode.reload.years).to eq(1)
- end
- end
end
describe "#pop" do
let!(:depeche_mode) do
@@ -293,33 +224,10 @@
it "does not error on uninitialized fields" do
expect(smiths.reload.members).to be_nil
end
end
-
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
-
- let(:criteria) do
- Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.pop(members: 1)
- end
-
- it "pops the last element off the array" do
- expect(depeche_mode.reload.members).to be_empty
- end
- end
end
describe "#pull" do
let!(:depeche_mode) do
@@ -347,280 +255,133 @@
end
it "does not error on non existent fields" do
expect(smiths.reload.members).to be_nil
end
-
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
-
- let(:criteria) do
- Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.pull(members: "DAVE")
- end
-
- it "pulls when the value is found" do
- expect(depeche_mode.reload.members).to be_empty
- end
- end
end
describe "#pull_all" do
- context 'when the criteria does not have a collation' do
+ let!(:depeche_mode) do
+ Band.create(members: [ "Dave", "Alan", "Fletch" ])
+ end
- let!(:depeche_mode) do
- Band.create(members: [ "Dave", "Alan", "Fletch" ])
- end
+ let!(:smiths) do
+ Band.create
+ end
- let!(:smiths) do
- Band.create
- end
+ let(:criteria) do
+ Band.all
+ end
- let(:criteria) do
- Band.all
- end
+ let(:context) do
+ Mongoid::Contextual::Mongo.new(criteria)
+ end
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
+ before do
+ context.pull_all(members: [ "Alan", "Dave" ])
+ end
- before do
- context.pull_all(members: [ "Alan", "Dave" ])
- end
-
- it "pulls when the values are found" do
- expect(depeche_mode.reload.members).to eq([ "Fletch" ])
- end
-
- it "does not error on non existent fields" do
- expect(smiths.reload.members).to be_nil
- end
+ it "pulls when the values are found" do
+ expect(depeche_mode.reload.members).to eq([ "Fletch" ])
end
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave", "Alan", "Fletch" ])
- end
-
- let(:criteria) do
- Band.all.collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.pull_all(members: [ "ALAN", "DAVE" ])
- end
-
- it "pulls when the value is found" do
- expect(depeche_mode.reload.members).to eq([ "Fletch" ])
- end
+ it "does not error on non existent fields" do
+ expect(smiths.reload.members).to be_nil
end
end
describe "#push" do
- context 'when the criteria does not have a collation' do
+ let!(:depeche_mode) do
+ Band.create(members: [ "Dave" ])
+ end
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
+ let!(:smiths) do
+ Band.create
+ end
- let!(:smiths) do
- Band.create
- end
+ let(:criteria) do
+ Band.all
+ end
- let(:criteria) do
- Band.all
- end
+ let(:context) do
+ Mongoid::Contextual::Mongo.new(criteria)
+ end
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
+ before do
+ context.push(members: "Alan")
+ end
- before do
- context.push(members: "Alan")
- end
-
- it "pushes the value to existing arrays" do
- expect(depeche_mode.reload.members).to eq([ "Dave", "Alan" ])
- end
-
- it "pushes to non existent fields" do
- expect(smiths.reload.members).to eq([ "Alan" ])
- end
+ it "pushes the value to existing arrays" do
+ expect(depeche_mode.reload.members).to eq([ "Dave", "Alan" ])
end
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
-
- let!(:smiths) do
- Band.create
- end
-
- let(:criteria) do
- Band.where(members: ['DAVE']).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.push(members: "Alan")
- end
-
- it "pushes the value to existing arrays" do
- expect(depeche_mode.reload.members).to eq([ "Dave", "Alan" ])
- end
-
- it "pushes to non existent fields" do
- expect(smiths.reload.members).to be_nil
- end
+ it "pushes to non existent fields" do
+ expect(smiths.reload.members).to eq([ "Alan" ])
end
end
- describe "#push_each" do
+ describe "#push_all" do
- context 'when the criteria does not have a collation' do
+ let!(:depeche_mode) do
+ Band.create(members: [ "Dave" ])
+ end
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
+ let!(:smiths) do
+ Band.create
+ end
- let!(:smiths) do
- Band.create
- end
+ let(:criteria) do
+ Band.all
+ end
- let(:criteria) do
- Band.all
- end
+ let(:context) do
+ Mongoid::Contextual::Mongo.new(criteria)
+ end
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
+ before do
+ context.push_all(members: [ "Alan", "Fletch" ])
+ end
- before do
- context.push_each(members: [ "Alan", "Fletch" ])
- end
-
- it "pushes the values to existing arrays" do
- expect(depeche_mode.reload.members).to eq([ "Dave", "Alan", "Fletch" ])
- end
-
- it "pushes to non existent fields" do
- expect(smiths.reload.members).to eq([ "Alan", "Fletch" ])
- end
+ it "pushes the values to existing arrays" do
+ expect(depeche_mode.reload.members).to eq([ "Dave", "Alan", "Fletch" ])
end
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
-
- let!(:smiths) do
- Band.create
- end
-
- let(:criteria) do
- Band.where(members: ['DAVE']).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.push_each(members: [ "Alan", "Fletch" ])
- end
-
- it "pushes the values to existing arrays" do
- expect(depeche_mode.reload.members).to eq([ "Dave", "Alan", "Fletch" ])
- end
+ it "pushes to non existent fields" do
+ expect(smiths.reload.members).to eq([ "Alan", "Fletch" ])
end
end
describe "#rename" do
- context 'when the criteria does not have a collation' do
+ let!(:depeche_mode) do
+ Band.create(members: [ "Dave" ])
+ end
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
+ let!(:smiths) do
+ Band.create
+ end
- let!(:smiths) do
- Band.create
- end
+ let(:criteria) do
+ Band.all
+ end
- let(:criteria) do
- Band.all
- end
+ let(:context) do
+ Mongoid::Contextual::Mongo.new(criteria)
+ end
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
+ before do
+ context.rename(members: :artists)
+ end
- before do
- context.rename(members: :artists)
- end
-
- it "renames existing fields" do
- expect(depeche_mode.reload.artists).to eq([ "Dave" ])
- end
-
- it "does not rename non existent fields" do
- expect(smiths.reload).to_not respond_to(:artists)
- end
+ it "renames existing fields" do
+ expect(depeche_mode.reload.artists).to eq([ "Dave" ])
end
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(members: [ "Dave" ])
- end
-
- let!(:smiths) do
- Band.create
- end
-
- let(:criteria) do
- Band.where(members: ['DAVE']).collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.rename(members: :artists)
- end
-
- it "renames existing fields" do
- expect(depeche_mode.reload.artists).to eq([ "Dave" ])
- end
-
- it "does not rename non existent fields" do
- expect(smiths.reload).to_not respond_to(:artists)
- end
+ it "does not rename non existent fields" do
+ expect(smiths.reload).to_not respond_to(:artists)
end
end
describe "#set" do
@@ -744,36 +505,9 @@
end
it "unsets the aliased field" do
expect(new_order.reload.years).to be_nil
end
- end
- end
-
- context 'when the criteria has a collation', if: collation_supported? do
-
- let!(:depeche_mode) do
- Band.create(name: "Depeche Mode", years: 10)
- end
-
- let!(:new_order) do
- Band.create(name: "New Order", years: 10)
- end
-
- let(:criteria) do
- Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2)
- end
-
- let(:context) do
- Mongoid::Contextual::Mongo.new(criteria)
- end
-
- before do
- context.unset(:name)
- end
-
- it "unsets the unaliased field" do
- expect(depeche_mode.reload.name).to be_nil
end
end
end
end