mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 21:53:48 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
53 lines
2.0 KiB
Ruby
53 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'onebox/movie'
|
|
|
|
RSpec.describe Onebox::Movie do
|
|
it 'returns a nil rating if there is no aggregateRating item in json_ld data' do
|
|
json_ld_data = json_ld_data_from_doc(
|
|
"<script type=\"application/ld+json\">{\"@type\":\"Movie\",\"someKey\":{}}</script>"
|
|
)
|
|
json_ld = described_class.new(json_ld_data)
|
|
expect(json_ld.rating).to eq(nil)
|
|
end
|
|
|
|
it 'returns a nil rating if there is no ratingValue item in json_ld data' do
|
|
json_ld_data = json_ld_data_from_doc(
|
|
"<script type=\"application/ld+json\">{\"@type\":\"Movie\",\"aggregateRating\":{\"@type\":\"AggregateRating\",\"ratingCount\":806928,\"bestRating\":10,\"worstRating\":1}}</script>"
|
|
)
|
|
json_ld = described_class.new(json_ld_data)
|
|
expect(json_ld.rating).to eq(nil)
|
|
end
|
|
|
|
it 'returns a nil if there is no duration in json_ld data' do
|
|
json_ld_data = json_ld_data_from_doc(
|
|
"<script type=\"application/ld+json\">{\"@type\":\"Movie\",\"aggregateRating\":{\"@type\":\"AggregateRating\",\"ratingCount\":806928,\"bestRating\":10,\"worstRating\":1}}</script>"
|
|
)
|
|
json_ld = described_class.new(json_ld_data)
|
|
expect(json_ld.duration).to eq(nil)
|
|
end
|
|
|
|
it 'to_h returns hash version of the object' do
|
|
json_ld_data = json_ld_data_from_doc(onebox_response('imdb'))
|
|
movie = described_class.new(json_ld_data)
|
|
expect(movie.to_h).to eq(expected_movie_hash)
|
|
end
|
|
|
|
private
|
|
|
|
def json_ld_data_from_doc(html)
|
|
JSON[Nokogiri::HTML(html).search('script[type="application/ld+json"]').text]
|
|
end
|
|
|
|
def expected_movie_hash
|
|
{
|
|
name: 'Rudy',
|
|
image: 'https://m.media-amazon.com/images/M/MV5BZGUzMDU1YmQtMzBkOS00MTNmLTg5ZDQtZjY5Njk4Njk2MmRlXkEyXkFqcGdeQXVyNjc1NTYyMjg@._V1_.jpg',
|
|
description: 'Rudy has always been told that he was too small to play college football. But he is determined to overcome the odds and fulfill his dream of playing for Notre Dame.',
|
|
rating: 7.5,
|
|
genres: ['Biography', 'Drama', 'Sport'],
|
|
duration: '01:54'
|
|
}
|
|
end
|
|
end
|