|
194 | 194 | end |
195 | 195 | end |
196 | 196 |
|
| 197 | + context "when updating notes" do |
| 198 | + it "appends notes with a semicolon delimiter" do |
| 199 | + asset_1.update!(notes: "First note") |
| 200 | + asset_2.update!(notes: nil) |
| 201 | + |
| 202 | + patch volume_batch_actions_path(volume), params: { |
| 203 | + asset_ids: "#{asset_1.id},#{asset_2.id}", |
| 204 | + notes_action: "append", |
| 205 | + notes: "Second note" |
| 206 | + } |
| 207 | + |
| 208 | + expect(response).to have_http_status(:redirect) |
| 209 | + |
| 210 | + asset_1.reload |
| 211 | + asset_2.reload |
| 212 | + |
| 213 | + expect(asset_1.notes).to eq("First note; Second note") |
| 214 | + expect(asset_2.notes).to eq("Second note") |
| 215 | + expect(flash[:notice]).to include("notes appended") |
| 216 | + end |
| 217 | + |
| 218 | + it "replaces notes even when the new value is blank" do |
| 219 | + asset_1.update!(notes: "Existing note") |
| 220 | + |
| 221 | + patch volume_batch_actions_path(volume), params: { |
| 222 | + asset_ids: asset_1.id.to_s, |
| 223 | + notes_action: "replace", |
| 224 | + notes: "" |
| 225 | + } |
| 226 | + |
| 227 | + expect(response).to have_http_status(:redirect) |
| 228 | + expect(asset_1.reload.notes).to eq("") |
| 229 | + expect(flash[:notice]).to include("notes replaced") |
| 230 | + end |
| 231 | + |
| 232 | + it "clears notes for selected assets" do |
| 233 | + asset_1.update!(notes: "Existing note") |
| 234 | + |
| 235 | + patch volume_batch_actions_path(volume), params: { |
| 236 | + asset_ids: asset_1.id.to_s, |
| 237 | + notes_action: "clear", |
| 238 | + notes: "ignored" |
| 239 | + } |
| 240 | + |
| 241 | + expect(response).to have_http_status(:redirect) |
| 242 | + expect(asset_1.reload.notes).to be_nil |
| 243 | + expect(flash[:notice]).to include("notes cleared") |
| 244 | + end |
| 245 | + end |
| 246 | + |
197 | 247 | context "when updating multiple fields simultaneously" do |
198 | 248 | it "updates all specified fields for selected assets" do |
199 | 249 | patch volume_batch_actions_path(volume), params: { |
|
0 commit comments