Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

611 base_path spec #613

Merged
merged 11 commits into from
Jul 27, 2022
7 changes: 7 additions & 0 deletions db/migrate/20220726162605_create_site.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateSite < ActiveRecord::Migration[5.2]
def change
create_table :sites do |t|
t.integer :account_id
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/20220726164334_create_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateAccount < ActiveRecord::Migration[5.2]
def change
create_table :accounts do |t|
t.string :name
end
end
end
53 changes: 45 additions & 8 deletions spec/parsers/bulkrax/application_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

module Bulkrax
RSpec.describe ApplicationParser do
describe '#get_field_mapping_hash_for' do
let(:importer) { FactoryBot.create(:bulkrax_importer) }
let(:exporter_with_no_field_mapping) { FactoryBot.create(:bulkrax_exporter) }
let(:exporter_with_field_mapping) do
FactoryBot.create(:bulkrax_exporter, field_mapping: {
"bulkrax_identifier" => { "from" => ["source_identifier"], "source_identifier" => true }
})
end
let(:importer) { FactoryBot.create(:bulkrax_importer) }
let(:exporter_with_no_field_mapping) { FactoryBot.create(:bulkrax_exporter) }
let(:exporter_with_field_mapping) do
FactoryBot.create(:bulkrax_exporter, field_mapping: {
"bulkrax_identifier" => { "from" => ["source_identifier"], "source_identifier" => true }
})
end
let(:site) { instance_double(Site, id: 1, account_id: 1) }
let(:account) { instance_double(Account, id: 1, name: 'bulkrax') }

describe '#get_field_mapping_hash_for' do
context 'with `[{}]` as the field mapping' do
subject(:application_parser) { described_class.new(importer) }

Expand All @@ -37,5 +39,40 @@ module Bulkrax
end
end
end

describe '#base_path' do
before do
allow(Site).to receive(:instance).and_return(site)
allow(Site.instance).to receive(:account).and_return(account)
end

context 'in a hyku enabled app' do
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
before do
ENV['SETTINGS__MULTITENANCY__ENABLED'] = 'true'
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
end

it 'sets the import path correctly' do
expect(importer.parser.base_path).to eq('tmp/imports/bulkrax')
end

it 'sets the export path correctly' do
expect(importer.parser.base_path('export')).to eq('tmp/exports/bulkrax')
end
end

context 'in a hyrax app' do
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
before do
ENV['SETTINGS__MULTITENANCY__ENABLED'] = 'false'
end

it 'sets the import path correctly' do
expect(importer.parser.base_path).to eq('tmp/imports')
end

it 'sets the export path correctly' do
expect(importer.parser.base_path('export')).to eq('tmp/exports')
end
end
end
end
end
4 changes: 4 additions & 0 deletions spec/parsers/bulkrax/bagit_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,13 @@ module Bulkrax

context 'folders and files for export' do
let(:bulkrax_exporter_run) { FactoryBot.create(:bulkrax_exporter_run, exporter: exporter) }
let(:site) { instance_double(Site, id: 1, account_id: 1) }
let(:account) { instance_double(Account, id: 1, name: 'bulkrax') }

before do
allow(exporter).to receive(:exporter_runs).and_return([bulkrax_exporter_run])
allow(Site).to receive(:instance).and_return(site)
allow(Site.instance).to receive(:account).and_return(account)
end

describe '#setup_csv_metadata_export_file' do
Expand Down
4 changes: 4 additions & 0 deletions spec/parsers/bulkrax/csv_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,13 @@ module Bulkrax
subject(:parser) { described_class.new(exporter) }
let(:bulkrax_exporter_run) { FactoryBot.create(:bulkrax_exporter_run, exporter: exporter) }
let(:exporter) { FactoryBot.create(:bulkrax_exporter_worktype) }
let(:site) { instance_double(Site, id: 1, account_id: 1) }
let(:account) { instance_double(Account, id: 1, name: 'bulkrax') }

before do
allow(exporter).to receive(:exporter_runs).and_return([bulkrax_exporter_run])
allow(Site).to receive(:instance).and_return(site)
allow(Site.instance).to receive(:account).and_return(account)
end

it 'creates the csv metadata file' do
Expand Down
4 changes: 4 additions & 0 deletions spec/test_app/app/models/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Account < ApplicationRecord
end
14 changes: 14 additions & 0 deletions spec/test_app/app/models/site.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class Site < ApplicationRecord
class << self

def instance
Site.create
end
end

def account
"account"
end
end
10 changes: 9 additions & 1 deletion spec/test_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_06_09_001128) do
ActiveRecord::Schema.define(version: 2022_07_26_164334) do

create_table "accounts", force: :cascade do |t|
t.string "name"
end

create_table "bookmarks", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -543,6 +547,10 @@
t.index ["permission_template_id", "name"], name: "index_sipity_workflows_on_permission_template_and_name", unique: true
end

create_table "sites", force: :cascade do |t|
t.integer "account_id"
end

create_table "tinymce_assets", force: :cascade do |t|
t.string "file"
t.datetime "created_at", null: false
Expand Down