diff --git a/app/models/answer.rb b/app/models/answer.rb index c139e04..ebc583c 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -7,11 +7,13 @@ belongs_to :plan has_and_belongs_to_many :question_options, join_table: "answers_question_options" + has_many :notes + ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :text, :plan_id, :question_id, :user_id, :question_option_ids, - :question, :user, :plan, :question_options, + :question, :user, :plan, :question_options, :notes, :note_ids, :as => [:default, :admin] ## diff --git a/app/models/note.rb b/app/models/note.rb index fe23a76..74b3078 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -9,4 +9,6 @@ # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :text, :user_id, :answer_id, :archived, :archived_by, :answer, :user, :as => [:default, :admin] + + validates :text, :answer, :user, presence: true end diff --git a/test/unit/answer_test.rb b/test/unit/answer_test.rb index 14b9d3e..4766440 100644 --- a/test/unit/answer_test.rb +++ b/test/unit/answer_test.rb @@ -7,7 +7,10 @@ @plan = plan_scaffold - q = @plan.template.questions.select{|q| !q.question_format.option_based }.first + q = @plan.template.questions.select{|q| !q.question_format.option_based }.last + q = Question.create(text: 'Answer Testing', number: 9, + section: @plan.template.phases.first.sections.first, + question_format: QuestionFormat.find_by(option_based: false)) @answer = Answer.create(user: @user, plan: @plan, question: q, text: 'Testing') end @@ -105,6 +108,12 @@ # --------------------------------------------------- test "can manage belongs_to relationship with Question" do q = @plan.template.phases.first.sections.first.questions.last - verify_belongs_to_relationship(@question, q) + verify_belongs_to_relationship(@answer, q) + end + + # --------------------------------------------------- + test "can manage has_many relationship with Notes" do + note = Note.new(text: 'Test Note', user: @user) + verify_has_many_relationship(@answer, note, @answer.notes.count) end end