Sha256: c0e6d5134fc524aa781bac78aa4b9a81da4aee287df8574674dad231194e4b1c

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe "reload" do
  before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }

  describe "updates the Saviour::File instances on the model" do
    it do
      uploader = Class.new(Saviour::BaseUploader) { store_dir { "/store/dir" } }
      klass = Class.new(Test) { include Saviour::Model }
      klass.attach_file :file, uploader
      a = klass.create!
      b = klass.find(a.id)

      with_test_file("example.xml") do |example|
        a.update_attributes! file: example
        expect(a.file.exists?).to be_truthy
        expect(b.file.exists?).to be_falsey

        b.reload(lock: false)
        expect(b.file.exists?).to be_truthy
      end
    end
  end

  it "reloads the file instance" do
    uploader = Class.new(Saviour::BaseUploader) { store_dir { "/store/dir" } }
    klass = Class.new(Test) { include Saviour::Model }
    klass.attach_file :file, uploader
    a = klass.create!

    expect(a.file.present?).to be_falsey
    Saviour::Config.storage.write "contents", "file.txt"
    a.update_columns(file: "file.txt")
    expect(a.file.present?).to be_falsey

    a.file.reload
    expect(a.file.present?).to be_truthy
    expect(a.file.read).to eq "contents"
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
saviour-0.6.4 spec/feature/reload_model_spec.rb
saviour-0.6.3 spec/feature/reload_model_spec.rb
saviour-0.6.2 spec/feature/reload_model_spec.rb
saviour-0.6.1 spec/feature/reload_model_spec.rb
saviour-0.6.0 spec/feature/reload_model_spec.rb
saviour-0.5.11 spec/feature/reload_model_spec.rb
saviour-0.5.10 spec/feature/reload_model_spec.rb
saviour-0.5.9 spec/feature/reload_model_spec.rb
saviour-0.5.8 spec/feature/reload_model_spec.rb
saviour-0.5.7 spec/feature/reload_model_spec.rb