Sha256: da7129ee0db6f1725b4959926b76147d5a327fa29510d6f0bd9a9fe59ce31b04

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 Bytes

Contents

require 'spec_helper'

class MongoidArticle
  include Mongoid::Document
  include Uploader::Fileuploads

  has_one :mongoid_picture, :as => :assetable

  fileuploads :mongoid_picture
end

class MongoidPicture
  include Mongoid::Document
  include Uploader::Asset::Mongoid

  before_create :generate_public_token

  belongs_to :assetable, polymorphic: true
end

describe Uploader::Asset::Mongoid do
  before do
    @guid = 'guid'
    @picture = MongoidPicture.create!(:guid => @guid, :assetable_type => 'MongoidArticle')
  end

  it 'should find asset by guid' do
    asset = MongoidArticle.fileupload_find("mongoid_picture", @picture.guid)
    asset.should == @picture
  end

  it "should update asset target_id by guid" do
    MongoidArticle.fileupload_update(1000, @picture.guid, :mongoid_picture)
    @picture.reload
    @picture.assetable_id.should == 1000
    @picture.guid.should be_nil
  end

  after do
    MongoidPicture.destroy_all
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-uploader-0.2.2 spec/mongoid_spec.rb
rails-uploader-0.2.1 spec/mongoid_spec.rb