From e2e0ed49554a2ca832f902a0e7e147b4d9f75b28 Mon Sep 17 00:00:00 2001 From: JG Date: Wed, 8 Jun 2022 15:56:56 +0100 Subject: [PATCH] added migration to add foreign key to the schemes table --- app/models/scheme.rb | 1 + db/migrate/20220608142147_create_schemes.rb | 12 ------------ db/schema.rb | 16 +++++++++++++--- spec/features/schemes_spec.rb | 11 +++++++++++ 4 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 db/migrate/20220608142147_create_schemes.rb diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 443b2fba4..4adcafe36 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -1,2 +1,3 @@ class Scheme < ApplicationRecord + belongs_to :organisation end diff --git a/db/migrate/20220608142147_create_schemes.rb b/db/migrate/20220608142147_create_schemes.rb deleted file mode 100644 index 9c102cc85..000000000 --- a/db/migrate/20220608142147_create_schemes.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateSchemes < ActiveRecord::Migration[7.0] - def change - create_table :schemes do |t| - t.string :code null: false - t.string :service - t.bigint :organisation_id - t.datetime :created_at - - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 4cca6211e..d9c37eca4 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[7.0].define(version: 2022_06_06_082639) do +ActiveRecord::Schema[7.0].define(version: 2022_06_08_144156) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -192,9 +192,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_06_082639) do t.integer "joint" t.bigint "created_by_id" t.integer "illness_type_0" + t.integer "retirement_value_check" t.integer "tshortfall_known" t.integer "shelteredaccom" - t.integer "retirement_value_check" t.integer "pregnancy_value_check" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" @@ -232,7 +232,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_06_082639) do create_table "logs_exports", force: :cascade do |t| t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } - t.datetime "started_at", precision: nil, null: false + t.datetime "started_at", null: false t.integer "base_number", default: 1, null: false t.integer "increment_number", default: 1, null: false t.boolean "empty_export", default: false, null: false @@ -277,6 +277,15 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_06_082639) do t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true end + create_table "schemes", force: :cascade do |t| + t.string "code" + t.string "service" + t.bigint "organisation_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["organisation_id"], name: "index_schemes_on_organisation_id" + end + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false @@ -330,4 +339,5 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_06_082639) do t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" end + add_foreign_key "schemes", "organisations" end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 90d662b8c..a876ae27a 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -5,12 +5,23 @@ RSpec.describe "Supported housing scheme Features" do context "when I am signed as a support user in there are schemes in the database" do let(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now) } let!(:schemes) { FactoryBot.create(:scheme) } + let(:notify_client) { instance_double(Notifications::Client) } + let(:confirmation_token) { "MCDH5y6Km-U7CFPgAMVS" } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } + let(:otp) { "999111" } before do + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(Devise).to receive(:friendly_token).and_return(confirmation_token) + allow(notify_client).to receive(:send_email).and_return(true) + allow(SecureRandom).to receive(:random_number).and_return(otp) visit("/logs") fill_in("user[email]", with: user.email) fill_in("user[password]", with: user.password) click_button("Sign in") + fill_in("code", with: otp) + click_button("Submit") end it "displays the link to the supported housing" do