Sha256: a6cc28b58e13551444c3a5c606a4ce0c3e6b30e8062f08c29898104a355a0a7c

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

RSpec.describe Refile::BackendMacros do
  let(:klass) do
    Class.new do
      extend Refile::BackendMacros

      attr_accessor :max_size

      verify_uploadable def upload(uploadable)
        uploadable
      end

      verify_id def get(id)
        id
      end
    end
  end
  let(:instance) { klass.new }

  describe "#verify_uploadable" do
    let(:io) { StringIO.new("hello") }

    it "works if it conforms to required API" do
      expect(instance.upload(double(size: 444, read: io, eof?: true, close: nil))).to be_truthy
    end

    it "raises ArgumentError if argument does not respond to `size`" do
      expect { instance.upload(double(read: io, eof?: true, close: nil)) }.to raise_error(ArgumentError)
    end

    it "raises ArgumentError if argument does not respond to `read`" do
      expect { instance.upload(double(size: 444, eof?: true, close: nil)) }.to raise_error(ArgumentError)
    end

    it "raises ArgumentError if argument does not respond to `eof?`" do
      expect { instance.upload(double(size: 444, read: true, close: nil)) }.to raise_error(ArgumentError)
    end

    it "raises ArgumentError if argument does not respond to `close`" do
      expect { instance.upload(double(size: 444, read: true, eof?: true)) }.to raise_error(ArgumentError)
    end

    it "returns true if size is respeced" do
      instance.max_size = 8
      expect(instance.upload(Refile::FileDouble.new("hello"))).to be_truthy
    end

    it "raises Refile::Invalid if size is exceeded" do
      instance.max_size = 8
      expect { instance.upload(Refile::FileDouble.new("hello world")) }.to raise_error(Refile::Invalid)
    end
  end

  describe "#verify_id" do
    it "works if it has a valid ID" do
      expect(instance.get("1234aBCde123aee")).to be_truthy
    end

    it "raises ArgumentError if argument does not respond to `size`" do
      expect { instance.get("ev/il") }.to raise_error(Refile::InvalidID)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
refile-0.5.5 spec/refile/backend_macros_spec.rb
refile-0.5.4 spec/refile/backend_macros_spec.rb
refile-0.5.3 spec/refile/backend_macros_spec.rb