Skip to content

Commit

Permalink
Fix #99
Browse files Browse the repository at this point in the history
  • Loading branch information
simc committed Oct 18, 2019
1 parent 4179585 commit fda9c8a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
5 changes: 4 additions & 1 deletion hive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions hive/lib/src/hive_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ abstract class HiveObject {
/// Persists this object.
Future<void> 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);
}
Expand All @@ -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.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion hive/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
homepage: https://github.com/hivedb/hive

Expand Down
10 changes: 4 additions & 6 deletions hive/test/hive_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
});

Expand All @@ -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'));
});
});

Expand Down

0 comments on commit fda9c8a

Please sign in to comment.