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

Make the /wiki page display unique results #9592

Merged
merged 3 commits into from
May 7, 2021
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
12 changes: 6 additions & 6 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def index
.references(:node_revisions)
.group('node_revisions.nid, node_revisions.vid')
.order(order_string)
.where("node_revisions.status = 1 AND node.status = 1 AND type = 'page'"), items: 10)
.where("node_revisions.status = 1 AND node.status = 1 AND type = 'page'"), items: 10).uniq

@paginated = true
end
Expand All @@ -353,7 +353,7 @@ def stale
.references(:node_revisions)
.group('node_revisions.nid, node_revisions.vid')
.order('node_revisions.timestamp ASC')
.where("node_revisions.status = 1 AND node.status = 1 AND type = 'page'"), items: 10)
.where("node_revisions.status = 1 AND node.status = 1 AND type = 'page'"), items: 10).uniq

@paginated = true
render template: 'wiki/index'
Expand All @@ -365,16 +365,16 @@ def popular
.joins(:revision)
.group('node_revisions.nid, node_revisions.vid')
.order('node_revisions.timestamp DESC')
.where("node.status = 1 AND node_revisions.status = 1 AND node.nid != 259 AND (type = 'page' OR type = 'tool' OR type = 'place')")
.sort_by(&:views).reverse
.where("node.status = 1 AND node_revisions.status = 1 AND node.nid != 259 AND type = 'page'")
.sort_by(&:views).reverse.uniq
render template: 'wiki/index'
end

def liked
@title = I18n.t('wiki_controller.well_liked_wiki_pages')
@wikis = Node.limit(40)
.order('node.cached_likes DESC')
.where("status = 1 AND nid != 259 AND (type = 'page' OR type = 'tool' OR type = 'place') AND cached_likes >= 0")
.where("status = 1 AND nid != 259 AND (type = 'page') AND cached_likes >= 0").uniq

render template: 'wiki/index'
end
Expand Down Expand Up @@ -501,7 +501,7 @@ def author
@title = @user.name
@pagy, @wikis = pagy(Node
.order('nid DESC')
.where("uid = ? AND type = 'page' OR type = 'place' OR type = 'tool' AND status = 1", @user.uid), items: 24)
.where("uid = ? AND type = 'page' AND status = 1", @user.uid), items: 24)
render template: 'wiki/index'
end
end
7 changes: 7 additions & 0 deletions test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def teardown
assert assigns(:wikis).each_cons(2).all?{|i,j| "j.node_revisions.title" >= "i.node_revisions.title" }
end

test 'should display unique wikis' do
get :index

assert_response :success
assert assigns(:wikis).each_cons(2).all?{|i,j| "j.node_revisions.id" != "i.node_revisions.id" }
end

test 'should paginate the wikis' do
12.times{
post :create,
Expand Down