Skip to content

Commit

Permalink
sort published drafts by last updated (#9995)
Browse files Browse the repository at this point in the history
* sort published drafts by last updated

* added functional test
  • Loading branch information
TildaDares authored Aug 21, 2021
1 parent 236381b commit d741da5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ def activity
# remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375
hidden_nids = Node.hidden_response_node_ids
notes = Node.where(type: 'note')
.includes(:revision)
.references(:node_revision)
.where('node.nid NOT IN (?)', hidden_nids + [0]) # in case hidden_nids is empty
.order('nid DESC')
.order('node_revisions.timestamp DESC')
.page(params[:page])
notes = notes.where('nid != (?)', blog.nid) if blog
notes = notes.where('node.nid != (?)', blog.nid) if blog

comments = Comment.joins(:node, :user)
.includes(:node)
Expand Down
23 changes: 23 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,29 @@ def test_get_rss_feed
end
end

test "drafts are sorted by last updated" do
UserSession.create(users(:jeff))
saved, node, revision = Node.new_note( title: 'Sort Drafts', draft: 'true', uid: 2, body: 'I have sorted drafts' )
revision_timestamp = revision.timestamp

assert_equal 3, node.status
assert_equal DateTime.now.to_i, revision_timestamp

updated_timestamp = nil

Timecop.freeze(Date.today + 1.day) do
get :publish_draft, params: { id: node.id }

updated_timestamp = DateTime.now.to_i
assert_response :redirect
node = assigns(:node)
assert_equal 1, node.status
end

assert_equal updated_timestamp, node.latest['timestamp']
assert_redirected_to '/notes/' + users(:jeff).username + '/' + (Date.today + 1.day).strftime('%m-%d-%Y') + '/' + node.title.parameterize
end

test 'co-author can publish the draft' do
perform_enqueued_jobs do
UserSession.create(users(:test_user))
Expand Down

0 comments on commit d741da5

Please sign in to comment.