From 7cdabaaf399976b4085a34ee67eaf7c3d27c62d2 Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 5 Apr 2017 21:51:53 -0700 Subject: [PATCH 1/2] Add missing test for a72314d (no tags) --- spec/support/server.rb | 1 + spec/video/snippet_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/spec/support/server.rb b/spec/support/server.rb index 7cd9976..7aa40bb 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -14,6 +14,7 @@ $existing_video_id = 'gknzFj_0vvY' $another_video_id = '9bZkp7q19f0' $unknown_video_id = 'invalid-id-' + $untagged_video_id = 'oO6WawhsxTA' $existing_playlist_id = 'PL-LeTutc9GRKD3yBDhnRF_yE8UTaQI5Jf' $unknown_playlist_id = 'invalid-id-' diff --git a/spec/video/snippet_spec.rb b/spec/video/snippet_spec.rb index e9e971b..9962258 100644 --- a/spec/video/snippet_spec.rb +++ b/spec/video/snippet_spec.rb @@ -20,6 +20,15 @@ end end + context 'given an video without tags' do + let(:attrs) { {id: $untagged_video_id} } + + specify 'return an empty array as the tags', requests: 1 do + expect(video.tags).to eq [] + end + end + + context 'given an unknown video ID' do let(:attrs) { {id: $unknown_video_id} } From 6ac0e356844d4dc0052476a298f3b03bfb16e122 Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 5 Apr 2017 21:49:38 -0700 Subject: [PATCH 2/2] Fix .select to always include required part For instance if `channel = Yt::Channel.new(id: ..).select(:snippet)` and then I ask for `channel.view_count`, the `:statistics` part should be added to the request even if it was not specified at the beginning. --- CHANGELOG.md | 4 ++++ lib/yt/core/version.rb | 2 +- lib/yt/resource.rb | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e67f96..43f1253 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ For more information about changelogs, check [Keep a Changelog](http://keepachangelog.com) and [Vandamme](http://tech-angels.github.io/vandamme). +## 0.1.2 - 2017-04-06 + +* [BUGFIX] Fix cases like `channel.select(:snippet).view_count` where attribute does not belong to any selected part. + ## 0.1.1 - 2017-04-04 * [ENHANCEMENT] Add :defaults to `has_attribute` diff --git a/lib/yt/core/version.rb b/lib/yt/core/version.rb index e793771..080f613 100644 --- a/lib/yt/core/version.rb +++ b/lib/yt/core/version.rb @@ -3,6 +3,6 @@ module Yt module Core # @return [String] the SemVer-compatible gem version. # @see http://semver.org - VERSION = '0.1.1' + VERSION = '0.1.2' end end diff --git a/lib/yt/resource.rb b/lib/yt/resource.rb index ad05090..21f2046 100644 --- a/lib/yt/resource.rb +++ b/lib/yt/resource.rb @@ -6,7 +6,7 @@ class Resource # @option data [String] :id The unique ID of a YouTube resource. def initialize(data = {}) @data = data - @selected_data_parts = nil + @selected_data_parts = [] end # @return [String] the resource’s unique ID. @@ -65,7 +65,7 @@ def fetch_part(required_part) fetch resources_path, resource_params(options) end - parts = @selected_data_parts || [required_part] + parts = (@selected_data_parts + [required_part]).uniq if (resource = resources.select(*parts).first) parts.each{|part| @data[part] = resource.data[part]} @data[required_part]