Skip to content

Commit

Permalink
Merge pull request #3 from Fullscreen/fix-select
Browse files Browse the repository at this point in the history
Fix select
  • Loading branch information
claudiofullscreen committed Apr 6, 2017
2 parents 48ce28f + 6ac0e35 commit 2e2ee45
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion lib/yt/core/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/yt/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions spec/support/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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-'
Expand Down
9 changes: 9 additions & 0 deletions spec/video/snippet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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} }

Expand Down

0 comments on commit 2e2ee45

Please sign in to comment.