diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-23 12:24:52 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-23 12:24:52 +0200 |
| commit | 932d4a4be40587fa6d489eca16a1ef6d6f2936d1 (patch) | |
| tree | a7512889db54347845ce8f72e5a2155d917b4500 /test | |
| parent | 6ef98ad444631b1d5ba67bb16aaaa2afdfa53ae0 (diff) | |
Witness asset uploads and out-of-band attaches in the action log
Diffstat (limited to 'test')
| -rw-r--r-- | test/controllers/assets_controller_test.rb | 10 | ||||
| -rw-r--r-- | test/models/node_attach_asset_test.rb | 19 |
2 files changed, 29 insertions, 0 deletions
diff --git a/test/controllers/assets_controller_test.rb b/test/controllers/assets_controller_test.rb index 0e251aad..4be2e8a1 100644 --- a/test/controllers/assets_controller_test.rb +++ b/test/controllers/assets_controller_test.rb | |||
| @@ -133,6 +133,16 @@ class AssetsControllerTest < ActionController::TestCase | |||
| 133 | assert_equal node_path(node), flash[:headline_kept_path] | 133 | assert_equal node_path(node), flash[:headline_kept_path] |
| 134 | end | 134 | end |
| 135 | 135 | ||
| 136 | test "create with node_id writes an asset_create and an asset_attach entry" do | ||
| 137 | node = Node.root.children.create!(:slug => "asset_log_pair") | ||
| 138 | assert_difference 'NodeAction.where(:action => "asset_create").count' do | ||
| 139 | assert_difference 'NodeAction.where(:action => "asset_attach").count' do | ||
| 140 | post :create, params: { asset: { name: 'Logged twice' }, node_id: node.id } | ||
| 141 | end | ||
| 142 | end | ||
| 143 | assert_equal users(:quentin), NodeAction.last.user | ||
| 144 | end | ||
| 145 | |||
| 136 | # --- edit --- | 146 | # --- edit --- |
| 137 | 147 | ||
| 138 | test "get edit" do | 148 | test "get edit" do |
diff --git a/test/models/node_attach_asset_test.rb b/test/models/node_attach_asset_test.rb index cb5b60f5..2df2cfbb 100644 --- a/test/models/node_attach_asset_test.rb +++ b/test/models/node_attach_asset_test.rb | |||
| @@ -95,6 +95,25 @@ class NodeAttachAssetTest < ActiveSupport::TestCase | |||
| 95 | assert_raises(ActiveRecord::RecordInvalid) { @node.attach_asset!(@image, :user => @user) } | 95 | assert_raises(ActiveRecord::RecordInvalid) { @node.attach_asset!(@image, :user => @user) } |
| 96 | end | 96 | end |
| 97 | 97 | ||
| 98 | test "attaching writes an asset_attach entry with node and asset participants" do | ||
| 99 | result = @node.attach_asset!(@image, :user => @user, :headline => true) | ||
| 100 | assert_equal :set, result[:headline] | ||
| 101 | |||
| 102 | action = NodeAction.where(:action => "asset_attach").last | ||
| 103 | assert_equal @node, action.node | ||
| 104 | subjects = action.action_participants.map { |p| [p.subject_type, p.subject_id] } | ||
| 105 | assert_includes subjects, ["Node", @node.id] | ||
| 106 | assert_includes subjects, ["Asset", @image.id] | ||
| 107 | assert action.metadata["headline"] | ||
| 108 | end | ||
| 109 | |||
| 110 | test "a fully redundant attach writes no entry" do | ||
| 111 | @node.attach_asset!(@image, :user => @user) | ||
| 112 | assert_no_difference 'NodeAction.count' do | ||
| 113 | @node.attach_asset!(@image, :user => @user) | ||
| 114 | end | ||
| 115 | end | ||
| 116 | |||
| 98 | private | 117 | private |
| 99 | 118 | ||
| 100 | def create_image_asset | 119 | def create_image_asset |
