Cleanup naming specs if there is more than one

Fixed: Rare scenario where settings wouldn't load due to data issue
pull/6/head
Mark McDowall 11 years ago
parent dc100845a5
commit 7442cb4c68

@ -0,0 +1,37 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Housekeeping.Housekeepers;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{
[TestFixture]
public class CleanupAdditionalNamingSpecsFixture : DbTest<CleanupAdditionalNamingSpecs, History.History>
{
[Test]
public void should_delete_additional_naming_configs()
{
var specs = Builder<NamingConfig>.CreateListOfSize(5)
.BuildListOfNew();
Db.InsertMany(specs);
Subject.Clean();
AllStoredModels.Should().HaveCount(1);
}
[Test]
public void should_not_delete_if_only_one_spec()
{
var spec = Builder<NamingConfig>.CreateNew()
.BuildNew();
Db.Insert(spec);
Subject.Clean();
AllStoredModels.Should().HaveCount(1);
}
}
}

@ -0,0 +1,29 @@
using NLog;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupAdditionalNamingSpecs : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly Logger _logger;
public CleanupAdditionalNamingSpecs(IDatabase database, Logger logger)
{
_database = database;
_logger = logger;
}
public void Clean()
{
_logger.Trace("Running naming spec cleanup");
var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"DELETE FROM NamingConfig
WHERE ID NOT IN (
SELECT ID FROM NamingConfig
LIMIT 1)");
}
}
}

@ -1,6 +1,5 @@
using NLog;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{

@ -1,6 +1,5 @@
using NLog;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.History;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{

Loading…
Cancel
Save