Sha256: c7ad3dcf7af917d92abe8c4d16e9dbd9bdb752e32ac312ffe4c56b56e5da4b08

Contents?: true

Size: 1.81 KB

Versions: 71

Compression:

Stored size: 1.81 KB

Contents

require 'test_helper'

class SafeTest < Test::Unit::TestCase
  context "A Document" do
    should "default safe to off" do
      Doc().should_not be_safe
    end

    should "allow turning safe on" do
      Doc() { safe }.should be_safe
    end

    context "inherited with safe setting on" do
      should "set subclass safe setting on" do
        inherited = Class.new(Doc() { safe })
        inherited.should be_safe
      end
    end

    context "inherited with safe setting off" do
      should "leave subclass safe setting off" do
        inherited = Class.new(Doc())
        inherited.should_not be_safe
      end
    end
  end

  context "A safe document" do
    setup do
      @klass = Doc() do
        safe
      end
    end
    teardown { drop_indexes(@klass) }

    context "#save" do
      setup do
        @klass.ensure_index :email, :unique => true
      end

      context "using safe setting from class" do
        should "work fine when all is well" do
          assert_nothing_raised do
            @klass.new(:email => 'john@doe.com').save
          end
        end

        should "raise error when operation fails" do
          assert_raises(Mongo::OperationFailure) do
            2.times do
              @klass.new(:email => 'john@doe.com').save
            end
          end
        end
      end

      context "overriding safe setting" do
        should "raise error if safe is true" do
          assert_raises(Mongo::OperationFailure) do
            2.times do
              @klass.new(:email => 'john@doe.com').save(:safe => true)
            end
          end
        end

        should "not raise error if safe is false" do
          assert_nothing_raised do
            2.times do
              @klass.new(:email => 'john@doe.com').save(:safe => false)
            end
          end
        end
      end
    end
  end
end

Version data entries

71 entries across 71 versions & 9 rubygems

Version Path
mongo_mapper-0.12.0 test/functional/test_safe.rb
lookout-mongo_mapper-0.11.3 test/functional/test_safe.rb
mongo_mapper-0.11.2 test/functional/test_safe.rb
jamieorc-mongo_mapper-0.11.1.1 test/functional/test_safe.rb
mongo_mapper-0.11.1 test/functional/test_safe.rb
mongo_mapper-0.11.0 test/functional/test_safe.rb
mongo_mapper-0.10.1 test/functional/test_safe.rb
mongo_mapper-0.10.0 test/functional/test_safe.rb
mongo_mapper-0.9.2 test/functional/test_safe.rb
jonbell-mongo_mapper-0.8.6 test/functional/test_safe.rb
mongo_mapper-0.9.1 test/functional/test_safe.rb
mongo_mapper-0.9.0 test/functional/test_safe.rb
ign-mongo_mapper-0.8.6.2 test/functional/test_safe.rb
ign-mongo_mapper-0.8.6.1 test/functional/test_safe.rb
ssherman-mongo_mapper-0.8.6 test/functional/test_safe.rb
mongo_mapper-0.8.6 test/functional/test_safe.rb
mongo_mapper-0.8.5 test/functional/test_safe.rb
honkster-mongo_mapper-0.8.4 test/functional/test_safe.rb
mongo_mapper-0.8.4 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.19 test/functional/test_safe.rb