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-unstable-2010.08.18 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.17 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.16 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.15 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.14 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.13 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.12 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.11 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.10 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.09 test/functional/test_safe.rb
mongo_mapper-0.8.3 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.08 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.06 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.05 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.04 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.03 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.02 test/functional/test_safe.rb
mongo_mapper-unstable-2010.08.01 test/functional/test_safe.rb
mongo_mapper-unstable-2010.07.31 test/functional/test_safe.rb
mongo_mapper-unstable-2010.07.30 test/functional/test_safe.rb