From 5ad11ba728db94bfcfabeac307997cf21dd9b76a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 15 Nov 2011 15:11:17 -0800 Subject: [PATCH] Fixed adding of Newznab provider. --- .../ProviderTests/NewznabProviderTest.cs | 40 +++++++++++++++++++ NzbDrone.Core/Providers/NewznzbProvider.cs | 5 ++- .../Controllers/SettingsController.cs | 4 +- NzbDrone.Web/NzbDrone.Web.csproj | 2 +- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs index 3592fd1c5..64050c75c 100644 --- a/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs @@ -56,6 +56,46 @@ namespace NzbDrone.Core.Test.ProviderTests db.Single(result).Url.Should().Be(expectedUrl); } + [Test] + public void Save_should_clean_url_before_inserting_when_url_is_not_empty() + { + //Setup + var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" }; + var expectedUrl = ""; + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + //Act + var result = mocker.Resolve().Save(newznab); + + //Assert + db.Single(result).Url.Should().Be(expectedUrl); + } + + [Test] + public void Save_should_clean_url_before_updating_when_url_is_not_empty() + { + //Setup + var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com" }; + var expectedUrl = ""; + var newUrl = ""; + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + newznab.Id = Convert.ToInt32(db.Insert(newznab)); + newznab.Url = newUrl; + + //Act + var result = mocker.Resolve().Save(newznab); + + //Assert + db.Single(result).Url.Should().Be(expectedUrl); + } + [Test] public void SaveAll_should_clean_urls_before_updating() { diff --git a/NzbDrone.Core/Providers/NewznzbProvider.cs b/NzbDrone.Core/Providers/NewznzbProvider.cs index 5cb92b52f..820d5806b 100644 --- a/NzbDrone.Core/Providers/NewznzbProvider.cs +++ b/NzbDrone.Core/Providers/NewznzbProvider.cs @@ -37,8 +37,9 @@ namespace NzbDrone.Core.Providers public virtual int Save(NewznabDefinition definition) { - //Cleanup the URL - definition.Url = (new Uri(definition.Url).ParentUriString()); + //Cleanup the URL if it is not null or whitespace + if (!String.IsNullOrWhiteSpace(definition.Url)) + definition.Url = (new Uri(definition.Url).ParentUriString()); if (definition.Id == 0) { diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 66cde8881..d5249580d 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -299,7 +299,7 @@ namespace NzbDrone.Web.Controllers return new JsonResult { Data = "ok" }; } - public ViewResult AddNewznabProvider() + public PartialViewResult AddNewznabProvider() { var newznab = new NewznabDefinition { @@ -312,7 +312,7 @@ namespace NzbDrone.Web.Controllers ViewData["ProviderId"] = id; - return View("NewznabProvider", newznab); + return PartialView("NewznabProvider", newznab); } public ActionResult GetNewznabProviderView(NewznabDefinition provider) diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index c054da65b..e44164400 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -974,4 +974,4 @@ xcopy /s /y "$(SolutionDir)packages\SqlServerCompact.4.0.8482.1\NativeBinaries\x if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64" xcopy /s /y "$(SolutionDir)packages\SqlServerCompact.4.0.8482.1\NativeBinaries\amd64\*.*" "$(TargetDir)amd64" - + \ No newline at end of file