File: media_object_examples.rb

package info (click to toggle)
ruby-twitter 7.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,840 kB
  • sloc: ruby: 10,919; makefile: 6
file content (146 lines) | stat: -rw-r--r-- 5,572 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
shared_examples_for 'a Twitter::Media object' do
  describe '#==' do
    it 'returns true when objects IDs are the same' do
      media = described_class.new(id: 1)
      other = described_class.new(id: 1)
      expect(media == other).to be true
    end
    it 'returns false when objects IDs are different' do
      media = described_class.new(id: 1)
      other = described_class.new(id: 2)
      expect(media == other).to be false
    end
    it 'returns false when classes are different' do
      media = described_class.new(id: 1)
      other = Twitter::Identity.new(id: 1)
      expect(media == other).to be false
    end
  end

  describe '#sizes' do
    it 'returns a hash of Sizes when sizes is set' do
      sizes = described_class.new(id: 110_102_452_988_157_952, sizes: {small: {h: 226, w: 340, resize: 'fit'}, large: {h: 466, w: 700, resize: 'fit'}, medium: {h: 399, w: 600, resize: 'fit'}, thumb: {h: 150, w: 150, resize: 'crop'}}).sizes
      expect(sizes).to be_a Hash
      expect(sizes[:small]).to be_a Twitter::Size
    end
    it 'is empty when sizes is not set' do
      sizes = described_class.new(id: 110_102_452_988_157_952).sizes
      expect(sizes).to be_empty
    end
  end

  describe '#display_uri' do
    it 'returns a String when the display_url is set' do
      photo = Twitter::Media::Photo.new(id: 1, display_url: 'example.com/expanded...')
      expect(photo.display_uri).to be_a String
      expect(photo.display_uri).to eq('example.com/expanded...')
    end
    it 'returns nil when the display_url is not set' do
      photo = Twitter::Media::Photo.new(id: 1)
      expect(photo.display_uri).to be_nil
    end
  end

  describe '#display_uri?' do
    it 'returns true when the display_url is set' do
      photo = Twitter::Media::Photo.new(id: 1, display_url: 'example.com/expanded...')
      expect(photo.display_uri?).to be true
    end
    it 'returns false when the display_url is not set' do
      photo = Twitter::Media::Photo.new(id: 1)
      expect(photo.display_uri?).to be false
    end
  end

  describe '#expanded_uri' do
    it 'returns a URI when the expanded_url is set' do
      media = described_class.new(id: 1, expanded_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.expanded_uri).to be_an Addressable::URI
      expect(media.expanded_uri.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
    end
    it 'returns nil when the expanded_url is not set' do
      media = described_class.new(id: 1)
      expect(media.expanded_uri).to be_nil
    end
  end

  describe '#expanded_uri?' do
    it 'returns true when the expanded_url is set' do
      media = described_class.new(id: 1, expanded_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.expanded_uri?).to be true
    end
    it 'returns false when the expanded_url is not set' do
      media = described_class.new(id: 1)
      expect(media.expanded_uri?).to be false
    end
  end

  describe '#media_uri' do
    it 'returns a URI when the media_url is set' do
      media = described_class.new(id: 1, media_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.media_uri).to be_an Addressable::URI
      expect(media.media_uri.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
    end
    it 'returns nil when the media_url is not set' do
      media = described_class.new(id: 1)
      expect(media.media_uri).to be_nil
    end
  end

  describe '#media_uri?' do
    it 'returns true when the media_url is set' do
      media = described_class.new(id: 1, media_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.media_uri?).to be true
    end
    it 'returns false when the media_url is not set' do
      media = described_class.new(id: 1)
      expect(media.media_uri?).to be false
    end
  end

  describe '#media_uri_https' do
    it 'returns a URI when the media_url_https is set' do
      media = described_class.new(id: 1, media_url_https: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.media_uri_https).to be_an Addressable::URI
      expect(media.media_uri_https.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
    end
    it 'returns nil when the media_url_https is not set' do
      media = described_class.new(id: 1)
      expect(media.media_uri_https).to be_nil
    end
  end

  describe '#media_uri_https?' do
    it 'returns true when the media_url_https is set' do
      media = described_class.new(id: 1, media_url_https: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.media_uri_https?).to be true
    end
    it 'returns false when the media_url_https is not set' do
      media = described_class.new(id: 1)
      expect(media.media_uri_https?).to be false
    end
  end

  describe '#uri' do
    it 'returns a URI when the url is set' do
      media = described_class.new(id: 1, url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.uri).to be_an Addressable::URI
      expect(media.uri.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
    end
    it 'returns nil when the url is not set' do
      media = described_class.new(id: 1)
      expect(media.uri).to be_nil
    end
  end

  describe '#uri?' do
    it 'returns true when the url is set' do
      media = described_class.new(id: 1, url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png')
      expect(media.uri?).to be true
    end
    it 'returns false when the url is not set' do
      media = described_class.new(id: 1)
      expect(media.uri?).to be false
    end
  end
end