Browse Source

added migration to add foreign key to the schemes table

pull/648/head
JG 3 years ago
parent
commit
e2e0ed4955
  1. 1
      app/models/scheme.rb
  2. 12
      db/migrate/20220608142147_create_schemes.rb
  3. 16
      db/schema.rb
  4. 11
      spec/features/schemes_spec.rb

1
app/models/scheme.rb

@ -1,2 +1,3 @@
class Scheme < ApplicationRecord class Scheme < ApplicationRecord
belongs_to :organisation
end end

12
db/migrate/20220608142147_create_schemes.rb

@ -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

16
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -192,9 +192,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_06_082639) do
t.integer "joint" t.integer "joint"
t.bigint "created_by_id" t.bigint "created_by_id"
t.integer "illness_type_0" t.integer "illness_type_0"
t.integer "retirement_value_check"
t.integer "tshortfall_known" t.integer "tshortfall_known"
t.integer "shelteredaccom" t.integer "shelteredaccom"
t.integer "retirement_value_check"
t.integer "pregnancy_value_check" t.integer "pregnancy_value_check"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" 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" 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| create_table "logs_exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } 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 "base_number", default: 1, null: false
t.integer "increment_number", default: 1, null: false t.integer "increment_number", default: 1, null: false
t.boolean "empty_export", default: false, 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 t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true
end 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| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", 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" t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end end
add_foreign_key "schemes", "organisations"
end end

11
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 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(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now) }
let!(:schemes) { FactoryBot.create(:scheme) } 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 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") visit("/logs")
fill_in("user[email]", with: user.email) fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password) fill_in("user[password]", with: user.password)
click_button("Sign in") click_button("Sign in")
fill_in("code", with: otp)
click_button("Submit")
end end
it "displays the link to the supported housing" do it "displays the link to the supported housing" do

Loading…
Cancel
Save