diff --git a/db/schema.rb b/db/schema.rb index 6f48cccf0..bbbc93b4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_09_14_014133) do +ActiveRecord::Schema.define(version: 2018_09_28_021042) do create_table "bundle_contexts", force: :cascade do |t| t.string "project_name", null: false @@ -18,16 +18,17 @@ t.string "bundle_dir", null: false t.boolean "staging_style_symlink", default: false, null: false t.integer "content_metadata_creation", null: false - t.integer "user_id", null: false + t.bigint "user_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["user_id", "project_name"], name: "index_bundle_contexts_on_user_id_and_project_name", unique: true t.index ["user_id"], name: "index_bundle_contexts_on_user_id" end create_table "job_runs", force: :cascade do |t| t.string "output_location" t.integer "job_type", null: false - t.integer "bundle_context_id", null: false + t.bigint "bundle_context_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["bundle_context_id"], name: "index_job_runs_on_bundle_context_id" diff --git a/spec/controllers/bundle_contexts_controller_spec.rb b/spec/controllers/bundle_contexts_controller_spec.rb index f0eb0fa4b..80fefbf9e 100644 --- a/spec/controllers/bundle_contexts_controller_spec.rb +++ b/spec/controllers/bundle_contexts_controller_spec.rb @@ -37,30 +37,30 @@ context "POST create" do context "Valid Parameters" do let(:output_dir) { "#{Settings.job_output_parent_dir}/#{subject.current_user.sunet_id}/SMPL-multimedia" } - before do - Dir.delete(output_dir) if Dir.exist?(output_dir) - post :create, params: params - end + + before { Dir.delete(output_dir) if Dir.exist?(output_dir) } it 'passes newly created object' do + post :create, params: params expect(assigns(:bundle_context)).to be_a(BundleContext).and be_persisted expect(response).to have_http_status(302) # HTTP code for found expect(response).to redirect_to(job_runs_path(created: 1)) end it 'has the correct attributes' do + post :create, params: params bc = assigns(:bundle_context) expect(bc.project_name).to eq 'SMPL-multimedia' expect(bc.content_structure).to eq "simple_image" expect(bc.content_metadata_creation).to eq "default" expect(bc.bundle_dir).to eq "spec/test_data/smpl_multimedia" end - it "persists the JobRun" do - Dir.delete(output_dir) if Dir.exist?(output_dir) + it "persists the first JobRun, rejects dups" do expect { post :create, params: params }.to change(JobRun, :count).by(1) + expect { post :create, params: params }.to raise_error(RuntimeError, /Output directory.*should not already exist/) + Dir.delete(output_dir) if Dir.exist?(output_dir) # even if the directory is missing, cannot reuse user & project_name + expect { post :create, params: params }.to raise_error(ActiveRecord::RecordNotUnique) end - it "fails if job_type is nil" do - Dir.delete(output_dir) if Dir.exist?(output_dir) params[:bundle_context][:job_runs_attributes] = { "0" => { job_type: "" } } expect { post :create, params: params }.not_to change(JobRun, :count) end