summaryrefslogtreecommitdiff
path: root/test/controllers/admin_controller_test.rb
blob: 13cc1bb0e2a93557c48801cf1e038880255c4bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'test_helper'

class AdminControllerTest < ActionController::TestCase
  test "current drafts includes nodes with only an autosave" do
    node = Node.root.children.create!(:slug => "admin_autosave_only")
    node.lock_for_editing!(User.find_by_login("aaron"))
    node.autosave!({title: "in progress"}, User.find_by_login("aaron"))
    node.save_draft!(User.find_by_login("aaron"))
    node.publish_draft!
    node.lock_for_editing!(User.find_by_login("aaron"))
    node.autosave!({title: "editing again"}, User.find_by_login("aaron"))

    login_as :quentin
    get :index
    assert_includes assigns(:drafts), node
  end

  test "my work list shows each matching node only once, even with several revisions by the same user" do
    login_as :quentin
    user = User.find_by_login("quentin")
    node = Node.root.children.create!(:slug => "dedup_test")
    node.lock_for_editing!(user)
    node.autosave!({:title => "v1"}, user)
    node.save_draft!(user)
    node.publish_draft!
    node.lock_for_editing!(user)
    node.autosave!({:title => "v2"}, user)
    node.save_draft!(user)
    node.publish_draft!
    # three pages now exist on this node, all touched by quentin --
    # without DISTINCT, the join would return this node three times

    get :index
    matches = assigns(:mynodes).select { |n| n.id == node.id }
    assert_equal 1, matches.length
  end
end