Sha256: d982b7e801e589f3955186a079015645675dc6d477f1cc4bdfef96b1a138de01

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'
require 'newspaper_works_fixtures'

RSpec.describe NewspaperWorks::Ingest::FromCommand do
  include_context "ingest test fixtures"

  describe "alternate construction" do
    let(:klass) do
      Class.new do
        extend NewspaperWorks::Ingest::FromCommand

        attr_accessor :path, :opts

        def initialize(path, opts = {})
          @path = path
          @opts = opts
        end
      end
    end

    def construct(args)
      klass.from_command(
        args,
        'rake newspaper_works:ingest_pdf_issues --'
      )
    end

    let(:lccn) { 'sn93059126' }

    let(:pdf_path) { File.join(pdf_fixtures, lccn) }

    let(:fake_argv) do
      [
        'newspaper_works:ingest_pdf_issues',
        '--',
        "--path=#{pdf_path}"
      ]
    end

    let(:more_argv) do
      fake_argv + [
        "--lccn=#{lccn}"
      ]
    end

    let(:most_argv) do
      more_argv + [
        "--admin_set=admin_set/default",
        "--depositor=#{User.batch_user.user_key}",
        "--visibility=open"
      ]
    end

    it "calls constructor with minimal options parsed" do
      ingester = construct(fake_argv)
      expect(ingester.path).to eq pdf_path
      expect(ingester.opts[:path]).to eq pdf_path
    end

    it "calls constructor with explict lccn option" do
      ingester = construct(more_argv)
      expect(ingester.path).to eq pdf_path
      expect(ingester.opts[:lccn]).to eq lccn
    end

    it "calls constructor with all options" do
      ingester = construct(most_argv)
      expect(ingester.path).to eq pdf_path
      expect(ingester.opts[:lccn]).to eq lccn
      expect(ingester.opts[:admin_set]).to eq 'admin_set/default'
      expect(ingester.opts[:depositor]).to eq User.batch_user.user_key
      expect(ingester.opts[:visibility]).to eq 'open'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
newspaper_works-1.0.1 spec/lib/newspaper_works/ingest/from_command_spec.rb
newspaper_works-1.0.0 spec/lib/newspaper_works/ingest/from_command_spec.rb
newspaper_works-0.1.0 spec/lib/newspaper_works/ingest/from_command_spec.rb