Skip to content

Commit

Permalink
Changes for renaming answer to CustomForm::SubmittedAnswer (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaiyanidhi authored Jun 25, 2024
1 parent 2cfb160 commit 0e60a29
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: answers
# Table name: submitted_answers
#
# id :bigint not null, primary key
# question_snapshot :json not null
Expand All @@ -12,18 +12,20 @@
#
# Indexes
#
# index_answers_on_question_id (question_id)
# index_answers_on_user_id (user_id)
# index_submitted_answers_on_question_id (question_id)
# index_submitted_answers_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (question_id => questions.id)
# fk_rails_... (user_id => users.id)
#
class Answer < ApplicationRecord
belongs_to :question
belongs_to :user
module CustomForm
class SubmittedAnswer < ApplicationRecord
belongs_to :question
belongs_to :user

has_one :form, through: :question
has_one :organization, through: :form
has_one :form, through: :question
has_one :organization, through: :form
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameAnswersToSubmittedAnswers < ActiveRecord::Migration[7.1]
def change
rename_table :answers, :submitted_answers
end
end
28 changes: 14 additions & 14 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryBot.define do
factory :answer do
factory :submitted_answer, class: "custom_form/submitted_answer" do
value { JSON.dump Faker::Lorem.sentence }
question_snapshot { question.snapshot }
question
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class AnswerTest < ActiveSupport::TestCase
class CustomForm::SubmittedAnswerTest < ActiveSupport::TestCase
context "associations" do
should belong_to(:question)
should belong_to(:user)
Expand Down

0 comments on commit 0e60a29

Please sign in to comment.