Commit ce416ccc by wajeeha-khalid

Merge pull request #147 from edx/jia/MA-1190

MA-1190; Thread PUT -  update thread read status
parents f0056cca cdab7cd7
......@@ -54,10 +54,15 @@ put "#{APIPREFIX}/threads/:thread_id" do |thread_id|
filter_blocked_content params["body"]
thread.update_attributes(params.slice(*%w[title body pinned closed commentable_id group_id thread_type]))
if params["user_id"] and value_to_boolean(params["read"])
user = User.only([:id, :username, :read_states]).find_by(external_id: params["user_id"])
user.mark_as_read(thread) if user
end
if thread.errors.any?
error 400, thread.errors.full_messages.to_json
else
presenter = ThreadPresenter.factory(thread, nil)
presenter = ThreadPresenter.factory(thread, user || nil)
presenter.to_hash.to_json
end
end
......
......@@ -576,7 +576,7 @@ describe "app" do
before(:each) { init_without_subscriptions }
it "update information of comment thread" do
it "update information of comment thread and don't mark thread as read" do
thread = CommentThread.first
comment = thread.comments.first
comment.endorsed = true
......@@ -592,7 +592,22 @@ describe "app" do
comment.reload
comment.endorsed.should == false
comment.endorsement.should == nil
check_thread_result_json(nil, changed_thread, parse(last_response.body))
check_unread_thread_result_json(changed_thread, parse(last_response.body))
end
it "update information of comment thread and mark thread as read" do
thread = CommentThread.first
user = create_test_user(42)
put "/api/v1/threads/#{thread.id}", body: "new body", title: "new title", commentable_id: "new_commentable_id", thread_type: "question", read: true, user_id: user.id
last_response.should be_ok
changed_thread = CommentThread.find(thread.id)
changed_thread.body.should == "new body"
changed_thread.title.should == "new title"
changed_thread.commentable_id.should == "new_commentable_id"
changed_thread.thread_type.should == "question"
user = User.find_by(external_id: user.id)
json_response = parse(last_response.body)
check_thread_result_json(user, changed_thread, json_response)
json_response["read"].should == true
end
it "returns 400 when the thread does not exist" do
put "/api/v1/threads/does_not_exist", body: "new body", title: "new title"
......
......@@ -282,6 +282,12 @@ def check_thread_result_json(user, thread, json_response)
check_thread_result(user, thread, json_response, true)
end
def check_unread_thread_result_json(thread, json_response)
# when thread is unread we do not check if thread matches the user read states data
# and explicitly asserts `read` to false; hence pass user=nil
check_thread_result(nil, thread, json_response, true)
end
def check_thread_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is_json=false, recursive=false)
case thread.thread_type
when "discussion"
......
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