Sha256: cba5a51c2fa1c3d67dfdb1003a2f854c5f7a65c9fbac9c524192a60070bd604b

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

require "spec_helper"

describe Mongoid::Persistence::Atomic::Bit do

  describe "#bit" do

    let(:person) do
      Person.create(age: 60)
    end

    let(:reloaded) do
      person.reload
    end

    context "when performing a bitwise and" do

      let!(:bit) do
        person.bit(:age, { and: 13 })
      end

      it "performs the bitwise operation" do
        person.age.should eq(12)
      end

      it "returns the new value" do
        bit.should eq(12)
      end

      it "persists the changes" do
        reloaded.age.should eq(12)
      end

      it "resets the dirty attributes" do
        person.changes["age"].should be_nil
      end
    end

    context "when performing a bitwise or" do

      let!(:bit) do
        person.bit(:age, { or: 13 })
      end

      it "performs the bitwise operation" do
        person.age.should eq(61)
      end

      it "returns the new value" do
        bit.should eq(61)
      end

      it "persists the changes" do
        reloaded.age.should eq(61)
      end

      it "resets the dirty attributes" do
        person.changes["age"].should be_nil
      end
    end

    context "when chaining bitwise operations" do

      let(:hash) do
        { and: 13, or: 10 }
      end

      let!(:bit) do
        person.bit(:age, hash)
      end

      it "performs the bitwise operation" do
        person.age.should eq(14)
      end

      it "returns the new value" do
        bit.should eq(14)
      end

      it "persists the changes" do
        reloaded.age.should eq(14)
      end

      it "resets the dirty attributes" do
        person.changes["age"].should be_nil
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-3.1.7 spec/mongoid/persistence/atomic/bit_spec.rb
mongoid-3.1.6 spec/mongoid/persistence/atomic/bit_spec.rb
mongoid-3.1.5 spec/mongoid/persistence/atomic/bit_spec.rb