Sha256: 48cb2f7095de75185010ad572c7e47315ff89cc93494b2ffe5731cbe41f0188b

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

# jruby has problems with installing sqlite3 - don't bother with these tests for jruby
unless RUBY_PLATFORM == "java"
  require "spec_helper"
  require "active_record"
  require "sqlite3"

  # ActiveRecord specific stuff goes here (there should be very little!)
  describe "ActiveRecord models" do
    let! :dragonfly_app do test_app(:test_ar) end

    before :all do
      @connection = ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")

      ActiveRecord::Migration.verbose = false

      ActiveRecord::Schema.define(:version => 1) do
        create_table :photos do |t|
          t.string :image_uid
        end
      end

      class Photo < ActiveRecord::Base
        extend Dragonfly::Model
        dragonfly_accessor :image, app: :test_ar
      end
    end

    after :all do
      Photo.destroy_all
      ActiveRecord::Base.remove_connection(@connection)
    end

    describe "destroying" do
      before do
        Photo.destroy_all
        @photo = Photo.create(image: "some data")
      end

      def data_exists(uid)
        !!dragonfly_app.datastore.read(uid)
      end

      it "should not remove the attachment if a transaction is cancelled" do
        Photo.transaction do
          @photo.destroy
          raise ActiveRecord::Rollback
        end
        photo = Photo.last
        expect(photo.image_uid).not_to be_nil
        expect(data_exists(photo.image_uid)).to eq(true)
      end

      it "should remove the attachment as per usual otherwise" do
        uid = @photo.image_uid
        @photo.destroy
        photo = Photo.last
        expect(photo).to be_nil
        expect(data_exists(uid)).to eq(false)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dragonfly-1.4.0 spec/dragonfly/model/active_record_spec.rb
dragonfly-1.3.0 spec/dragonfly/model/active_record_spec.rb