From 20df619dddd9699ee22e87b0619157c687647fb4 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 15 Oct 2015 00:23:14 -0700 Subject: [PATCH] HistorySpecification checks cutoff as well --- .../HistorySpecificationFixture.cs | 15 +++++++++++++-- .../RssSync/HistorySpecification.cs | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs index d223dd135..482f4d519 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs @@ -5,7 +5,6 @@ using Moq; using NUnit.Framework; using NzbDrone.Core.DecisionEngine.Specifications.RssSync; -using NzbDrone.Core.Download; using NzbDrone.Core.History; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; @@ -148,7 +147,7 @@ public void should_be_not_upgradable_if_only_second_episodes_is_upgradable() [Test] public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing() { - _fakeSeries.Profile = new Profile { Cutoff = Quality.WEBDL1080p, Items = Qualities.QualityFixture.GetDefaultQualities() }; + _fakeSeries.Profile = new Profile { Cutoff = Quality.Bluray1080p, Items = Qualities.QualityFixture.GetDefaultQualities() }; _parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)); _upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)); @@ -156,5 +155,17 @@ public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing() _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); } + + [Test] + public void should_not_be_upgradable_if_cutoff_already_met() + { + _fakeSeries.Profile = new Profile { Cutoff = Quality.WEBDL1080p, Items = Qualities.QualityFixture.GetDefaultQualities() }; + _parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)); + _upgradableQuality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1)); + + GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + + _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs index 65d5af73d..b3bfd6cc4 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs @@ -40,9 +40,14 @@ public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase if (mostRecent != null && mostRecent.EventType == HistoryEventType.Grabbed && mostRecent.DownloadId.IsNullOrWhiteSpace() && mostRecent.Date.After(DateTime.UtcNow.AddHours(-1))) { + if (!_qualityUpgradableSpecification.CutoffNotMet(subject.Series.Profile, mostRecent.Quality, subject.ParsedEpisodeInfo.Quality)) + { + return Decision.Reject("Recent grab event in history already meets cutoff: {0}", mostRecent.Quality); + } + if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.Profile, mostRecent.Quality, subject.ParsedEpisodeInfo.Quality)) { - return Decision.Reject("Existing grab event in history is of equal or higher quality: {0}", mostRecent.Quality); + return Decision.Reject("Recent grab event in history is of equal or higher quality: {0}", mostRecent.Quality); } } }