Fix bug: unable to set currency rate with Postgres
This commit is contained in:
@@ -15,6 +15,7 @@ Bug fixes:
|
|||||||
|
|
||||||
* Automatic action listeners were using the same instance
|
* Automatic action listeners were using the same instance
|
||||||
* Fix wrong link for category in task footer
|
* Fix wrong link for category in task footer
|
||||||
|
* Unable to set currency rate with Postgres database
|
||||||
|
|
||||||
Version 1.0.23
|
Version 1.0.23
|
||||||
--------------
|
--------------
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class Currency extends Base
|
|||||||
$reference = $this->config->get('application_currency', 'USD');
|
$reference = $this->config->get('application_currency', 'USD');
|
||||||
|
|
||||||
if ($reference !== $currency) {
|
if ($reference !== $currency) {
|
||||||
$rates = $rates === null ? $this->db->hashtable(self::TABLE)->getAll('currency', 'rate') : array();
|
$rates = $rates === null ? $this->db->hashtable(self::TABLE)->getAll('currency', 'rate') : $rates;
|
||||||
$rate = isset($rates[$currency]) ? $rates[$currency] : 1;
|
$rate = isset($rates[$currency]) ? $rates[$currency] : 1;
|
||||||
|
|
||||||
return $rate * $price;
|
return $rate * $price;
|
||||||
@@ -65,7 +65,7 @@ class Currency extends Base
|
|||||||
return $this->update($currency, $rate);
|
return $this->update($currency, $rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->persist(self::TABLE, compact('currency', 'rate'));
|
return $this->db->table(self::TABLE)->insert(array('currency' => $currency, 'rate' => $rate));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class CurrencyValidator extends Base
|
|||||||
$v = new Validator($values, array(
|
$v = new Validator($values, array(
|
||||||
new Validators\Required('currency', t('Field required')),
|
new Validators\Required('currency', t('Field required')),
|
||||||
new Validators\Required('rate', t('Field required')),
|
new Validators\Required('rate', t('Field required')),
|
||||||
|
new Validators\Numeric('rate', t('This value must be numeric')),
|
||||||
));
|
));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|||||||
46
tests/units/Model/CurrencyTest.php
Normal file
46
tests/units/Model/CurrencyTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__.'/../Base.php';
|
||||||
|
|
||||||
|
use Kanboard\Model\Currency;
|
||||||
|
|
||||||
|
class CurrencyTest extends Base
|
||||||
|
{
|
||||||
|
public function testGetAll()
|
||||||
|
{
|
||||||
|
$currencyModel = new Currency($this->container);
|
||||||
|
$currencies = $currencyModel->getAll();
|
||||||
|
$this->assertCount(0, $currencies);
|
||||||
|
|
||||||
|
$this->assertNotFalse($currencyModel->create('USD', 9.9));
|
||||||
|
$currencies = $currencyModel->getAll();
|
||||||
|
$this->assertCount(1, $currencies);
|
||||||
|
$this->assertEquals('USD', $currencies[0]['currency']);
|
||||||
|
$this->assertEquals(9.9, $currencies[0]['rate']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$currencyModel = new Currency($this->container);
|
||||||
|
$this->assertNotFalse($currencyModel->create('EUR', 1.2));
|
||||||
|
$this->assertNotFalse($currencyModel->create('EUR', 1.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdate()
|
||||||
|
{
|
||||||
|
$currencyModel = new Currency($this->container);
|
||||||
|
$this->assertNotFalse($currencyModel->create('EUR', 1.1));
|
||||||
|
$this->assertNotFalse($currencyModel->update('EUR', 2.2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPrice()
|
||||||
|
{
|
||||||
|
$currencyModel = new Currency($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(123, $currencyModel->getPrice('USD', 123));
|
||||||
|
|
||||||
|
$this->assertNotFalse($currencyModel->create('EUR', 0.5));
|
||||||
|
$this->assertEquals(50.0, $currencyModel->getPrice('EUR', 100));
|
||||||
|
$this->assertEquals(50.0, $currencyModel->getPrice('EUR', 100)); // test with cached result
|
||||||
|
}
|
||||||
|
}
|
||||||
27
tests/units/Validator/CurrencyValidatorTest.php
Normal file
27
tests/units/Validator/CurrencyValidatorTest.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__.'/../Base.php';
|
||||||
|
|
||||||
|
use Kanboard\Validator\CurrencyValidator;
|
||||||
|
|
||||||
|
class CurrencyValidatorTest extends Base
|
||||||
|
{
|
||||||
|
public function testValidation()
|
||||||
|
{
|
||||||
|
$validator = new CurrencyValidator($this->container);
|
||||||
|
$result = $validator->validateCreation(array());
|
||||||
|
$this->assertFalse($result[0]);
|
||||||
|
|
||||||
|
$result = $validator->validateCreation(array('currency' => 'EUR'));
|
||||||
|
$this->assertFalse($result[0]);
|
||||||
|
|
||||||
|
$result = $validator->validateCreation(array('rate' => 1.9));
|
||||||
|
$this->assertFalse($result[0]);
|
||||||
|
|
||||||
|
$result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
|
||||||
|
$this->assertFalse($result[0]);
|
||||||
|
|
||||||
|
$result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
|
||||||
|
$this->assertTrue($result[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user