Commit ef5862be by Diana Huang

Handle comment context in cases of missing parent thread.

TNL-4944
parent f471f96d
...@@ -141,7 +141,14 @@ class Comment < Content ...@@ -141,7 +141,14 @@ class Comment < Content
end end
def context def context
self.comment_thread_id ? self.comment_thread.context : nil if self.comment_thread_id
t = CommentThread.find self.comment_thread_id
if t
t.context
end
end
rescue Mongoid::Errors::DocumentNotFound
nil
end end
def course_context? def course_context?
......
...@@ -36,6 +36,14 @@ describe Comment do ...@@ -36,6 +36,14 @@ describe Comment do
expect(comment.context).to eq("course") expect(comment.context).to eq("course")
end end
end end
context 'without valid parent thread' do
it 'returns nil' do
comment = make_comment(author, course_thread, "comment")
comment.comment_thread_id = 'not a thread'
expect(comment.context).to eq(nil)
end
end
end end
describe '#course_context?' do describe '#course_context?' do
...@@ -52,6 +60,14 @@ describe Comment do ...@@ -52,6 +60,14 @@ describe Comment do
expect(comment.course_context?).to be_true expect(comment.course_context?).to be_true
end end
end end
context 'without valid parent thread' do
it 'returns false' do
comment = make_comment(author, course_thread, "comment")
comment.comment_thread_id = 'not a thread'
expect(comment.course_context?).to be_false
end
end
end end
describe '#standalone_context?' do describe '#standalone_context?' do
...@@ -68,6 +84,15 @@ describe Comment do ...@@ -68,6 +84,15 @@ describe Comment do
expect(comment.standalone_context?).to be_false expect(comment.standalone_context?).to be_false
end end
end end
context 'without valid parent thread' do
it 'returns false' do
comment = make_comment(author, course_thread, "comment")
comment.comment_thread_id = 'not a thread'
expect(comment.standalone_context?).to be_false
end
end
end end
describe '#child_count' do describe '#child_count' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment