summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/controllers/assets_controller_test.rb41
-rw-r--r--test/controllers/node_actions_controller_test.rb10
-rw-r--r--test/controllers/nodes_controller_test.rb29
-rw-r--r--test/models/node_action_test.rb20
-rw-r--r--test/models/node_test.rb10
5 files changed, 109 insertions, 1 deletions
diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb
index f834541..05fc6de 100644
--- a/test/controllers/assets_controller_test.rb
+++ b/test/controllers/assets_controller_test.rb
@@ -92,6 +92,47 @@ class AssetsControllerTest < ActionController::TestCase
92 end 92 end
93 end 93 end
94 94
95 # --- create with attach ---
96
97 test "create with node_id attaches the asset to the node's draft" do
98 node = Node.root.children.create!(:slug => "asset_attach_target")
99
100 post :create, params: { asset: { name: 'Attach me' }, node_id: node.id }
101
102 assert_response :redirect
103 asset = Asset.last
104 assert_includes node.draft.assets.reload, asset
105 assert_match /attached/, flash[:notice]
106 end
107
108 test "create against a foreign-locked node keeps the asset but refuses the attach" do
109 node = Node.root.children.create!(:slug => "asset_attach_locked")
110 node.lock_for_editing!(users(:aaron))
111
112 assert_difference 'Asset.count', 1 do
113 post :create, params: { asset: { name: 'Orphaned for now' }, node_id: node.id }
114 end
115
116 assert_empty node.draft.assets.reload
117 assert_equal node_path(node), flash[:locked_node_path]
118 assert_equal "aaron", flash[:locked_by]
119 end
120
121 test "create with headline against a page that has one keeps the incumbent and warns" do
122 node = Node.root.children.create!(:slug => "asset_attach_headline")
123 incumbent = Asset.create!(:name => 'Incumbent', :upload_content_type => 'image/png')
124 node.draft.related_assets.create!(:asset => incumbent, :headline => true)
125
126 uploaded = Rack::Test::UploadedFile.new(
127 Rails.root.join('test', 'fixtures', 'files', 'test_image.png'), 'image/png')
128 post :create, params: { asset: { name: 'Challenger', upload: uploaded },
129 node_id: node.id, headline: "1" }
130
131 assert_includes node.draft.assets.reload, Asset.last
132 assert_equal incumbent, node.draft.reload.headline_asset
133 assert_equal node_path(node), flash[:headline_kept_path]
134 end
135
95 # --- edit --- 136 # --- edit ---
96 137
97 test "get edit" do 138 test "get edit" do
diff --git a/test/controllers/node_actions_controller_test.rb b/test/controllers/node_actions_controller_test.rb
index 8bc68ec..cfc5a31 100644
--- a/test/controllers/node_actions_controller_test.rb
+++ b/test/controllers/node_actions_controller_test.rb
@@ -48,4 +48,14 @@ class NodeActionsControllerTest < ActionController::TestCase
48 get :index 48 get :index
49 assert_response :redirect 49 assert_response :redirect
50 end 50 end
51
52 test "zooming on a node finds subtree entries recorded at its ancestor" do
53 parent = Node.root.children.create!(:slug => "zoom_participant_parent")
54 child = parent.children.create!(:slug => "zoom_participant_child")
55 parent.trash!(users(:quentin))
56
57 get :index, params: { :node_id => child.id }
58 assert_response :success
59 assert_includes assigns(:actions).map(&:action), "trash"
60 end
51end 61end
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb
index 55da524..d777108 100644
--- a/test/controllers/nodes_controller_test.rb
+++ b/test/controllers/nodes_controller_test.rb
@@ -79,6 +79,35 @@ class NodesControllerTest < ActionController::TestCase
79 end 79 end
80 end 80 end
81 81
82 test "create with asset_id attaches the asset to the new draft, as headline when asked" do
83 login_as :quentin
84 asset = Asset.create!(:name => 'Birth attachment', :upload_content_type => 'image/png')
85
86 post :create, params: { :kind => "generic", :parent_id => Node.root.id,
87 :title => "Born Attached",
88 :asset_id => asset.id, :asset_headline => "1" }
89
90 assert_response :redirect
91 node = Node.last
92 assert_includes node.draft.assets, asset
93 assert_equal asset, node.draft.headline_asset
94 assert_match /attached/, flash[:notice]
95 end
96
97 test "the attach notice survives the redirect into the editor" do
98 login_as :quentin
99 asset = Asset.create!(:name => 'Flash survivor', :upload_content_type => 'image/png')
100
101 post :create, params: { :kind => "generic", :parent_id => Node.root.id,
102 :title => "Notice Carrier", :asset_id => asset.id }
103 assert_redirected_to edit_node_path(Node.last)
104
105 get :edit, params: { :id => Node.last.id }
106 assert_response :success
107 assert_match /attached/, flash[:notice]
108 assert_no_match /ready to edit/, flash[:notice]
109 end
110
82 test "editing a node" do 111 test "editing a node" do
83 login_as :quentin 112 login_as :quentin
84 113
diff --git a/test/models/node_action_test.rb b/test/models/node_action_test.rb
index b177cca..849b36f 100644
--- a/test/models/node_action_test.rb
+++ b/test/models/node_action_test.rb
@@ -118,11 +118,29 @@ class NodeActionTest < ActiveSupport::TestCase
118 118
119 test "record! passes provenance and historical timestamps through" do 119 test "record! passes provenance and historical timestamps through" do
120 long_ago = 2.years.ago 120 long_ago = 2.years.ago
121 action = NodeAction.record!(:node => nil, :action => "publish", 121 node = Node.root.children.create!(:slug => "provenance_backfill_test")
122 action = NodeAction.record!(:node => node, :action => "publish",
122 :occurred_at => long_ago, 123 :occurred_at => long_ago,
123 :inferred_from => "from_page_revision") 124 :inferred_from => "from_page_revision")
124 125
125 assert_equal "from_page_revision", action.inferred_from 126 assert_equal "from_page_revision", action.inferred_from
126 assert_in_delta long_ago.to_f, action.occurred_at.to_f, 1.0 127 assert_in_delta long_ago.to_f, action.occurred_at.to_f, 1.0
127 end 128 end
129
130
131 test "record! with participants: writes one action_participant per subject" do
132 n1, n2 = Node.root.children.create!(:slug => "participant_a"), Node.root.children.create!(:slug => "participant_b")
133 action = NodeAction.record!(:participants => [n1, n2], :action => "trash", :user => users(:quentin))
134 assert_equal [n1, n2], action.action_participants.map(&:subject)
135 end
136
137 test "record! with node: alone still writes exactly one participant" do
138 node = Node.root.children.create!(:slug => "participant_sugar")
139 action = NodeAction.record!(:node => node, :action => "create", :user => users(:quentin))
140 assert_equal [node], action.action_participants.map(&:subject)
141 end
142
143 test "record! refuses an empty participant set" do
144 assert_raises(ArgumentError) { NodeAction.record!(:action => "create", :user => users(:quentin)) }
145 end
128end 146end
diff --git a/test/models/node_test.rb b/test/models/node_test.rb
index ba38340..0083b08 100644
--- a/test/models/node_test.rb
+++ b/test/models/node_test.rb
@@ -756,6 +756,16 @@ class NodeTest < ActiveSupport::TestCase
756 assert node.valid? 756 assert node.valid?
757 end 757 end
758 758
759 test "trash! records every subtree node as a participant, not just the root" do
760 parent = Node.root.children.create!(:slug => "trash_participants_parent")
761 child = parent.children.create!(:slug => "trash_participants_child")
762
763 parent.trash!(users(:quentin))
764
765 action = parent.node_actions.where(:action => "trash").last
766 assert_includes action.action_participants.map(&:subject), child
767 end
768
759 test "destroying a node with children is refused" do 769 test "destroying a node with children is refused" do
760 parent = Node.root.children.create!(:slug => "destroy_guard_parent") 770 parent = Node.root.children.create!(:slug => "destroy_guard_parent")
761 parent.children.create!(:slug => "destroy_guard_child") 771 parent.children.create!(:slug => "destroy_guard_child")