Merge branch 'master' into clintonb/replace-tire

This commit is contained in:
Toby Lawrence 2016-08-01 09:48:28 -04:00 коммит произвёл GitHub
Родитель 56b61a13ef c309a7dee4
Коммит d0835ab2e8
9 изменённых файлов: 69 добавлений и 48 удалений

Просмотреть файл

@ -29,7 +29,7 @@ gem 'mongoid_magic_counter_cache'
gem 'will_paginate_mongoid', "~>2.0"
gem 'rdiscount'
gem 'nokogiri', "~>1.6.7.2"
gem 'nokogiri', "~>1.6.8"
gem 'elasticsearch', '~> 0.4'
gem 'elasticsearch-model', '~> 0.1.8'

Просмотреть файл

@ -90,7 +90,7 @@ GEM
listen (0.5.0)
method_source (0.8)
mime-types (2.6.1)
mini_portile2 (2.0.0)
mini_portile2 (2.1.0)
minitest (5.8.1)
mongo (2.1.1)
bson (~> 3.0)
@ -108,10 +108,12 @@ GEM
multi_json (1.11.2)
multipart-post (2.0.0)
netrc (0.10.3)
newrelic_rpm (3.15.0.314)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
newrelic_rpm (3.16.0.318)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
origin (2.1.1)
pkg-config (1.1.7)
protected_attributes (1.1.3)
activemodel (>= 4.0.1, < 5.0)
pry (0.9.10)
@ -199,7 +201,7 @@ DEPENDENCIES
mongoid-tree!
mongoid_magic_counter_cache
newrelic_rpm
nokogiri (~> 1.6.7.2)
nokogiri (~> 1.6.8)
protected_attributes
pry
pry-nav
@ -216,6 +218,3 @@ DEPENDENCIES
webmock (~> 1.22)
will_paginate_mongoid (~> 2.0)
yajl-ruby
BUNDLED WITH
1.11.2

Просмотреть файл

@ -57,16 +57,10 @@ 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]))
# user_id is the owner for a thread, requested_user_id is the user requesting to update said thread
if params["requested_user_id"] and value_to_boolean(params["read"])
user = User.only([:id, :username, :read_states]).find_by(external_id: params["requested_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, user || nil)
presenter = ThreadPresenter.factory(thread, nil)
presenter.to_hash.to_json
end
end

Просмотреть файл

@ -74,3 +74,8 @@ put "#{APIPREFIX}/users/:user_id" do |user_id|
user.to_hash.to_json
end
end
post "#{APIPREFIX}/users/:user_id/read" do |user_id|
user.mark_as_read(source)
user.reload.to_hash.to_json
end

Просмотреть файл

@ -141,7 +141,14 @@ class Comment < Content
end
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
def course_context?

Просмотреть файл

@ -1,3 +1,5 @@
require 'new_relic/agent/method_tracer'
module ThreadUtils
def self.get_endorsed(threads)
@ -39,9 +41,10 @@ module ThreadUtils
read_states
end
extend self
class << self
include ::NewRelic::Agent::MethodTracer
add_method_tracer :get_read_states
add_method_tracer :get_endorsed
end
end

Просмотреть файл

@ -614,7 +614,7 @@ describe "app" do
before(:each) { init_without_subscriptions }
it "update information of comment thread and don't mark thread as read" do
it "updates information of comment thread" do
thread = CommentThread.first
comment = thread.comments.first
comment.endorsed = true
@ -632,35 +632,6 @@ describe "app" do
comment.endorsement.should == nil
check_unread_thread_result_json(changed_thread, parse(last_response.body))
end
it "update information of comment thread and mark thread as read for owner user" do
thread = CommentThread.first
put "/api/v1/threads/#{thread.id}", body: "new body", title: "new title", commentable_id: "new_commentable_id", thread_type: "question", read: true, requested_user_id: thread.author.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: thread.author.id)
json_response = parse(last_response.body)
check_thread_result_json(user, changed_thread, json_response)
json_response["read"].should == true
end
it "update information of comment thread and mark thread as read for non-owner user" 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, requested_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"
last_response.status.should == 400

Просмотреть файл

@ -361,5 +361,22 @@ describe "app" do
include_examples "unicode data"
end
describe "POST /api/v1/users/:user_id/read" do
before(:each) { setup_10_threads }
it "marks a thread as read for the user" do
thread = @threads["t0"]
user = create_test_user(42)
post "/api/v1/users/#{user.external_id}/read", source_type: "thread", source_id: thread.id
last_response.should be_ok
user.reload
read_states = user.read_states.where(course_id: thread.course_id).to_a
read_date = read_states.first.last_read_times[thread.id.to_s]
read_date.should >= thread.updated_at
end
end
end
end

Просмотреть файл

@ -36,6 +36,14 @@ describe Comment do
expect(comment.context).to eq("course")
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
describe '#course_context?' do
@ -52,6 +60,14 @@ describe Comment do
expect(comment.course_context?).to be_true
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
describe '#standalone_context?' do
@ -68,6 +84,15 @@ describe Comment do
expect(comment.standalone_context?).to be_false
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
describe '#child_count' do