|
79 | 79 | reply_position = response.body.index(reply_message.body) |
80 | 80 | expect(root_position).to be < reply_position |
81 | 81 | end |
| 82 | + |
| 83 | + it "renders patch attachments inline as expandable diff blocks" do |
| 84 | + create(:attachment, :patch_file, message: root_message) |
| 85 | + |
| 86 | + get topic_path(topic) |
| 87 | + |
| 88 | + expect(response).to have_http_status(:success) |
| 89 | + expect(response.body).to include("Attachments:") |
| 90 | + expect(response.body).to include('class="language-diff"') |
| 91 | + expect(response.body).to include("diff --git") |
| 92 | + end |
82 | 93 | end |
83 | 94 |
|
84 | 95 | context "with nonexistent topic" do |
|
89 | 100 | end |
90 | 101 | end |
91 | 102 |
|
| 103 | + describe "GET /attachments/:id" do |
| 104 | + let!(:creator) { create(:alias) } |
| 105 | + let!(:topic) { create(:topic, creator: creator) } |
| 106 | + let!(:message) { create(:message, topic: topic, sender: creator, reply_to: nil, created_at: 2.hours.ago) } |
| 107 | + |
| 108 | + it "streams the attachment as a download with the right filename" do |
| 109 | + attachment = create(:attachment, :patch_file, message: message) |
| 110 | + |
| 111 | + get attachment_path(attachment) |
| 112 | + |
| 113 | + expect(response).to have_http_status(:success) |
| 114 | + expect(response.headers["Content-Disposition"]).to include("attachment") |
| 115 | + expect(response.headers["Content-Disposition"]).to include(attachment.file_name) |
| 116 | + expect(response.body).to include("diff --git") |
| 117 | + end |
| 118 | + |
| 119 | + it "returns 404 when the attachment body is missing" do |
| 120 | + attachment = create(:attachment, body: nil, message: message) |
| 121 | + |
| 122 | + get attachment_path(attachment) |
| 123 | + |
| 124 | + expect(response).to have_http_status(:not_found) |
| 125 | + end |
| 126 | + end |
| 127 | + |
92 | 128 | describe "GET /topics/search" do |
93 | 129 | let!(:creator1) { create(:alias) } |
94 | 130 | let!(:creator2) { create(:alias) } |
|
0 commit comments