yt 0.32.6 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -4
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +22 -32
  5. data/YOUTUBE_IT.md +4 -4
  6. data/lib/yt.rb +0 -1
  7. data/lib/yt/associations/has_reports.rb +9 -14
  8. data/lib/yt/collections/reports.rb +5 -7
  9. data/lib/yt/models/resource.rb +69 -3
  10. data/lib/yt/models/url.rb +2 -60
  11. data/lib/yt/request.rb +6 -2
  12. data/lib/yt/version.rb +1 -1
  13. data/yt.gemspec +5 -2
  14. metadata +31 -169
  15. data/spec/collections/claims_spec.rb +0 -62
  16. data/spec/collections/comment_threads_spec.rb +0 -46
  17. data/spec/collections/playlist_items_spec.rb +0 -44
  18. data/spec/collections/playlists_spec.rb +0 -27
  19. data/spec/collections/policies_spec.rb +0 -30
  20. data/spec/collections/references_spec.rb +0 -30
  21. data/spec/collections/reports_spec.rb +0 -30
  22. data/spec/collections/subscriptions_spec.rb +0 -25
  23. data/spec/collections/videos_spec.rb +0 -43
  24. data/spec/constants/geography_spec.rb +0 -16
  25. data/spec/errors/forbidden_spec.rb +0 -10
  26. data/spec/errors/missing_auth_spec.rb +0 -24
  27. data/spec/errors/no_items_spec.rb +0 -10
  28. data/spec/errors/request_error_spec.rb +0 -44
  29. data/spec/errors/server_error_spec.rb +0 -10
  30. data/spec/errors/unauthorized_spec.rb +0 -10
  31. data/spec/models/account_spec.rb +0 -138
  32. data/spec/models/annotation_spec.rb +0 -180
  33. data/spec/models/asset_spec.rb +0 -32
  34. data/spec/models/channel_spec.rb +0 -127
  35. data/spec/models/claim_event_spec.rb +0 -62
  36. data/spec/models/claim_history_spec.rb +0 -27
  37. data/spec/models/claim_spec.rb +0 -223
  38. data/spec/models/comment_spec.rb +0 -40
  39. data/spec/models/comment_thread_spec.rb +0 -93
  40. data/spec/models/configuration_spec.rb +0 -44
  41. data/spec/models/content_detail_spec.rb +0 -52
  42. data/spec/models/content_owner_detail_spec.rb +0 -6
  43. data/spec/models/file_detail_spec.rb +0 -13
  44. data/spec/models/live_streaming_detail_spec.rb +0 -6
  45. data/spec/models/ownership_spec.rb +0 -59
  46. data/spec/models/player_spec.rb +0 -13
  47. data/spec/models/playlist_item_spec.rb +0 -120
  48. data/spec/models/playlist_spec.rb +0 -138
  49. data/spec/models/policy_rule_spec.rb +0 -63
  50. data/spec/models/policy_spec.rb +0 -41
  51. data/spec/models/rating_spec.rb +0 -12
  52. data/spec/models/reference_spec.rb +0 -249
  53. data/spec/models/request_spec.rb +0 -204
  54. data/spec/models/resource_spec.rb +0 -42
  55. data/spec/models/right_owner_spec.rb +0 -71
  56. data/spec/models/snippet_spec.rb +0 -13
  57. data/spec/models/statistics_set_spec.rb +0 -13
  58. data/spec/models/status_spec.rb +0 -13
  59. data/spec/models/subscription_spec.rb +0 -30
  60. data/spec/models/url_spec.rb +0 -78
  61. data/spec/models/video_category_spec.rb +0 -21
  62. data/spec/models/video_spec.rb +0 -669
  63. data/spec/requests/as_account/account_spec.rb +0 -143
  64. data/spec/requests/as_account/authentications_spec.rb +0 -127
  65. data/spec/requests/as_account/channel_spec.rb +0 -246
  66. data/spec/requests/as_account/channels_spec.rb +0 -18
  67. data/spec/requests/as_account/playlist_item_spec.rb +0 -55
  68. data/spec/requests/as_account/playlist_spec.rb +0 -218
  69. data/spec/requests/as_account/thumbnail.jpg +0 -0
  70. data/spec/requests/as_account/video.mp4 +0 -0
  71. data/spec/requests/as_account/video_spec.rb +0 -408
  72. data/spec/requests/as_content_owner/account_spec.rb +0 -29
  73. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +0 -15
  74. data/spec/requests/as_content_owner/asset_spec.rb +0 -31
  75. data/spec/requests/as_content_owner/bulk_report_job_spec.rb +0 -19
  76. data/spec/requests/as_content_owner/channel_spec.rb +0 -1836
  77. data/spec/requests/as_content_owner/claim_history_spec.rb +0 -20
  78. data/spec/requests/as_content_owner/claim_spec.rb +0 -17
  79. data/spec/requests/as_content_owner/content_owner_spec.rb +0 -370
  80. data/spec/requests/as_content_owner/match_policy_spec.rb +0 -17
  81. data/spec/requests/as_content_owner/ownership_spec.rb +0 -25
  82. data/spec/requests/as_content_owner/playlist_spec.rb +0 -767
  83. data/spec/requests/as_content_owner/video_group_spec.rb +0 -112
  84. data/spec/requests/as_content_owner/video_spec.rb +0 -1223
  85. data/spec/requests/as_server_app/channel_spec.rb +0 -54
  86. data/spec/requests/as_server_app/comment_spec.rb +0 -22
  87. data/spec/requests/as_server_app/comment_thread_spec.rb +0 -27
  88. data/spec/requests/as_server_app/comment_threads_spec.rb +0 -41
  89. data/spec/requests/as_server_app/playlist_item_spec.rb +0 -30
  90. data/spec/requests/as_server_app/playlist_spec.rb +0 -33
  91. data/spec/requests/as_server_app/url_spec.rb +0 -94
  92. data/spec/requests/as_server_app/video_spec.rb +0 -60
  93. data/spec/requests/as_server_app/videos_spec.rb +0 -40
  94. data/spec/requests/unauthenticated/video_spec.rb +0 -14
  95. data/spec/spec_helper.rb +0 -20
  96. data/spec/support/fail_matcher.rb +0 -15
  97. data/spec/support/global_hooks.rb +0 -48
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/policies'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::Policies do
6
- subject(:collection) { Yt::Collections::Policies.new parent: content_owner }
7
- let(:content_owner) { Yt::ContentOwner.new owner_name: 'any-name' }
8
- let(:page) { {items: [], token: 'any-token'} }
9
- let(:query) { {id: 'any-id'} }
10
-
11
- describe '#count' do
12
- context 'called once with .where(query) and once without' do
13
- after do
14
- collection.where(query).count
15
- collection.count
16
- end
17
-
18
- it 'only applies the query on the first call' do
19
- expect(collection).to receive(:fetch_page) do |options|
20
- expect(options[:params]).to include query
21
- page
22
- end
23
- expect(collection).to receive(:fetch_page) do |options|
24
- expect(options[:params]).not_to include query
25
- page
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/references'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::References do
6
- subject(:collection) { Yt::Collections::References.new parent: content_owner }
7
- let(:content_owner) { Yt::ContentOwner.new id: 'any-id' }
8
- let(:page) { {items: [], token: 'any-token'} }
9
- let(:query) { {id: 'reference-id'} }
10
-
11
- describe '#count' do
12
- context 'called once with .where(query) and once without' do
13
- after do
14
- collection.where(query).count
15
- collection.count
16
- end
17
-
18
- it 'only applies the query on the first call' do
19
- expect(collection).to receive(:fetch_page) do |options|
20
- expect(options[:params]).to include query
21
- page
22
- end
23
- expect(collection).to receive(:fetch_page) do |options|
24
- expect(options[:params]).not_to include query
25
- page
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/reports'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::Reports do
6
- subject(:reports) { Yt::Collections::Reports.new(parent: content_owner).tap{|reports| reports.metrics = {views: Integer}} }
7
- let(:content_owner) { Yt::ContentOwner.new owner_name: 'any-name' }
8
- let(:error){ {reason: reason, message: message} }
9
- let(:msg) { {response_body: {error: {errors: [error]}}}.to_json }
10
-
11
- describe '#within' do
12
- let(:result) { reports.within Range.new(5.days.ago, 4.days.ago), nil, nil, :day, nil, nil }
13
- context 'given the request raises error 400 with "Invalid Query" message' do
14
- let(:reason) { 'badRequest' }
15
- let(:message) { 'Invalid query. Query did not conform to the expectations' }
16
- before { expect(reports).to receive(:list).once.and_raise Yt::Error, msg }
17
- let(:try_again) { expect(reports).to receive(:list).at_least(:once) }
18
-
19
- context 'every time' do
20
- before { try_again.and_raise Yt::Error, msg }
21
- it { expect{result}.to fail }
22
- end
23
-
24
- context 'but returns a success code 2XX the second time' do
25
- before { try_again.and_return [views: {total: 20}] }
26
- it { expect{result}.not_to fail }
27
- end
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/subscriptions'
3
-
4
- describe Yt::Collections::Subscriptions do
5
- subject(:collection) { Yt::Collections::Subscriptions.new }
6
- let(:msg) { {response_body: {error: {errors: [{reason: reason}]}}}.to_json }
7
- before { expect(collection).to behave }
8
-
9
- describe '#insert' do
10
- context 'given a new subscription' do
11
- let(:subscription) { Yt::Subscription.new }
12
- let(:behave) { receive(:do_insert).and_return subscription }
13
-
14
- it { expect(collection.insert).to eq subscription }
15
- end
16
-
17
- context 'given a duplicate subscription' do
18
- let(:reason) { 'subscriptionDuplicate' }
19
- let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }
20
-
21
- it { expect{collection.insert}.to fail.with 'subscriptionDuplicate' }
22
- it { expect{collection.insert ignore_errors: true}.not_to fail }
23
- end
24
- end
25
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/videos'
3
- require 'yt/models/channel'
4
-
5
- describe Yt::Collections::Videos do
6
- subject(:collection) { Yt::Collections::Videos.new parent: channel }
7
- let(:channel) { Yt::Channel.new id: 'any-id' }
8
- let(:page) { {items: [], token: 'any-token'} }
9
-
10
- describe '#size', :ruby2 do
11
- describe 'sends only one request and return the total results' do
12
- let(:total_results) { 123456 }
13
- before do
14
- expect_any_instance_of(Yt::Request).to receive(:run).once do
15
- double(body: {'pageInfo'=>{'totalResults'=>total_results}})
16
- end
17
- end
18
- it { expect(collection.size).to be total_results }
19
- end
20
- end
21
-
22
- describe '#count' do
23
- let(:query) { {q: 'search string'} }
24
-
25
- context 'called once with .where(query) and once without' do
26
- after do
27
- collection.where(query).count
28
- collection.count
29
- end
30
-
31
- it 'only applies the query on the first call' do
32
- expect(collection).to receive(:fetch_page) do |options|
33
- expect(options[:params]).to include query
34
- page
35
- end
36
- expect(collection).to receive(:fetch_page) do |options|
37
- expect(options[:params]).not_to include query
38
- page
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/constants/geography'
3
-
4
- describe 'Yt::COUNTRIES' do
5
- it 'returns all country codes and names' do
6
- expect(Yt::COUNTRIES[:US]).to eq 'United States'
7
- expect(Yt::COUNTRIES['IT']).to eq 'Italy'
8
- end
9
- end
10
-
11
- describe 'Yt::US_STATES' do
12
- it 'returns all U.S. state codes and names' do
13
- expect(Yt::US_STATES[:CA]).to eq 'California'
14
- expect(Yt::US_STATES['CO']).to eq 'Colorado'
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/forbidden'
3
-
4
- describe Yt::Errors::Forbidden do
5
- let(:msg) { %r{^A request to YouTube API was considered forbidden by the server} }
6
-
7
- describe '#exception' do
8
- it { expect{raise Yt::Errors::Forbidden}.to raise_error msg }
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/missing_auth'
3
-
4
- describe Yt::Errors::MissingAuth do
5
- subject(:error) { raise Yt::Errors::MissingAuth, params }
6
- let(:params) { {} }
7
- let(:msg) { %r{^A request to YouTube API was sent without a valid authentication} }
8
-
9
- describe '#exception' do
10
- it { expect{error}.to raise_error msg }
11
-
12
- context 'given the user can authenticate via web' do
13
- let(:params) { {scopes: 'youtube', authentication_url: 'http://google.example.com/auth', redirect_uri: 'http://localhost/'} }
14
- let(:msg) { %r{^You can ask YouTube accounts to authenticate your app} }
15
- it { expect{error}.to raise_error msg }
16
- end
17
-
18
- context 'given the user can authenticate via device code' do
19
- let(:params) { {scopes: 'youtube', user_code: 'abcdefgh', verification_url: 'http://google.com/device'} }
20
- let(:msg) { %r{^Please authenticate your app by visiting the page} }
21
- it { expect{error}.to raise_error msg }
22
- end
23
- end
24
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/no_items'
3
-
4
- describe Yt::Errors::NoItems do
5
- let(:msg) { %r{^A request to YouTube API returned no items} }
6
-
7
- describe '#exception' do
8
- it { expect{raise Yt::Errors::NoItems}.to raise_error msg }
9
- end
10
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/request_error'
3
-
4
- describe Yt::Errors::RequestError do
5
- subject(:error) { raise Yt::Errors::RequestError, params }
6
- let(:params) { {} }
7
- let(:msg) { %r{^A request to YouTube API failed} }
8
-
9
- describe '#exception' do
10
- it { expect{error}.to raise_error msg }
11
-
12
- context 'given the exception includes sensitive data' do
13
- let(:body) { 'some secret token' }
14
- let(:curl) { 'curl -H "Authorization: secret-token"' }
15
- let(:params) { {response_body: body, request_curl: curl}.to_json }
16
-
17
- describe 'given a log level of :debug or :devel' do
18
- before(:all) { Yt.configuration.log_level = :debug }
19
- specify 'exposes sensitive data' do
20
- expect{error}.to raise_error do |error|
21
- expect(error.message).to include 'secret'
22
- end
23
- end
24
- end
25
-
26
- describe 'given a different log level' do
27
- before(:all) { Yt.configuration.log_level = :info }
28
- specify 'hides sensitive data' do
29
- expect{error}.to raise_error do |error|
30
- expect(error.message).not_to include 'secret'
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- describe Yt::Error do
39
- let(:msg) { %r{^A request to YouTube API failed} }
40
-
41
- describe '#exception' do
42
- it { expect{raise Yt::Error}.to raise_error msg }
43
- end
44
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/server_error'
3
-
4
- describe Yt::Errors::ServerError do
5
- let(:msg) { %r{^A request to YouTube API caused an unexpected server error} }
6
-
7
- describe '#exception' do
8
- it { expect{raise Yt::Errors::ServerError}.to raise_error msg }
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/unauthorized'
3
-
4
- describe Yt::Errors::Unauthorized do
5
- let(:msg) { %r{^A request to YouTube API was sent without a valid authentication} }
6
-
7
- describe '#exception' do
8
- it { expect{raise Yt::Errors::Unauthorized}.to raise_error msg }
9
- end
10
- end
@@ -1,138 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/account'
3
-
4
- describe Yt::Video do
5
- subject(:account) { Yt::Account.new attrs }
6
-
7
- describe '#id' do
8
- context 'given a user info with an ID' do
9
- let(:attrs) { {user_info: {"id"=>"103024385"}} }
10
- it { expect(account.id).to eq '103024385' }
11
- end
12
-
13
- context 'given a user info without an ID' do
14
- let(:attrs) { {user_info: {}} }
15
- it { expect(account.id).to eq '' }
16
- end
17
- end
18
-
19
- describe '#email' do
20
- context 'given a user info with an email' do
21
- let(:attrs) { {user_info: {"email"=>"user@example.com"}} }
22
- it { expect(account.email).to eq 'user@example.com' }
23
- end
24
-
25
- context 'given a user info without an email' do
26
- let(:attrs) { {user_info: {}} }
27
- it { expect(account.email).to eq '' }
28
- end
29
- end
30
-
31
- describe '#has_verified_email?' do
32
- context 'given a user info with a verified email' do
33
- let(:attrs) { {user_info: {"verified_email"=>true}} }
34
- it { expect(account).to have_verified_email }
35
- end
36
-
37
- context 'given a user info without a verified email' do
38
- let(:attrs) { {user_info: {"verified_email"=>false}} }
39
- it { expect(account).not_to have_verified_email }
40
- end
41
- end
42
-
43
- describe '#name' do
44
- context 'given a user info with a name' do
45
- let(:attrs) { {user_info: {"name"=>"User Example"}} }
46
- it { expect(account.name).to eq 'User Example' }
47
- end
48
-
49
- context 'given a user info without a name' do
50
- let(:attrs) { {user_info: {}} }
51
- it { expect(account.name).to eq '' }
52
- end
53
- end
54
-
55
- describe '#given_name' do
56
- context 'given a user info with a given name' do
57
- let(:attrs) { {user_info: {"given_name"=>"User"}} }
58
- it { expect(account.given_name).to eq 'User' }
59
- end
60
-
61
- context 'given a user info without a given name' do
62
- let(:attrs) { {user_info: {}} }
63
- it { expect(account.given_name).to eq '' }
64
- end
65
- end
66
-
67
- describe '#family_name' do
68
- context 'given a user info with a family name' do
69
- let(:attrs) { {user_info: {"family_name"=>"Example"}} }
70
- it { expect(account.family_name).to eq 'Example' }
71
- end
72
-
73
- context 'given a user info without a family name' do
74
- let(:attrs) { {user_info: {}} }
75
- it { expect(account.family_name).to eq '' }
76
- end
77
- end
78
-
79
- describe '#profile_url' do
80
- context 'given a user info with a link' do
81
- let(:attrs) { {user_info: {"link"=>"https://plus.google.com/1234"}} }
82
- it { expect(account.profile_url).to eq 'https://plus.google.com/1234' }
83
- end
84
-
85
- context 'given a user info without a link' do
86
- let(:attrs) { {user_info: {}} }
87
- it { expect(account.profile_url).to eq '' }
88
- end
89
- end
90
-
91
- describe '#avatar_url' do
92
- context 'given a user info with a picture' do
93
- let(:attrs) { {user_info: {"picture"=>"https://lh3.googleusercontent.com/photo.jpg"}} }
94
- it { expect(account.avatar_url).to eq 'https://lh3.googleusercontent.com/photo.jpg' }
95
- end
96
-
97
- context 'given a user info without a picture' do
98
- let(:attrs) { {user_info: {}} }
99
- it { expect(account.avatar_url).to eq '' }
100
- end
101
- end
102
-
103
- describe '#gender' do
104
- context 'given a user info with a gender' do
105
- let(:attrs) { {user_info: {"gender"=>"male"}} }
106
- it { expect(account.gender).to eq 'male' }
107
- end
108
-
109
- context 'given a user info without a gender' do
110
- let(:attrs) { {user_info: {}} }
111
- it { expect(account.gender).to eq '' }
112
- end
113
- end
114
-
115
- describe '#locale' do
116
- context 'given a user info with a locale' do
117
- let(:attrs) { {user_info: {"locale"=>"en"}} }
118
- it { expect(account.locale).to eq 'en' }
119
- end
120
-
121
- context 'given a user info without a locale' do
122
- let(:attrs) { {user_info: {}} }
123
- it { expect(account.locale).to eq '' }
124
- end
125
- end
126
-
127
- describe '#hd' do
128
- context 'given a user info with a Google App domain' do
129
- let(:attrs) { {user_info: {"hd"=>"example.com"}} }
130
- it { expect(account.hd).to eq 'example.com' }
131
- end
132
-
133
- context 'given a user info without a Google App domain' do
134
- let(:attrs) { {user_info: {}} }
135
- it { expect(account.hd).to eq '' }
136
- end
137
- end
138
- end
@@ -1,180 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/annotation'
3
-
4
- describe Yt::Annotation do
5
- subject(:annotation) { Yt::Annotation.new data: Hash.from_xml(xml) }
6
-
7
- describe '#above? and #below?' do
8
- let(:xml) { %Q{
9
- <segment>
10
- <movingRegion type="rect">
11
- <rectRegion d="0" h="17.7779998779" t="0:04.000" w="25.0" x="7.117000103" y="5.07000017166"/>
12
- <rectRegion d="0" h="17.7779998779" t="0:05.000" w="25.0" x="7.117000103" y="5.07000017166"/>
13
- </movingRegion>
14
- </segment>
15
- } }
16
-
17
- context 'given an annotation located above N% of the video height' do
18
- it { expect(annotation.above? 50).to be true }
19
- it { expect(annotation.below? 50).to be_falsey }
20
- end
21
-
22
- context 'given an annotation located below N% of the video height' do
23
- it { expect(annotation.above? 5).to be_falsey }
24
- it { expect(annotation.below? 5).to be true }
25
- end
26
-
27
- context 'given an annotation without a single position' do
28
- let(:xml) { %Q{
29
- <segment>
30
- <movingRegion type="rect">
31
- <rectRegion d="0" h="17.7779998779" t="0:05.000" w="25.0" x="7.117000103" y="5.07000017166"/>
32
- </movingRegion>
33
- </segment>
34
- } }
35
- it { expect(annotation.above? 50).to be true }
36
- it { expect(annotation.below? 50).to be_falsey }
37
- end
38
-
39
- context 'given an annotation without explicit location' do
40
- let(:xml) { '<segment></segment>' }
41
- it { expect(annotation.above? 50).to be_falsey }
42
- it { expect(annotation.below? 50).to be_falsey }
43
- end
44
- end
45
-
46
- describe '#text' do
47
- context 'given an annotation with text' do
48
- let(:xml) { '<TEXT>Hello, world!</TEXT>' }
49
- it { expect(annotation.text).to eq 'Hello, world!' }
50
- end
51
- end
52
-
53
- describe '#has_link_to_subscribe?' do
54
- context 'given an annotation with a link of class 5' do
55
- let(:xml) { '<action type="openUrl"><url link_class="5"/></action>' }
56
- it { expect(annotation).to have_link_to_subscribe }
57
- end
58
-
59
- context 'given an annotation without a link of class 5' do
60
- let(:xml) { '<action type="openUrl"><url link_class="3"/></action>' }
61
- it { expect(annotation).not_to have_link_to_subscribe }
62
- end
63
- end
64
-
65
- describe '#has_link_to_video?' do
66
- context 'given an annotation with a link of class 1' do
67
- let(:xml) { '<action type="openUrl"><url link_class="1"/></action>' }
68
- it { expect(annotation).to have_link_to_video }
69
- end
70
-
71
- context 'given an annotation with a "featured video" invideo programming' do
72
- let(:xml) { '<type>promotion</type>' }
73
- it { expect(annotation).to have_link_to_video }
74
- end
75
-
76
- context 'given an annotation without a link of class 1' do
77
- let(:xml) { '<action type="openUrl"><url link_class="3"/></action>' }
78
- it { expect(annotation).not_to have_link_to_video }
79
- end
80
- end
81
-
82
- describe '#has_link_to_playlist?' do
83
- context 'given an annotation with a link of class 2' do
84
- let(:xml) { '<action type="openUrl"><url link_class="2"/></action>' }
85
- it { expect(annotation).to have_link_to_playlist }
86
- end
87
-
88
- context 'given an annotation with an embedded playlist link' do
89
- let(:xml) { '<TEXT>https://www.youtube.com/watch?v=9bZkp7q19f0&amp;list=LLxO1tY8h1AhOz0T4ENwmpow"</TEXT>' }
90
- it { expect(annotation).to have_link_to_playlist }
91
- end
92
-
93
- context 'given an annotation without a link of class 2' do
94
- let(:xml) { '<action type="openUrl"><url link_class="3"/></action>' }
95
- it { expect(annotation).not_to have_link_to_playlist }
96
- end
97
-
98
- context 'given an annotation without text' do
99
- let(:xml) { '<TEXT />' }
100
- it { expect(annotation).not_to have_link_to_playlist }
101
- end
102
- end
103
-
104
- describe '#has_link_to_same_window?' do
105
- context 'given an annotation with a "current" target' do
106
- let(:xml) { '<action type="openUrl"><url target="current"/></action>' }
107
- it { expect(annotation).to have_link_to_same_window }
108
- end
109
-
110
- context 'given an annotation without a "current" target' do
111
- let(:xml) { '<action type="openUrl"><url target="new"/></action>' }
112
- it { expect(annotation).not_to have_link_to_same_window }
113
- end
114
- end
115
-
116
- describe '#has_invideo_programming?' do
117
- context 'given an annotation with a "featured video" invideo programming' do
118
- let(:xml) { '<type>promotion</type>' }
119
- it { expect(annotation).to have_invideo_programming }
120
- end
121
-
122
- context 'given an annotation with a "branding intro" invideo programming' do
123
- let(:xml) { '<type>branding</type>' }
124
- it { expect(annotation).to have_invideo_programming }
125
- end
126
-
127
- context 'given an annotation without an invideo programming' do
128
- let(:xml) { '<segment></segment>' }
129
- it { expect(annotation).not_to have_invideo_programming }
130
- end
131
- end
132
-
133
- describe '#starts_after and #starts_before' do
134
- context 'given an annotation with the first timestamp equal to 1 hour' do
135
- let(:xml) { %Q{
136
- <segment>
137
- <movingRegion type="rect">
138
- <rectRegion d="0" h="17.7779998779" t="01:00:01.000" w="25.0" x="7.117000103" y="5.07000017166"/>
139
- <rectRegion d="0" h="17.7779998779" t="01:05:56.066" w="25.0" x="7.117000103" y="5.07000017166"/>
140
- </movingRegion>
141
- </segment>
142
- } }
143
- it { expect(annotation.starts_after? 3600).to be true }
144
- it { expect(annotation.starts_after? 3610).to be_falsey }
145
- it { expect(annotation.starts_before? 3600).to be_falsey }
146
- it { expect(annotation.starts_before? 3610).to be true }
147
- end
148
-
149
- context 'given an annotation without timestamps' do
150
- let(:xml) { '<segment></segment>' }
151
- it { expect(annotation.starts_after? 0).to be_nil }
152
- it { expect(annotation.starts_before? 0).to be_nil }
153
- end
154
-
155
- context 'given an annotation with "never" as the timestamp' do
156
- let(:xml) { %Q{
157
- <segment>
158
- <movingRegion type="rect">
159
- <rectRegion h="6.0" t="never" w="25.0" x="7.0" y="5.0"/>
160
- <rectRegion h="6.0" t="never" w="25.0" x="7.0" y="5.0"/>
161
- </movingRegion>
162
- </segment>
163
- } }
164
- it { expect(annotation.starts_after? 0).to be_nil }
165
- it { expect(annotation.starts_before? 0).to be_nil }
166
- end
167
-
168
- context 'given an annotation with "0" as the timestamp' do
169
- let(:xml) { %Q{
170
- <segment>
171
- <movingRegion type="rect">
172
- <rectRegion h="6.0" t="0" w="25.0" x="7.0" y="5.0"/>
173
- </movingRegion>
174
- </segment>
175
- } }
176
- it { expect(annotation.starts_after? 10).to be_falsey }
177
- it { expect(annotation.starts_before? 10).to be true }
178
- end
179
- end
180
- end