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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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
test "dashboard_search returns matching tags and nodes grouped separately" do
node = Node.root.children.create!(:slug => "dashboard_search_test")
node.find_or_create_draft(User.find_by_login("aaron"))
node.draft.update(:title => "Biometrics Workshop")
node.draft.tag_list = "biometrics-workshop"
node.draft.save!
login_as :quentin
get :dashboard_search, params: { :search_term => "biometr" }, :format => :json
json = JSON.parse(response.body)
assert json["tags"].any? { |t| t["name"] == "biometrics-workshop" }
assert json["nodes"].any? { |n| n["title"] == "Biometrics Workshop" }
end
test "dashboard_search returns empty results for a blank term" do
login_as :quentin
get :dashboard_search, params: { :search_term => "" }, :format => :json
json = JSON.parse(response.body)
assert_equal [], json["tags"]
assert_equal [], json["nodes"]
end
end
|