Merge branch 'release/3.4.2'

This commit is contained in:
James Cole
2015-05-25 23:18:32 +02:00
8 changed files with 34 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
# Firefly III # Firefly III
#### 3.4.1 #### 3.4.2
[![Build Status](https://travis-ci.org/JC5/firefly-iii.svg?branch=develop)](https://travis-ci.org/JC5/firefly-iii) [![Build Status](https://travis-ci.org/JC5/firefly-iii.svg?branch=develop)](https://travis-ci.org/JC5/firefly-iii)
[![Project Status](http://stillmaintained.com/JC5/firefly-iii.png?a=b)](http://stillmaintained.com/JC5/firefly-iii) [![Project Status](http://stillmaintained.com/JC5/firefly-iii.png?a=b)](http://stillmaintained.com/JC5/firefly-iii)

View File

@@ -38,8 +38,7 @@ class PreferencesController extends Controller
$viewRange = $viewRangePref->data; $viewRange = $viewRangePref->data;
$frontPageAccounts = Preferences::get('frontPageAccounts', []); $frontPageAccounts = Preferences::get('frontPageAccounts', []);
$budgetMax = Preferences::get('budgetMaximum', 1000); $budgetMax = Preferences::get('budgetMaximum', 1000);
$languagePref = Preferences::get('language', 'en'); $language = Preferences::get('language', 'en')->data;
$language = $languagePref->data;
$budgetMaximum = $budgetMax->data; $budgetMaximum = $budgetMax->data;
return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange')); return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange'));

View File

@@ -4,6 +4,7 @@ namespace FireflyIII\Support;
use Auth; use Auth;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use Log;
/** /**
* Class Preferences * Class Preferences
@@ -20,14 +21,19 @@ class Preferences
*/ */
public function get($name, $default = null) public function get($name, $default = null)
{ {
$pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(); $preferences = Preference::where('user_id', Auth::user()->id)->get();
if (is_null($pref) && is_null($default)) {
/** @var Preference $preference */
foreach ($preferences as $preference) {
if ($preference->name == $name) {
return $preference;
}
}
// no preference found and default is null:
if (is_null($default)) {
// return NULL // return NULL
return null; return null;
} }
if (!is_null($pref)) {
return $pref;
}
return $this->set($name, $default); return $this->set($name, $default);
@@ -41,12 +47,20 @@ class Preferences
*/ */
public function set($name, $value) public function set($name, $value)
{ {
$pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(); $preferences = Preference::where('user_id', Auth::user()->id)->get();
if (is_null($pref)) { /** @var Preference $preference */
$pref = new Preference; foreach ($preferences as $preference) {
$pref->name = $name; if ($preference->name == $name) {
$preference->data = $value;
$preference->save();
return $preference;
}
} }
$pref = new Preference;
$pref->name = $name;
$pref->data = $value; $pref->data = $value;
if (!is_null(Auth::user()->id)) { if (!is_null(Auth::user()->id)) {
$pref->user()->associate(Auth::user()); $pref->user()->associate(Auth::user());
$pref->save(); $pref->save();

View File

@@ -67,7 +67,11 @@ class AccountControllerTest extends TestCase
$this->be($pref->user); $this->be($pref->user);
Preferences::shouldReceive('get', 'viewRange')->andReturn($pref); Preferences::shouldReceive('get')->withArgs(['viewRange', '1M'])->andReturn($pref);
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($language);
// CURRENCY: // CURRENCY:
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');

View File

@@ -67,7 +67,7 @@ class BillControllerTest extends TestCase
$bill = FactoryMuffin::create('FireflyIII\Models\Bill'); $bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user); $this->be($bill->user);
$this->call('GET', '/bills/delete/' . $bill->id); $this->call('GET', '/bills/delete/' . $bill->id);
$this->assertViewHas('subTitle', 'Delete "' . e($bill->name) . '"'); $this->assertViewHas('subTitle', 'Delete bill "' . e($bill->name) . '"');
$this->assertResponseOk(); $this->assertResponseOk();
} }

View File

@@ -97,7 +97,7 @@ class BudgetControllerTest extends TestCase
$this->call('GET', '/budgets/delete/' . $budget->id); $this->call('GET', '/budgets/delete/' . $budget->id);
$this->assertResponseOk(); $this->assertResponseOk();
$this->assertViewHas('subTitle', 'Delete budget' . e($budget->name) . '"'); $this->assertViewHas('subTitle', 'Delete budget "' . e($budget->name) . '"');
$this->assertViewHas('budget'); $this->assertViewHas('budget');
$this->assertSessionHas('budgets.delete.url'); $this->assertSessionHas('budgets.delete.url');
} }

View File

@@ -101,7 +101,7 @@ class PiggyBankControllerTest extends TestCase
$this->call('GET', '/piggy-banks/delete/' . $piggyBank->id); $this->call('GET', '/piggy-banks/delete/' . $piggyBank->id);
$this->assertResponseOk(); $this->assertResponseOk();
$this->assertViewHas('subTitle', 'Delete "' . e($piggyBank->name) . '"'); $this->assertViewHas('subTitle', 'Delete piggy bank "' . e($piggyBank->name) . '"');
} }
/** /**

View File

@@ -172,6 +172,7 @@ class ReminderHelperTest extends TestCase
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$reminder = FactoryMuffin::create('FireflyIII\Models\Reminder'); $reminder = FactoryMuffin::create('FireflyIII\Models\Reminder');
$piggyBank->targetdate = new Carbon; $piggyBank->targetdate = new Carbon;
$this->be($piggyBank->account->user);
$reminder->remindersable_id = $piggyBank->id; $reminder->remindersable_id = $piggyBank->id;
Amount::shouldReceive('format')->andReturn('xx'); Amount::shouldReceive('format')->andReturn('xx');