about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-10-13 15:27:19 +0200
committerGitHub <noreply@github.com>2021-10-13 15:27:19 +0200
commit5159ba26e485daaeded2288c1b02bd1e516e1ca6 (patch)
tree409023bc5a521a321205265d9c1d8fd6d3eb3273 /spec/models
parent8818622feb9454684e51cd9b977b967883779432 (diff)
Fix error when rendering public pages with media attachments (#16763)
* Add tests

* Fix error when rendering public pages with media attachments

* Add tests

* Fix tests

* Please CodeClimate
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/media_attachment_spec.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb
index 5dbb3d206..7360b23cf 100644
--- a/spec/models/media_attachment_spec.rb
+++ b/spec/models/media_attachment_spec.rb
@@ -62,11 +62,23 @@ RSpec.describe MediaAttachment, type: :model do
   end
 
   describe '#to_param' do
-    let(:media_attachment) { Fabricate(:media_attachment) }
-    let(:shortcode)        { media_attachment.shortcode }
+    let(:media_attachment) { Fabricate(:media_attachment, shortcode: shortcode) }
+    let(:shortcode)        { nil }
 
-    it 'returns shortcode' do
-      expect(media_attachment.to_param).to eq shortcode
+    context 'when media attachment has a shortcode' do
+      let(:shortcode) { 'foo' }
+
+      it 'returns shortcode' do
+        expect(media_attachment.to_param).to eq shortcode
+      end
+    end
+
+    context 'when media attachment does not have a shortcode' do
+      let(:shortcode) { nil }
+
+      it 'returns string representation of id' do
+        expect(media_attachment.to_param).to eq media_attachment.id.to_s
+      end
     end
   end