Sha256: 9ec852c81c405c2fdd657155afb9b128d3a64ce5bf047346572f12201a864c8c

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

describe RSpecCandy::Helpers::Rails::CreateWithoutCallbacks do

  describe ActiveRecord::Base do

    describe '.create_without_callbacks' do

      it 'should create a record without running callbacks or validations' do
        model = Model.disposable_copy do
          before_save :crash
          validate :crash
          def crash
            raise 'callback was run'
          end
        end
        record = nil
        expect do
          record = model.create_without_callbacks(:string_field => 'foo')
        end.to_not raise_error
        record.string_field.should == 'foo'
        record.should be_a(Model)
        record.id.should be_a(Fixnum)
        record.should_not be_new_record
      end

      it 'should work with single table inheritance' do
        child = StiChild.create_without_callbacks(:string_field => 'foo')
        child.string_field.should == 'foo'
        child.should be_a(StiChild)
        child.id.should be_a(Fixnum)
        child.type.should == 'StiChild'
        child.should_not be_new_record
        StiChild.all.should == [child]
      end

    end

    describe '.new_and_store' do

      it 'should print a deprecation warning urging to use .create_without_callbacks instead' do
        Model.should_receive(:warn).with(/Use create_without_callbacks instead/i)
        Model.should_receive(:create_without_callbacks).with('args')
        Model.new_and_store('args')
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec_candy-0.2.7 spec/shared/rspec_candy/helpers/rails/create_without_callbacks_spec.rb
rspec_candy-0.2.6 spec/shared/rspec_candy/helpers/rails/create_without_callbacks_spec.rb