Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/contact_topic_answer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ContactTopicAnswer < ApplicationRecord
belongs_to :case_contact
belongs_to :contact_topic, optional: true
acts_as_paranoid

has_one :casa_case, through: :case_contact
has_one :casa_org, through: :case_contact
Expand All @@ -17,6 +18,7 @@ class ContactTopicAnswer < ApplicationRecord
# Table name: contact_topic_answers
#
# id :bigint not null, primary key
# deleted_at :datetime
# selected :boolean default(FALSE), not null
# value :text
# created_at :datetime not null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDeletedAtToContactTopicAnswers < ActiveRecord::Migration[7.2]
def change
add_column :contact_topic_answers, :deleted_at, :datetime
end
end
3 changes: 2 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: 2026_02_11_001655) do
ActiveRecord::Schema[7.2].define(version: 2026_04_14_132818) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -259,6 +259,7 @@
t.boolean "selected", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "deleted_at"
t.index ["case_contact_id"], name: "index_contact_topic_answers_on_case_contact_id"
end

Expand Down
15 changes: 15 additions & 0 deletions spec/models/contact_topic_answer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@
create(:contact_topic_answer, value: Faker::Lorem.characters(number: 300))
}.not_to raise_error
end

it "soft deletes record instead of removing it from database" do
answer = create(:contact_topic_answer)

answer.destroy

expect(answer.deleted_at).not_to be_nil
expect(ContactTopicAnswer.with_deleted).to include(answer)
expect(ContactTopicAnswer.all).not_to include(answer)

answer.restore

expect(answer.deleted_at).to be_nil
expect(ContactTopicAnswer.all).to include(answer)
end
end
2 changes: 1 addition & 1 deletion spec/requests/contact_topic_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
answer = ContactTopicAnswer.last
expect(response_json[:id]).to eq answer.id
expect(response_json.keys)
.to contain_exactly(:id, :contact_topic_id, :value, :case_contact_id, :created_at, :updated_at, :selected)
.to contain_exactly(:id, :contact_topic_id, :value, :case_contact_id, :created_at, :updated_at, :selected, :deleted_at)
end

context "as casa_admin" do
Expand Down
Loading