-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create tables placement and placement_type with tests and factories
- Loading branch information
Showing
9 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Placement < ApplicationRecord | ||
belongs_to :placement_type | ||
belongs_to :creator, class_name: "User" | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: placements | ||
# | ||
# id :bigint not null, primary key | ||
# placement_started_at :datetime not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# creator_id :bigint not null | ||
# placement_type_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_placements_on_creator_id (creator_id) | ||
# index_placements_on_placement_type_id (placement_type_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (creator_id => users.id) | ||
# fk_rails_... (placement_type_id => placement_types.id) | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class PlacementType < ApplicationRecord | ||
belongs_to :casa_org | ||
validates :name, presence: true | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: placement_types | ||
# | ||
# id :bigint not null, primary key | ||
# name :string not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# casa_org_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_placement_types_on_casa_org_id (casa_org_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (casa_org_id => casa_orgs.id) | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreatePlacementTypes < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :placement_types do |t| | ||
t.string :name, null: false | ||
t.references :casa_org, null: false, foreign_key: true | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreatePlacements < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :placements do |t| | ||
# Add table placement_type: name, casa_org_id. Add table placement: placement_id, casa_case_id, started_at, created_by_id (links to user table) | ||
t.datetime :placement_started_at, null: false | ||
t.references :placement_type, null: false, foreign_key: true | ||
t.references :creator, foreign_key: {to_table: :users}, null: false | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryBot.define do | ||
factory :placement_type do | ||
sequence(:name) { |n| "Placement Type #{n}" } | ||
casa_org | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :placement do | ||
placement_type | ||
placement_started_at { DateTime.now } | ||
creator { association :user } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Placement, type: :model do | ||
let!(:object) { create(:placement) } | ||
|
||
it { is_expected.to belong_to(:placement_type) } | ||
it { is_expected.to belong_to(:creator) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe PlacementType, type: :model do | ||
let!(:object) { create(:placement_type) } | ||
|
||
it { is_expected.to validate_presence_of(:name) } | ||
it { is_expected.to belong_to(:casa_org) } | ||
end |