diff --git a/app/models/package.rb b/app/models/package.rb index 1323cc762..5c429c0e7 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -255,15 +255,16 @@ returns name: package_db.name, version: package_db.version, migration_not_down: true, + reinstall: data[:reinstall], ) end # store package - record = Package.create(meta) if !data[:reinstall] + package_db = Package.create(meta) Store.add( object: 'Package', - o_id: record.id, + o_id: package_db.id, data: package.to_json, filename: "#{meta[:name]}-#{meta[:version]}.zpm", preferences: {}, @@ -279,15 +280,15 @@ returns } # update package state - record.state = 'installed' - record.save + package_db.state = 'installed' + package_db.save # up migrations Package::Migration.migrate(meta[:name]) # prebuild assets - record + package_db end =begin @@ -307,7 +308,6 @@ returns if !package fail "No such package '#{package_name}'" end - file = _get_bin(package.name, package.version) install(string: file, reinstall: true) package @@ -350,11 +350,13 @@ returns } # delete package - record = Package.find_by( - name: package['name'], - version: package['version'], - ) - record.destroy + if !data[:reinstall] + record = Package.find_by( + name: package['name'], + version: package['version'], + ) + record.destroy + end record end diff --git a/test/unit/package_test.rb b/test/unit/package_test.rb index 7978254b3..8a2542ddf 100644 --- a/test/unit/package_test.rb +++ b/test/unit/package_test.rb @@ -61,7 +61,34 @@ class PackageTest < ActiveSupport::TestCase }, }, - # test 2 - try to install same package again / should not work + # test 2 - renstall + { + action: 'reinstall', + name: 'UnitTestSample', + result: true, + verify: { + package: { + name: 'UnitTestSample', + version: '1.0.1', + }, + check_files: [ + { + location: 'test.txt', + result: true, + }, + { + location: 'test2.txt', + result: false, + }, + { + location: 'some/dir/test.txt', + result: true, + }, + ], + }, + }, + + # test 3 - try to install same package again / should not work { zpm: '{ "name": "UnitTestSample", @@ -87,7 +114,7 @@ class PackageTest < ActiveSupport::TestCase result: false, }, - # test 3 - try to install lower version / should not work + # test 4 - try to install lower version / should not work { zpm: '{ "name": "UnitTestSample", @@ -113,7 +140,7 @@ class PackageTest < ActiveSupport::TestCase result: false, }, - # test 4 - upgrade 7 should work + # test 5 - upgrade 7 should work { zpm: '{ "name": "UnitTestSample", @@ -173,7 +200,7 @@ class PackageTest < ActiveSupport::TestCase }, }, - # test 4 - uninstall package / should work + # test 6 - uninstall package / should work { name: 'UnitTestSample', version: '1.0.2', @@ -193,7 +220,7 @@ class PackageTest < ActiveSupport::TestCase }, }, - # test 5 - check auto_install mechanism + # test 7 - check auto_install mechanism { zpm: '{ "name": "UnitTestSample", @@ -253,7 +280,7 @@ class PackageTest < ActiveSupport::TestCase }, }, - # test 6 - check uninstall / should work + # test 8 - check uninstall / should work { name: 'UnitTestSample', version: '1.0.2', @@ -288,6 +315,19 @@ class PackageTest < ActiveSupport::TestCase else assert( !package, 'install package successful but should not' ) end + elsif test[:action] == 'reinstall' + begin + package = Package.reinstall( test[:name] ) + rescue + package = false + end + if test[:result] + assert( package, 'reinstall package not successful' ) + issues = package.verify + assert( !issues, 'package verify not successful' ) + else + assert( !package, 'reinstall package successful but should not' ) + end elsif test[:action] == 'uninstall' if test[:zpm] begin