diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-09 04:14:30 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-09 04:14:30 +0200 |
| commit | 42b996e9197680a1955cfa5639462908677e5a94 (patch) | |
| tree | 7f079ddf260fd67fc61686a7800625db47d1837c /test/controllers/assets_controller_test.rb | |
| parent | d16161eab9029a509951146b80334c304c35fd34 (diff) | |
Attach an asset to a page from its edit form
Diffstat (limited to 'test/controllers/assets_controller_test.rb')
| -rw-r--r-- | test/controllers/assets_controller_test.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb index aa3e00e6..c2d7ad57 100644 --- a/test/controllers/assets_controller_test.rb +++ b/test/controllers/assets_controller_test.rb | |||
| @@ -102,7 +102,9 @@ 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_to_draft", :title => node.title), flash[:notice] | 105 | assert_equal [I18n.t("flash.assets.created"), |
| 106 | I18n.t("flash.assets.attached_to_draft", :title => node.title)].join(" "), | ||
| 107 | flash[:notice] | ||
| 106 | end | 108 | end |
| 107 | 109 | ||
| 108 | test "create with node_id creates a draft when none is pending" do | 110 | test "create with node_id creates a draft when none is pending" do |
| @@ -116,7 +118,9 @@ class AssetsControllerTest < ActionController::TestCase | |||
| 116 | assert_includes node.draft.assets.reload, Asset.last | 118 | assert_includes node.draft.assets.reload, Asset.last |
| 117 | assert_empty node.head.assets.reload | 119 | assert_empty node.head.assets.reload |
| 118 | assert_equal users(:quentin), node.draft.editor | 120 | assert_equal users(:quentin), node.draft.editor |
| 119 | assert_equal I18n.t("flash.assets.attached_new_draft", :title => node.title), flash[:notice] | 121 | assert_equal [I18n.t("flash.assets.created"), |
| 122 | I18n.t("flash.assets.attached_new_draft", :title => node.title)].join(" "), | ||
| 123 | flash[:notice] | ||
| 120 | end | 124 | end |
| 121 | 125 | ||
| 122 | test "create against a foreign-locked node keeps the asset but refuses the attach" do | 126 | test "create against a foreign-locked node keeps the asset but refuses the attach" do |
| @@ -159,6 +163,19 @@ class AssetsControllerTest < ActionController::TestCase | |||
| 159 | assert_equal users(:quentin), action.user | 163 | assert_equal users(:quentin), action.user |
| 160 | end | 164 | end |
| 161 | 165 | ||
| 166 | test "update with node_id attaches the asset to the node's draft" do | ||
| 167 | node = Node.root.children.create!(:slug => "asset_update_attach") | ||
| 168 | asset = Asset.create!(:name => "Existing", :upload_content_type => "image/png") | ||
| 169 | |||
| 170 | put :update, params: { id: asset.id, asset: { name: "Existing" }, node_id: node.id } | ||
| 171 | |||
| 172 | assert_response :redirect | ||
| 173 | assert_includes node.draft.assets.reload, asset | ||
| 174 | assert_equal [I18n.t("flash.assets.updated"), | ||
| 175 | I18n.t("flash.assets.attached_to_draft", :title => node.title)].join(" "), | ||
| 176 | flash[:notice] | ||
| 177 | end | ||
| 178 | |||
| 162 | # --- edit --- | 179 | # --- edit --- |
| 163 | 180 | ||
| 164 | test "get edit" do | 181 | test "get edit" do |
