summaryrefslogtreecommitdiff
path: root/test/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'test/controllers')
-rw-r--r--test/controllers/assets_controller_test.rb34
-rw-r--r--test/controllers/content_controller_test.rb2
2 files changed, 27 insertions, 9 deletions
diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb
index 467e1a68..aa3e00e6 100644
--- a/test/controllers/assets_controller_test.rb
+++ b/test/controllers/assets_controller_test.rb
@@ -94,7 +94,7 @@ class AssetsControllerTest < ActionController::TestCase
94 94
95 # --- create with attach --- 95 # --- create with attach ---
96 96
97 test "create with node_id attaches the asset to the node's draft" do 97 test "create with node_id attaches the asset to an existing draft" do
98 node = Node.root.children.create!(:slug => "asset_attach_target") 98 node = Node.root.children.create!(:slug => "asset_attach_target")
99 99
100 post :create, params: { asset: { name: 'Attach me' }, node_id: node.id } 100 post :create, params: { asset: { name: 'Attach me' }, node_id: node.id }
@@ -102,7 +102,21 @@ class AssetsControllerTest < ActionController::TestCase
102 assert_response :redirect 102 assert_response :redirect
103 asset = Asset.last 103 asset = Asset.last
104 assert_includes node.draft.assets.reload, asset 104 assert_includes node.draft.assets.reload, asset
105 assert_equal I18n.t("flash.assets.attached", :title => node.title), flash[:notice] 105 assert_equal I18n.t("flash.assets.attached_to_draft", :title => node.title), flash[:notice]
106 end
107
108 test "create with node_id creates a draft when none is pending" do
109 node = Node.root.children.create!(:slug => "asset_attach_no_draft")
110 node.publish_draft!(users(:quentin))
111 assert_nil node.reload.draft
112
113 post :create, params: { asset: { name: 'Attach me too' }, node_id: node.id }
114
115 node.reload
116 assert_includes node.draft.assets.reload, Asset.last
117 assert_empty node.head.assets.reload
118 assert_equal users(:quentin), node.draft.editor
119 assert_equal I18n.t("flash.assets.attached_new_draft", :title => node.title), flash[:notice]
106 end 120 end
107 121
108 test "create against a foreign-locked node keeps the asset but refuses the attach" do 122 test "create against a foreign-locked node keeps the asset but refuses the attach" do
@@ -133,14 +147,16 @@ class AssetsControllerTest < ActionController::TestCase
133 assert_equal node_path(node), flash[:headline_kept_path] 147 assert_equal node_path(node), flash[:headline_kept_path]
134 end 148 end
135 149
136 test "create with node_id writes an asset_create and an asset_attach entry" do 150 test "create with node_id writes only an asset_create entry" do
137 node = Node.root.children.create!(:slug => "asset_log_pair") 151 node = Node.root.children.create!(:slug => "asset_log_single")
138 assert_difference 'NodeAction.where(:action => "asset_create").count' do 152
139 assert_difference 'NodeAction.where(:action => "asset_attach").count' do 153 assert_difference 'NodeAction.count', 1 do
140 post :create, params: { asset: { name: 'Logged twice' }, node_id: node.id } 154 post :create, params: { asset: { name: 'Logged once' }, node_id: node.id }
141 end
142 end 155 end
143 assert_equal users(:quentin), NodeAction.last.user 156
157 action = NodeAction.last
158 assert_equal "asset_create", action.action
159 assert_equal users(:quentin), action.user
144 end 160 end
145 161
146 # --- edit --- 162 # --- edit ---
diff --git a/test/controllers/content_controller_test.rb b/test/controllers/content_controller_test.rb
index 39fe276b..482c1ddf 100644
--- a/test/controllers/content_controller_test.rb
+++ b/test/controllers/content_controller_test.rb
@@ -170,6 +170,8 @@ class ContentControllerTest < ActionController::TestCase
170 :upload_content_type => "image/png", 170 :upload_content_type => "image/png",
171 :upload_updated_at => Time.at(1_700_000_000)) 171 :upload_updated_at => Time.at(1_700_000_000))
172 node.attach_asset!(asset, :user => @user1, :headline => true) 172 node.attach_asset!(asset, :user => @user1, :headline => true)
173 node.publish_draft!
174 node.reload
173 175
174 # has_variant? only tests File.exist?, so touching the path is enough 176 # has_variant? only tests File.exist?, so touching the path is enough
175 # and no ImageMagick runs in the suite. image/png takes .jpg for the 177 # and no ImageMagick runs in the suite. image/png takes .jpg for the