Skip to content

Commit

Permalink
Add Schools and Providers
Browse files Browse the repository at this point in the history
Name might not be included long term.
  • Loading branch information
elceebee committed Dec 14, 2023
1 parent c10e5c0 commit 614e722
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/models/concerns/service_scopes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module ServiceScopes
extend ActiveSupport::Concern

included do
scope :placements, -> { where placements: true }
scope :claims, -> { where claims: true }
end
end
19 changes: 19 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: providers
#
# id :uuid not null, primary key
# claims :boolean default(FALSE)
# name :string
# placements :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# accredited_provider_id :string
#
# Indexes
#
# index_providers_on_accredited_provider_id (accredited_provider_id)
#
class Provider < ApplicationRecord
include ServiceScopes
end
19 changes: 19 additions & 0 deletions app/models/school.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: schools
#
# id :uuid not null, primary key
# claims :boolean default(FALSE)
# name :string
# placements :boolean default(FALSE)
# urn :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_schools_on_urn (urn)
#
class School < ApplicationRecord
include ServiceScopes
end
12 changes: 12 additions & 0 deletions db/migrate/20231214141009_create_schools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateSchools < ActiveRecord::Migration[7.1]
def change
create_table :schools, id: :uuid do |t|
t.string :urn, index: true
t.string :name
t.boolean :placements, default: false
t.boolean :claims, default: false

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20231214142055_create_providers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateProviders < ActiveRecord::Migration[7.1]
def change
create_table :providers, id: :uuid do |t|
t.string :accredited_provider_id, index: true
t.string :name
t.boolean :placements, default: false
t.boolean :claims, default: false

t.timestamps
end
end
end
32 changes: 31 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2023_12_13_152028) do
ActiveRecord::Schema[7.1].define(version: 2023_12_14_142055) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand All @@ -21,6 +21,36 @@
t.datetime "updated_at", null: false
end

create_table "gias_schools", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "urn", null: false
t.string "name", null: false
t.string "postcode"
t.string "town"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["urn"], name: "index_gias_schools_on_urn", unique: true
end

create_table "providers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "accredited_provider_id"
t.string "name"
t.boolean "placements", default: false
t.boolean "claims", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["accredited_provider_id"], name: "index_providers_on_accredited_provider_id"
end

create_table "schools", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "urn"
t.string "name"
t.boolean "placements", default: false
t.boolean "claims", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["urn"], name: "index_schools_on_urn"
end

create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "first_name", null: false
t.string "last_name", null: false
Expand Down
22 changes: 22 additions & 0 deletions spec/factories/providers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: providers
#
# id :uuid not null, primary key
# claims :boolean default(FALSE)
# name :string
# placements :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# accredited_provider_id :string
#
# Indexes
#
# index_providers_on_accredited_provider_id (accredited_provider_id)
#
FactoryBot.define do
factory :provider do
name { Faker::Educator.university }
accredited_provider_id { SecureRandom.uuid }
end
end
22 changes: 22 additions & 0 deletions spec/factories/schools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: schools
#
# id :uuid not null, primary key
# claims :boolean default(FALSE)
# name :string
# placements :boolean default(FALSE)
# urn :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_schools_on_urn (urn)
#
FactoryBot.define do
factory :school do
name { Faker::Educator.secondary_school }
urn { SecureRandom.uuid }
end
end
23 changes: 23 additions & 0 deletions spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# == Schema Information
#
# Table name: providers
#
# id :uuid not null, primary key
# claims :boolean default(FALSE)
# name :string
# placements :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# accredited_provider_id :string
#
# Indexes
#
# index_providers_on_accredited_provider_id (accredited_provider_id)
#
require "rails_helper"

RSpec.describe Provider, type: :model do
context "scopes" do
include_examples "service scopes"
end
end
23 changes: 23 additions & 0 deletions spec/models/school_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# == Schema Information
#
# Table name: schools
#
# id :uuid not null, primary key
# claims :boolean default(FALSE)
# name :string
# placements :boolean default(FALSE)
# urn :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_schools_on_urn (urn)
#
require "rails_helper"

RSpec.describe School, type: :model do
context "scopes" do
include_examples "service scopes"
end
end
18 changes: 18 additions & 0 deletions spec/support/shared_examples/service_scopes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "rails_helper"

RSpec.shared_examples "service scopes" do
let!(:placements_on) { create(described_class.model_name.param_key.to_sym, placements: true) }
let!(:claims_on) { create(described_class.model_name.param_key.to_sym, claims: true) }

describe "#placements" do
it "only returns instances with placements on" do
expect(described_class.placements).to contain_exactly(placements_on)
end
end

describe "#claims" do
it "only returns instance with claims on" do
expect(described_class.claims).to contain_exactly(claims_on)
end
end
end

0 comments on commit 614e722

Please sign in to comment.