summaryrefslogtreecommitdiff
path: root/test/controllers/node_actions_controller_test.rb
blob: 8f0104d32573bcd3fd2e8c7337f7a925e7107f43 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'test_helper'

class NodeActionsControllerTest < ActionController::TestCase

  def setup
    login_as :quentin
  end

  def logged_node slug, title
    node = Node.root.children.create!(:slug => slug)
    Globalize.with_locale(I18n.default_locale) { node.draft.update!(:title => title) }
    node
  end

  test "index renders" do
    get :index
    assert_response :success
  end

  test "index filters by node" do
    node_a = logged_node("log_filter_a", "Alpha Subject")
    node_b = logged_node("log_filter_b", "Beta Subject")
    NodeAction.record!(:node => node_a, :action => "create", :user => users(:quentin))
    NodeAction.record!(:node => node_b, :action => "create", :user => users(:quentin))

    get :index, params: { :node_id => node_a.id }

    assert_response :success
    assert_includes    @response.body, "Alpha Subject"
    assert_not_includes @response.body, "Beta Subject"
  end

  test "index filters by user" do
    node = logged_node("log_filter_user", "Gamma Subject")
    NodeAction.record!(:node => node, :action => "create", :user => users(:quentin))

    get :index, params: { :user_id => users(:quentin).id }
    assert_includes @response.body, "Gamma Subject"

    other = User.where.not(:id => users(:quentin).id).first
    get :index, params: { :user_id => other.id }
    assert_not_includes @response.body, "Gamma Subject"
  end

  test "index requires login" do
    session[:user_id] = nil
    @controller.instance_variable_set(:@current_user, nil)
    get :index
    assert_response :redirect
  end

  test "zooming on a node finds subtree entries recorded at its ancestor" do
    parent = Node.root.children.create!(:slug => "zoom_participant_parent")
    child  = parent.children.create!(:slug => "zoom_participant_child")
    parent.trash!(users(:quentin))

    get :index, params: { :node_id => child.id }
    assert_response :success
    assert_includes assigns(:actions).map(&:action), "trash"
  end

  test "zooming on an asset finds the publishes that changed it" do
    node  = Node.root.children.create!(:slug => "asset_zoom_node")
    asset = Asset.create!(:name => "Zoomable", :upload_content_type => "image/png")
    node.publish_draft!(users(:quentin))
    node.lock_for_editing!(users(:quentin))
    node.create_new_draft(users(:quentin))
    node.draft.related_assets.create!(:asset => asset)
    node.publish_draft!(users(:quentin))

    get :index, params: { :asset_id => asset.id }
    assert_response :success
    assert_equal 1, assigns(:actions).count
    assert_equal "publish", assigns(:actions).first.action
  end
end