Sha256: ed428a29260c9eed843db8fd24e7e50c3b013695c6714fae22cb29cc7ef3e72d

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require 'rom/lint/spec'
require 'rom/files/connection'
require 'shared/rom/files/media_relation'

RSpec.describe ROM::Files::Connection do
  include_context 'media relation'

  subject(:connection) { described_class.new(uri) }

  its(:path) { is_expected.to eq uri }

  describe '#create_dataset' do
    subject(:dataset) { connection.create_dataset(name_or_mime_type) }

    xcontext '(path)' do
      let(:name_or_mime_type) { :media }

      it { is_expected.to be_a ROM::Files::Dataset }
      its(:path) { is_expected.to eq uri.join(name_or_mime_type.to_s) }
      its(:mime_type) { is_expected.to eq nil }
    end

    context '(mime_type)' do
      let(:name_or_mime_type) { 'application/x-ruby' }

      it { is_expected.to be_a ROM::Files::Dataset }
      its(:path) { is_expected.to eq uri }
      its(:mime_type) { is_expected.to eq name_or_mime_type }
    end
  end

  describe '#key?' do
    subject { connection.key?(name) }

    context 'with existing path' do
      let(:name) { :media }

      it { is_expected.to eq true }
    end

    context 'with non-existing path' do
      let(:name) { :not_real }

      it { is_expected.to eq false }
    end

    context 'with registered MIME type' do
      let(:name) { 'application/x-ruby' }

      it { is_expected.to eq true }
    end

    context 'with unknown MIME type' do
      let(:name) { 'application/x-files' }

      it { is_expected.to eq false }
    end
  end

  describe '#search' do
    subject(:files) { connection.search(patterns, exclude_patterns: exclude_patterns, sorting: sorting, directories: directories) }
    let(:patterns) { ['*'] }
    let(:exclude_patterns) { [] }
    let(:sorting) { nil }
    let(:directories) { false }

    it { is_expected.to be_a Array }

    xcontext 'including everything'
    xcontext 'excluding images'
    xcontext 'sorting results'
    xcontext 'including directories'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-files-0.2.0 spec/lib/rom/files/connection_spec.rb