From fda9c8a4270566f582a1d913d32d4a3e9932018f Mon Sep 17 00:00:00 2001 From: Simon Leier Date: Fri, 18 Oct 2019 19:45:29 +0200 Subject: [PATCH] Fix #99 --- hive/CHANGELOG.md | 5 ++++- hive/lib/src/hive_object.dart | 5 ++--- hive/pubspec.yaml | 2 +- hive/test/hive_object_test.dart | 10 ++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hive/CHANGELOG.md b/hive/CHANGELOG.md index 3e89ee8b6..61c4df115 100644 --- a/hive/CHANGELOG.md +++ b/hive/CHANGELOG.md @@ -1,4 +1,7 @@ -## 1.1.0+3 +## 1.1.1 + +### Breaking changes +- `object.delete()` now throws exception if object is not stored in a box ### Fixes - Fixed bug where `object.save()` would faild on subsequent calls diff --git a/hive/lib/src/hive_object.dart b/hive/lib/src/hive_object.dart index 8a303a25d..93308bd60 100644 --- a/hive/lib/src/hive_object.dart +++ b/hive/lib/src/hive_object.dart @@ -18,8 +18,7 @@ abstract class HiveObject { /// Persists this object. Future save() { if (_box == null) { - throw HiveError('You have to add this object to a box first ' - 'using box.add() or box.put().'); + throw HiveError('This object is currently not in a box.'); } return _box.put(_key, this); } @@ -29,7 +28,7 @@ abstract class HiveObject { if (_box != null) { return _box.delete(_key); } else { - return Future.value(); + throw HiveError('This object is currently not in a box.'); } } diff --git a/hive/pubspec.yaml b/hive/pubspec.yaml index b2065ef6c..bacb63572 100644 --- a/hive/pubspec.yaml +++ b/hive/pubspec.yaml @@ -1,6 +1,6 @@ name: hive description: Lightweight and blazing fast key-value database written in pure Dart. Stronly encrypted using AES-256. -version: 1.1.0+3 +version: 1.1.1 author: Simon Leier homepage: https://github.com/hivedb/hive diff --git a/hive/test/hive_object_test.dart b/hive/test/hive_object_test.dart index f31c23e96..917680578 100644 --- a/hive/test/hive_object_test.dart +++ b/hive/test/hive_object_test.dart @@ -72,11 +72,9 @@ void main() { verify(box.put('key', obj)); }); - test('throws exception if object is not in a box', () { + test('throws HiveError if object is not in a box', () async { var obj = _TestObject(); - - expect(() => obj.save(), - throwsHiveError('add this object to a box first')); + await expectLater(() => obj.save(), throwsHiveError('not in a box')); }); }); @@ -91,9 +89,9 @@ void main() { verify(box.delete('key')); }); - test('does nothing if object is not in a box', () { + test('throws HiveError if object is not in a box', () async { var obj = _TestObject(); - obj.delete(); + await expectLater(() => obj.delete(), throwsHiveError('not in a box')); }); });