Skip to content

Commit

Permalink
Add Claim Activity model
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Dec 17, 2024
1 parent a1e9b2b commit 3762e90
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 1 deletion.
27 changes: 27 additions & 0 deletions app/models/claims/claim_activity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: claim_activities
#
# id :uuid not null, primary key
# action :string
# record_type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# record_id :uuid not null
# user_id :uuid not null
#
# Indexes
#
# index_claim_activities_on_record (record_type,record_id)
# index_claim_activities_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
class Claims::ClaimActivity < ApplicationRecord
belongs_to :user
belongs_to :record, polymorphic: true

enum :action, { payment_delivered: "payment_delivered" }
end
8 changes: 8 additions & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,11 @@ shared:
- claim_id
- created_at
- updated_at
:claim_activities:
- id
- action
- user_id
- record_type
- record_id
- created_at
- updated_at
11 changes: 11 additions & 0 deletions db/migrate/20241217132410_create_claims_claim_activities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateClaimsClaimActivities < ActiveRecord::Migration[7.2]
def change
create_table :claim_activities, id: :uuid do |t|
t.string :action
t.references :user, null: false, foreign_key: true, type: :uuid
t.references :record, null: false, polymorphic: true, type: :uuid

t.timestamps
end
end
end
14 changes: 13 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.2].define(version: 2024_12_16_161048) do
ActiveRecord::Schema[7.2].define(version: 2024_12_17_132410) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "plpgsql"
Expand Down Expand Up @@ -83,6 +83,17 @@
t.index ["user_id", "user_type"], name: "user_index"
end

create_table "claim_activities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "action"
t.uuid "user_id", null: false
t.string "record_type", null: false
t.uuid "record_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["record_type", "record_id"], name: "index_claim_activities_on_record"
t.index ["user_id"], name: "index_claim_activities_on_user_id"
end

create_table "claim_windows", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "academic_year_id", null: false
t.date "starts_on", null: false
Expand Down Expand Up @@ -523,6 +534,7 @@

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "claim_activities", "users"
add_foreign_key "claim_windows", "academic_years"
add_foreign_key "claims", "providers"
add_foreign_key "claims", "schools"
Expand Down
32 changes: 32 additions & 0 deletions spec/factories/claims/claim_activities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# == Schema Information
#
# Table name: claim_activities
#
# id :uuid not null, primary key
# action :string
# record_type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# record_id :uuid not null
# user_id :uuid not null
#
# Indexes
#
# index_claim_activities_on_record (record_type,record_id)
# index_claim_activities_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
factory :claim_activity, class: "Claims::ClaimActivity" do
association :user, factory: :claims_support_user

trait :payment_delivered do
action { "payment_delivered" }

association :record, factory: :claims_payment
end
end
end
29 changes: 29 additions & 0 deletions spec/models/claims/claim_activity_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# == Schema Information
#
# Table name: claim_activities
#
# id :uuid not null, primary key
# action :string
# record_type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# record_id :uuid not null
# user_id :uuid not null
#
# Indexes
#
# index_claim_activities_on_record (record_type,record_id)
# index_claim_activities_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
require "rails_helper"

RSpec.describe Claims::ClaimActivity, type: :model do
describe "associations" do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:record) }
end
end

0 comments on commit 3762e90

Please sign in to comment.