diff --git a/db/migrate/20220726162605_create_site.rb b/db/migrate/20220726162605_create_site.rb new file mode 100644 index 00000000..b45210a4 --- /dev/null +++ b/db/migrate/20220726162605_create_site.rb @@ -0,0 +1,7 @@ +class CreateSite < ActiveRecord::Migration[5.2] + def change + create_table :sites do |t| + t.integer :account_id + end + end +end diff --git a/db/migrate/20220726164334_create_account.rb b/db/migrate/20220726164334_create_account.rb new file mode 100644 index 00000000..634f9f15 --- /dev/null +++ b/db/migrate/20220726164334_create_account.rb @@ -0,0 +1,7 @@ +class CreateAccount < ActiveRecord::Migration[5.2] + def change + create_table :accounts do |t| + t.string :name + end + end +end diff --git a/spec/parsers/bulkrax/application_parser_spec.rb b/spec/parsers/bulkrax/application_parser_spec.rb index c4ceb635..606936d3 100644 --- a/spec/parsers/bulkrax/application_parser_spec.rb +++ b/spec/parsers/bulkrax/application_parser_spec.rb @@ -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) } @@ -37,5 +39,42 @@ 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 multi tenant app' do + before do + ENV['SETTINGS__MULTITENANCY__ENABLED'] = 'true' + 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 non multi tenant app' do + # this includes hyrax apps AND single tenant hyku apps + + 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 diff --git a/spec/parsers/bulkrax/bagit_parser_spec.rb b/spec/parsers/bulkrax/bagit_parser_spec.rb index cf8d2f2a..b52c9471 100644 --- a/spec/parsers/bulkrax/bagit_parser_spec.rb +++ b/spec/parsers/bulkrax/bagit_parser_spec.rb @@ -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 diff --git a/spec/parsers/bulkrax/csv_parser_spec.rb b/spec/parsers/bulkrax/csv_parser_spec.rb index 7e23edc1..db7055f0 100644 --- a/spec/parsers/bulkrax/csv_parser_spec.rb +++ b/spec/parsers/bulkrax/csv_parser_spec.rb @@ -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 diff --git a/spec/test_app/app/models/account.rb b/spec/test_app/app/models/account.rb new file mode 100644 index 00000000..72241397 --- /dev/null +++ b/spec/test_app/app/models/account.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Account < ApplicationRecord +end \ No newline at end of file diff --git a/spec/test_app/app/models/site.rb b/spec/test_app/app/models/site.rb new file mode 100644 index 00000000..3b089542 --- /dev/null +++ b/spec/test_app/app/models/site.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class Site < ApplicationRecord + class << self + + def instance + Site.create + end + end + + def account + "account" + end +end diff --git a/spec/test_app/db/schema.rb b/spec/test_app/db/schema.rb index b36b1f34..6e102c37 100644 --- a/spec/test_app/db/schema.rb +++ b/spec/test_app/db/schema.rb @@ -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 @@ -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