From 7b221a7f72c1b80306950e9e4fe5eda58fb7eee2 Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 10:51:21 -0600 Subject: [PATCH 1/9] fixes rubocop errors and adds collection to tags --- lib/plex-ruby/movie.rb | 4 +--- lib/plex-ruby/stream.rb | 2 -- lib/plex-ruby/tags.rb | 2 +- lib/plex-ruby/video.rb | 14 +++++++------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/plex-ruby/movie.rb b/lib/plex-ruby/movie.rb index 5fa177a..4a1f2f7 100644 --- a/lib/plex-ruby/movie.rb +++ b/lib/plex-ruby/movie.rb @@ -1,6 +1,5 @@ module Plex class Movie - attr_reader :section, :key # @param [Section] section this movie belongs in @@ -46,12 +45,11 @@ def inspect #:nodoc: private def xml_doc - @xml_doc ||= Nokogiri::XML( Plex.open(url+key) ) + @xml_doc ||= Nokogiri::XML(Plex.open(url+key)) end def video @video ||= Plex::Video.new(xml_doc.search('Video').first) end - end end diff --git a/lib/plex-ruby/stream.rb b/lib/plex-ruby/stream.rb index 18d6fa7..4e7f04f 100644 --- a/lib/plex-ruby/stream.rb +++ b/lib/plex-ruby/stream.rb @@ -1,6 +1,5 @@ module Plex class Stream - ATTRIBUTES = %w(id streamType codec index language languageCode) # @param [Nokogiri::XML::Element] nokogiri element that represents this @@ -20,6 +19,5 @@ def ==(other) super end end - end end diff --git a/lib/plex-ruby/tags.rb b/lib/plex-ruby/tags.rb index 7944074..7f872a3 100644 --- a/lib/plex-ruby/tags.rb +++ b/lib/plex-ruby/tags.rb @@ -1,4 +1,4 @@ -%w(Genre Writer Director Country).each { |type| +%w(Collection Genre Writer Director Country).each { |type| eval <<-CLASS module Plex class #{type} diff --git a/lib/plex-ruby/video.rb b/lib/plex-ruby/video.rb index 79d896e..821c6ad 100644 --- a/lib/plex-ruby/video.rb +++ b/lib/plex-ruby/video.rb @@ -1,11 +1,10 @@ module Plex class Video - ATTRIBUTES = %w(ratingKey key studio type title titleSort contentRating summary rating viewCount year tagline thumb art duration originallyAvailableAt updatedAt) - attr_reader :medias, :genres, :writers, :directors, :roles, :attribute_hash + attr_reader :medias, :genres, :writers, :directors, :roles, :collections, :attribute_hash # @param [Nokogiri::XML::Element] nokogiri element that represents this # Video @@ -18,11 +17,12 @@ def initialize(node) end end - @medias = node.search('Media').map { |m| Plex::Media.new(m) } - @genres = node.search('Genre').map { |m| Plex::Genre.new(m) } - @writers = node.search('Writer').map { |m| Plex::Writer.new(m) } - @directors = node.search('Director').map { |m| Plex::Director.new(m) } - @roles = node.search('Role').map { |m| Plex::Role.new(m) } + @medias = node.search('Media').map { |m| Plex::Media.new(m) } + @genres = node.search('Genre').map { |m| Plex::Genre.new(m) } + @writers = node.search('Writer').map { |m| Plex::Writer.new(m) } + @directors = node.search('Director').map { |m| Plex::Director.new(m) } + @roles = node.search('Role').map { |m| Plex::Role.new(m) } + @collections = node.search('Collection').map { |m| Plex::Collection.new(m) } end From 957c85c56cd74af1fdb4e15d64e77a0dfb950109 Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 10:52:25 -0600 Subject: [PATCH 2/9] increments version number --- lib/plex-ruby/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plex-ruby/version.rb b/lib/plex-ruby/version.rb index 9d95496..d13a139 100644 --- a/lib/plex-ruby/version.rb +++ b/lib/plex-ruby/version.rb @@ -1,3 +1,3 @@ module Plex - VERSION = "1.5.3" + VERSION = "1.5.4" end From c6a94e2fcce1405b14710ab7bd82ddfe5bfdc37a Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 11:26:02 -0600 Subject: [PATCH 3/9] fixing more linting issues and testing --- Rakefile | 1 - lib/plex-ruby/client.rb | 54 ++++++------ lib/plex-ruby/section.rb | 9 +- test/test_helper.rb | 173 +++++++++++++++++++-------------------- 4 files changed, 110 insertions(+), 127 deletions(-) diff --git a/Rakefile b/Rakefile index 3503c74..0d3afa7 100644 --- a/Rakefile +++ b/Rakefile @@ -8,4 +8,3 @@ Rake::TestTask.new do |i| end task default: :test - diff --git a/lib/plex-ruby/client.rb b/lib/plex-ruby/client.rb index e8e19e2..18ef790 100644 --- a/lib/plex-ruby/client.rb +++ b/lib/plex-ruby/client.rb @@ -1,25 +1,23 @@ module Plex class Client - NAV_METHODS = %w(moveUp moveDown moveLeft moveRight pageUp pageDown nextLetter - previousLetter select back contextMenu toggleOSD) + previousLetter select back contextMenu toggleOSD).freeze PLAYBACK_METHODS = %w(play pause stop rewind fastForward stepForward - bigStepForward stepBack bigStepBack skipNext skipPrevious) + bigStepForward stepBack bigStepBack skipNext skipPrevious).freeze - ATTRIBUTES = %w(name host address port machineIdentifier version) + ATTRIBUTES = %w(name host address port machineIdentifier version).freeze - attr_reader *ATTRIBUTES.map {|m| Plex.underscore(m) } + attr_reader(*ATTRIBUTES.map { |m| Plex.underscore(m) }) attr_reader :server - # @param [Server] server this client belongs to # @param [Nokogiri::XML::Element] nokogiri element to build from def initialize(server, node) @server = server - ATTRIBUTES.each { |e| - instance_variable_set("@#{Plex.underscore(e)}", node.attr(e)) - } + ATTRIBUTES.each do |attribute| + instance_variable_set("@#{Plex.underscore(attribute)}", node.attr(attribute)) + end end # Navigation methods @@ -27,29 +25,29 @@ def initialize(server, node) # # @return [True, nil] true if it worked, nil if something went wrong check # the console for the error message - NAV_METHODS.each { |nav| + NAV_METHODS.each do |nav| class_eval %( def #{Plex.underscore(nav)} ping player_url+'/navigation/#{nav}' end ) - } + end # Playback methods # Sends a playback command to the client to play / pause videos and such # # @return [True, nil] true if it worked, nil if something went wrong check # the console for the error message - PLAYBACK_METHODS.each { |playback| + PLAYBACK_METHODS.each do |playback| class_eval %( def #{Plex.underscore(playback)} ping player_url+'/playback/#{playback}' end ) - } + end def play_file - ping player_url+"/application/playFile" + ping player_url + '/application/playFile' end # Plays a video that is in the library @@ -62,14 +60,11 @@ def play_file # @return [True, nil] true if it worked, nil if something went wrong check # the console for the error message def play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil) + key = key.key if !key.is_a?(String) && key.respond_to?(:key) - if !key.is_a?(String) && key.respond_to?(:key) - key = key.key - end - - url = player_url+'/application/playMedia?' - url += "path=#{CGI::escape(server.url+key)}" - url += "&key=#{CGI::escape(key)}" + url = player_url + '/application/playMedia?' + url += "path=#{CGI.escape(server.url + key)}" + url += "&key=#{CGI.escape(key)}" url += "&userAgent=#{user_agent}" if user_agent url += "&httpCookies=#{http_cookies}" if http_cookies url += "&viewOffset=#{view_offset}" if view_offset @@ -85,10 +80,10 @@ def play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil) # @return [True, nil] true if it worked, nil if something went wrong check # the console for the error message def screenshot(width, height, quality) - url = player_url+'/application/screenshot?' - url += "width=#{width}" - url += "&height=#{height}" - url += "&quality=#{quality}" + url = player_url + '/application/screenshot?' + url += "width=#{width}" + url += "&height=#{height}" + url += "&quality=#{quality}" ping url end @@ -99,7 +94,7 @@ def screenshot(width, height, quality) # @return [True, nil] true if it worked, nil if something went wrong check # the console for the error message def send_string(text) - ping player_url+"/application/sendString?text=#{CGI::escape(text.to_s)}" + ping player_url + "/application/sendString?text=#{CGI.escape(text.to_s)}" end # Sends a key code to the Plex Client. Key codes represent key presses on @@ -112,12 +107,12 @@ def send_string(text) # @return [True, nil] true if it worked, nil if something went wrong check # the console for the error message def send_key(code) - ping player_url+"/application/sendKey?code=#{CGI::escape(code.to_s)}" + ping player_url + "/application/sendKey?code=#{CGI.escape(code.to_s)}" end # (see #send_key) def send_virtual_key(code) - ping player_url+"/application/sendVirtualKey?code=#{CGI::escape(code.to_s)}" + ping player_url + "/application/sendVirtualKey?code=#{CGI.escape(code.to_s)}" end # @private @@ -133,7 +128,7 @@ def inspect #:nodoc: private def player_url - URI.escape(url+"/system/players/#{name}") + URI.escape(url + "/system/players/#{name}") end def ping(url) @@ -141,6 +136,5 @@ def ping(url) rescue => e puts "Error trying to ping #{url} - #{e.message}" end - end end diff --git a/lib/plex-ruby/section.rb b/lib/plex-ruby/section.rb index 772d1eb..266813a 100644 --- a/lib/plex-ruby/section.rb +++ b/lib/plex-ruby/section.rb @@ -1,13 +1,12 @@ module Plex class Section + GROUPS = %w(all unwatched newest recentlyAdded recentlyViewed onDeck).freeze - GROUPS = %w(all unwatched newest recentlyAdded recentlyViewed onDeck) + ATTRIBUTES = %w(refreshing key type title art agent scanner language updatedAt).freeze - ATTRIBUTES = %w(refreshing key type title art agent scanner language updatedAt) + CATEGORIES = %w(collection firstCharacter genre year contentRating folder).freeze - CATEGORIES = %w(collection firstCharacter genre year contentRating folder) - - attr_reader *ATTRIBUTES.map {|m| Plex.underscore(m) } + attr_reader(*ATTRIBUTES.map { |m| Plex.underscore(m) }) attr_reader :library # @param [Library] library this Section belongs to diff --git a/test/test_helper.rb b/test/test_helper.rb index dcb7a62..51bdb89 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,6 @@ require 'minitest/autorun' class FakeAttr - def initialize(val) @val = val end @@ -10,12 +9,9 @@ def initialize(val) def value @val end - end - class FakeNode - def initialize(hash) @hash = hash end @@ -25,23 +21,20 @@ def attr(value) end def attributes - @hash.each_with_object({}) do |(key, val), obj| - obj[Plex.camelize(key)] = FakeAttr.new(val) + @hash.each_with_object({}) do |(key, val), obj| + obj[Plex.camelize(key)] = FakeAttr.new(val) end end def search(value) - Array( @hash[value.to_sym] ) + Array(@hash[value.to_sym]) end - end class FakeParent - def url 'http://localhost:32400' end - end FAKE_CLIENT_NODE_HASH = { @@ -50,50 +43,48 @@ def url address: '10.0.0.24', port: '3000', machine_identifier: 'f11283e2-a274-4c86-9a0a-23336c2d9e53', - version: '0.9.5.2-06ca164' -} + version: '0.9.5.2-06ca164', +}.freeze FAKE_SHOW_NODE_HASH = { - Directory: FakeNode.new({ - rating_key: "9", - guid: "com.plexapp.agents.thetvdb://73545?lang=en", - studio: "SciFi", - type: "show", - title: "Battlestar Galactica (2003)", - content_rating: "TV-14", - summary: "In a distant part of the universe, a civilization of humans live on planets known as the Twelve Colonies. In the past, the Colonies have been at war with a cybernetic race known as the Cylons. 40 years after the first war the Cylons launch a devastating attack on the Colonies. The only military ship that survived the attack takes up the task of leading a small fugitive fleet of survivors into space in search of a fabled refuge known as Earth.", - index: "1", - rating: "9.3", - year: "2003", - thumb: "/library/metadata/9/thumb?t=1323220437", - art: "/library/metadata/9/art?t=1323220437", - banner: "/library/metadata/9/banner?t=1323220437", - theme: "/library/metadata/9/theme?t=1323220437", - duration: "3600000", - originally_available_at: "2003-12-08", - leaf_count: "13", - viewed_leaf_count: "0", - added_at: "1323213639", - updated_at: "1323220437" - }) -} + Directory: FakeNode.new( + rating_key: '9', + guid: 'com.plexapp.agents.thetvdb://73545?lang=en', + studio: 'SciFi', + type: 'show', + title: 'Battlestar Galactica (2003)', + content_rating: 'TV-14', + summary: 'In a distant part of the universe, a civilization of humans live on planets known as the Twelve Colonies. In the past, the Colonies have been at war with a cybernetic race known as the Cylons. 40 years after the first war the Cylons launch a devastating attack on the Colonies. The only military ship that survived the attack takes up the task of leading a small fugitive fleet of survivors into space in search of a fabled refuge known as Earth.', + index: '1', + rating: '9.3', + year: '2003', + thumb: '/library/metadata/9/thumb?t=1323220437', + art: '/library/metadata/9/art?t=1323220437', + banner: '/library/metadata/9/banner?t=1323220437', + theme: '/library/metadata/9/theme?t=1323220437', + duration: '3600000', + originally_available_at: '2003-12-08', + leaf_count: '13', + viewed_leaf_count: '0', + added_at: '1323213639', + updated_at: '1323220437') +}.freeze FAKE_SEASON_NODE_HASH = { - Directory: FakeNode.new({ - rating_key: "10", - key: "/library/metadata/10/children", - guid: "com.plexapp.agents.thetvdb://73545/1?lang=en", - type: "season", - title: "Season 1", - summary: "", - index: "1", - thumb: "/library/metadata/10/thumb?t=1323220437", - leaf_count: "13", - viewed_leaf_count: "0", - added_at: "1323213639", - updated_at: "1323220437" - }) -} + Directory: FakeNode.new( + rating_key: '10', + key: '/library/metadata/10/children', + guid: 'com.plexapp.agents.thetvdb://73545/1?lang=en', + type: 'season', + title: 'Season 1', + summary: '', + index: '1', + thumb: '/library/metadata/10/thumb?t=1323220437', + leaf_count: '13', + viewed_leaf_count: '0', + added_at: '1323213639', + updated_at: '1323220437') +}.freeze FAKE_SECTION_NODE_HASH = { refreshing: '0', @@ -104,13 +95,13 @@ def url agent: 'com.plexapp.agents.imdb', scanner: 'Plex Movie Scanner', language: 'en', - updated_at: '1323213684' -} + updated_at: '1323213684', +}.freeze FAKE_LIBRARY_NODE_HASH = { :Directory => FakeNode.new(FAKE_SECTION_NODE_HASH), - :"Directory[@key='#{FAKE_SECTION_NODE_HASH[:key]}']" => FakeNode.new(FAKE_SECTION_NODE_HASH) -} + :"Directory[@key='#{FAKE_SECTION_NODE_HASH[:key]}.freeze']" => FakeNode.new(FAKE_SECTION_NODE_HASH), +}.freeze FAKE_STREAM_NODE_HASH = { id: '100', @@ -118,8 +109,8 @@ def url codec: 'aac', index: '5', language: 'English', - language_code: 'en' -} + language_code: 'en', +}.freeze FAKE_PART_NODE_HASH = { id: '45', @@ -127,8 +118,8 @@ def url duration: '1600', file: '/some/file/path/blah.mkv', size: '6500', - Stream: FakeNode.new( FAKE_STREAM_NODE_HASH ) -} + Stream: FakeNode.new(FAKE_STREAM_NODE_HASH), +}.freeze FAKE_MEDIA_NODE_HASH = { id: '63', @@ -142,55 +133,55 @@ def url container: 'mkv', video_frame_rate: '32/2', Part: FakeNode.new( FAKE_PART_NODE_HASH ) -} +}.freeze FAKE_GENRE_NODE_HASH = { id: '13', - tag: 'Action' -} + tag: 'Action', +}.freeze FAKE_WRITER_NODE_HASH = { id: '14', - tag: 'Poe' -} + tag: 'Poe', +}.freeze FAKE_DIRECTOR_NODE_HASH = { id: '15', - tag: 'King' -} + tag: 'King', +}.freeze FAKE_ROLE_NODE_HASH = { id: '16', tag: 'Red Haired Person', - role: "Ron" -} + role: 'Ron', +}.freeze FAKE_VIDEO_NODE_HASH = { rating_key: '7', - key: '/library/7', - studio: 'Six', - type: 'movie', - title: 'Men in Black (2011)', - title_sort: 'Men in Black', - content_rating: 'MA', - summary: 'Two men fight the entire world!', - rating: '9.9', - view_count: '0', - year: '2011', - tagline: 'Fight the Power!', - thumb: '/some/long/filename.jpg', - art: '/some/other/long/filename.jpg', - duration: '3400', - originally_available_at: '324124', - updated_at: '342214', + key: '/library/7', + studio: 'Six', + type: 'movie', + title: 'Men in Black (2011)', + title_sort: 'Men in Black', + content_rating: 'MA', + summary: 'Two men fight the entire world!', + rating: '9.9', + view_count: '0', + year: '2011', + tagline: 'Fight the Power!', + thumb: '/some/long/filename.jpg', + art: '/some/other/long/filename.jpg', + duration: '3400', + originally_available_at: '324124', + updated_at: '342214', index: '1', - Media: FakeNode.new( FAKE_MEDIA_NODE_HASH ), - Genre: FakeNode.new( FAKE_GENRE_NODE_HASH ), - Writer: FakeNode.new( FAKE_WRITER_NODE_HASH ), - Director: FakeNode.new( FAKE_DIRECTOR_NODE_HASH ), - Role: FakeNode.new( FAKE_ROLE_NODE_HASH ) -} + Media: FakeNode.new(FAKE_MEDIA_NODE_HASH), + Genre: FakeNode.new(FAKE_GENRE_NODE_HASH), + Writer: FakeNode.new(FAKE_WRITER_NODE_HASH), + Director: FakeNode.new(FAKE_DIRECTOR_NODE_HASH), + Role: FakeNode.new(FAKE_ROLE_NODE_HASH), +}.freeze FAKE_PARSER_NODE_HASH = { - MediaContainer: FakeNode.new(FAKE_VIDEO_NODE_HASH) -} + MediaContainer: FakeNode.new(FAKE_VIDEO_NODE_HASH), +}.freeze From 4074ed087fb50a3d13f6b6368b34f7d0ed63b97b Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 12:02:40 -0600 Subject: [PATCH 4/9] fixing URI.escape warning --- lib/plex-ruby/client.rb | 2 +- plex-ruby.gemspec | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/plex-ruby/client.rb b/lib/plex-ruby/client.rb index e8e19e2..af4e6a6 100644 --- a/lib/plex-ruby/client.rb +++ b/lib/plex-ruby/client.rb @@ -133,7 +133,7 @@ def inspect #:nodoc: private def player_url - URI.escape(url+"/system/players/#{name}") + url + '/system/players/' + CGI.escape(name) end def ping(url) diff --git a/plex-ruby.gemspec b/plex-ruby.gemspec index 6017a98..6e2e9f8 100644 --- a/plex-ruby.gemspec +++ b/plex-ruby.gemspec @@ -1,26 +1,26 @@ # -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "plex-ruby/version" +$LOAD_PATH.push File.expand_path('../lib', __FILE__) +require 'plex-ruby/version' Gem::Specification.new do |s| - s.name = "plex-ruby" + s.name = 'plex-ruby' s.version = Plex::VERSION s.platform = Gem::Platform::RUBY - s.authors = ["Eric Koslow"] - s.email = ["ekoslow@gmail.com"] - s.homepage = "https://github.com/ekosz/Plex-Ruby" - s.summary = %q{Plex Media Server APIs in easy ruby code} - s.description = %q{Extracts the Plex Media Server API into easy to write ruby code} + s.authors = ['Eric Koslow'] + s.email = ['ekoslow@gmail.com'] + s.homepage = 'https://github.com/ekosz/Plex-Ruby' + s.summary = 'Plex Media Server APIs in easy ruby code' + s.description = 'Extracts the Plex Media Server API into easy to write ruby code' - s.rubyforge_project = "plex-ruby" + s.rubyforge_project = 'plex-ruby' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } + s.require_paths = ['lib'] s.add_development_dependency 'minitest' - s.add_development_dependency "rake" - s.add_development_dependency "fakeweb" + s.add_development_dependency 'rake' + s.add_development_dependency 'fakeweb', ['~> 1.3'] s.add_runtime_dependency 'nokogiri' end From 57e3e2ff14fc6ad0d20ea1d47cee741b9468d773 Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 12:04:14 -0600 Subject: [PATCH 5/9] fixing assert_nil deprecation warning --- test/test_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_config.rb b/test/test_config.rb index be6eefe..939b62d 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -3,7 +3,7 @@ describe Plex::Config do it "should be configurable" do - Plex.config.auth_token.must_equal nil + Plex.config.auth_token.assert_nil Plex.configure do |config| config.auth_token = "ABCD" From c4f3b5c92ff0fc9c9c0da7403f9893b25481a1d4 Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 12:08:17 -0600 Subject: [PATCH 6/9] fixes assert_nil warning, adds colors --- test/test_config.rb | 2 +- test/test_helper.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_config.rb b/test/test_config.rb index 939b62d..83547f0 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -3,7 +3,7 @@ describe Plex::Config do it "should be configurable" do - Plex.config.auth_token.assert_nil + assert_nil(Plex.config.auth_token) Plex.configure do |config| config.auth_token = "ABCD" diff --git a/test/test_helper.rb b/test/test_helper.rb index dcb7a62..9c9198f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,6 @@ require 'plex-ruby' require 'minitest/autorun' +require 'minitest/pride' class FakeAttr From 3d1770a44e1f0e5cfb4b6feee51eec418c126419 Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 12:33:15 -0600 Subject: [PATCH 7/9] modifies testing --- lib/plex-ruby/library.rb | 1 - test/test_helper.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/plex-ruby/library.rb b/lib/plex-ruby/library.rb index e21d33c..4ed596d 100644 --- a/lib/plex-ruby/library.rb +++ b/lib/plex-ruby/library.rb @@ -1,6 +1,5 @@ module Plex class Library - attr_reader :server # @param [Server] server this libary belongs to diff --git a/test/test_helper.rb b/test/test_helper.rb index 6571917..969e1fa 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -97,7 +97,7 @@ def url scanner: 'Plex Movie Scanner', language: 'en', updated_at: '1323213684', -}.freeze +} FAKE_LIBRARY_NODE_HASH = { :Directory => FakeNode.new(FAKE_SECTION_NODE_HASH), From 6f6538195a37b92452b683c75444a81d977196b6 Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 12:35:39 -0600 Subject: [PATCH 8/9] fixes testing error --- test/test_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 969e1fa..2997880 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -97,11 +97,11 @@ def url scanner: 'Plex Movie Scanner', language: 'en', updated_at: '1323213684', -} +}.freeze FAKE_LIBRARY_NODE_HASH = { :Directory => FakeNode.new(FAKE_SECTION_NODE_HASH), - :"Directory[@key='#{FAKE_SECTION_NODE_HASH[:key]}.freeze']" => FakeNode.new(FAKE_SECTION_NODE_HASH), + :"Directory[@key='#{FAKE_SECTION_NODE_HASH[:key]}']" => FakeNode.new(FAKE_SECTION_NODE_HASH), }.freeze FAKE_STREAM_NODE_HASH = { From 0e3c5b9eaf8eead92ed378e654c814a651ec5c8b Mon Sep 17 00:00:00 2001 From: Alex Koch Date: Mon, 29 Apr 2019 12:52:57 -0600 Subject: [PATCH 9/9] adds testing for collections and adds assertions for classes for all tags just to be sure --- plex-ruby.gemspec | 3 ++- test/test_helper.rb | 7 +++++++ test/test_movie.rb | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plex-ruby.gemspec b/plex-ruby.gemspec index 6e2e9f8..a9f8d01 100644 --- a/plex-ruby.gemspec +++ b/plex-ruby.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'minitest' s.add_development_dependency 'rake' - s.add_development_dependency 'fakeweb', ['~> 1.3'] + s.add_development_dependency 'fakeweb' + s.add_development_dependency 'pry' s.add_runtime_dependency 'nokogiri' end diff --git a/test/test_helper.rb b/test/test_helper.rb index 2997880..c88ef24 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ require 'plex-ruby' require 'minitest/autorun' require 'minitest/pride' +require 'pry' class FakeAttr def initialize(val) @@ -151,6 +152,11 @@ def url tag: 'King', }.freeze +FAKE_COLLECTION_NODE_HASH = { + id: '78376', + tag: 'Harry Potter', +}.freeze + FAKE_ROLE_NODE_HASH = { id: '16', tag: 'Red Haired Person', @@ -181,6 +187,7 @@ def url Writer: FakeNode.new(FAKE_WRITER_NODE_HASH), Director: FakeNode.new(FAKE_DIRECTOR_NODE_HASH), Role: FakeNode.new(FAKE_ROLE_NODE_HASH), + Collection: FakeNode.new(FAKE_COLLECTION_NODE_HASH), }.freeze FAKE_PARSER_NODE_HASH = { diff --git a/test/test_movie.rb b/test/test_movie.rb index b01a2d5..8465e03 100644 --- a/test/test_movie.rb +++ b/test/test_movie.rb @@ -1,7 +1,6 @@ require 'test_helper' describe Plex::Movie do - before do @section = FakeParent.new @movie = Plex::Movie.new(@section, '/libary/metadata/6') @@ -18,15 +17,22 @@ } @movie.medias.must_equal fake_video.medias + assert_instance_of Plex::Media, @movie.medias.first @movie.genres.must_equal fake_video.genres + assert_instance_of Plex::Genre, @movie.genres.first @movie.writers.must_equal fake_video.writers + assert_instance_of Plex::Writer, @movie.writers.first @movie.directors.must_equal fake_video.directors + assert_instance_of Plex::Director, @movie.directors.first @movie.roles.must_equal fake_video.roles + assert_instance_of Plex::Role, @movie.roles.first + @movie.collections.must_equal fake_video.collections + assert_instance_of Plex::Collection, @movie.collections.first end it "should remember its parent (section)" do