Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

narrow content_followed_in_period to notes by default #5568

Merged
merged 4 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def questions
Node.questions.where(status: 1, uid: id)
end

def content_followed_in_period(start_time, end_time)
def content_followed_in_period(start_time, end_time, node_type = 'note')
tagnames = TagSelection.where(following: true, user_id: uid)
node_ids = []
tagnames.each do |tagname|
Expand All @@ -253,6 +253,7 @@ def content_followed_in_period(start_time, end_time)
.includes(:revision, :tag)
.references(:node_revision)
.where('node.status = 1')
.where(type: node_type)
.where("(created >= #{start_time.to_i} AND created <= #{end_time.to_i}) OR (timestamp >= #{start_time.to_i} AND timestamp <= #{end_time.to_i})")
.order('node_revisions.timestamp DESC')
.distinct
Expand Down
20 changes: 15 additions & 5 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,22 @@ class UserTest < ActiveSupport::TestCase
assert !users(:bob).has_tag('test:no')
end

test 'returns nodes created in given period of time' do
test 'returns notes created in given period of time' do
bob = users(:bob)
node_count = 5
nodes_fix = [1,2,8,9,15]
count_return = bob.content_followed_in_period(2.hours.ago,Time.now).count
nodes_time = bob.content_followed_in_period(2.hours.ago,Time.now).pluck(:nid)
node_count = 4
nodes_fix = [1 ,8 ,9 , 15]
count_return = bob.content_followed_in_period(2.hours.ago, Time.now).count
nodes_time = bob.content_followed_in_period(2.hours.ago, Time.now).pluck(:nid)
assert_equal node_count, count_return
assert_equal nodes_fix, nodes_time.sort
end

test 'returns wikis updated in given period of time' do
bob = users(:bob)
node_count = 1
nodes_fix = [2]
count_return = bob.content_followed_in_period(2.hours.ago, Time.now, 'page').count
nodes_time = bob.content_followed_in_period(2.hours.ago, Time.now, 'page').pluck(:nid)
assert_equal node_count, count_return
assert_equal nodes_fix, nodes_time.sort
end
Expand Down