Skip to content

Commit

Permalink
Merge 6907980 into e52875f
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jun 22, 2020
2 parents e52875f + 6907980 commit fcdd0b2
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor
tests/logs
build
composer.lock
.vscode/launch.json
22 changes: 0 additions & 22 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
$factory->define(\FriendsOfCat\LaravelFeatureFlags\FeatureFlag::class, function ($faker) {
return [
'key' => str_random(3),
'usage_count' => $faker->randomDigit,
'variants' => []
];
});



$factory->define(\FriendsOfCat\LaravelFeatureFlags\FeatureFlagUser::class, function ($faker) {
return [
'name' => $faker->word,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddUpdateCreatedAndOtherMetaInfo extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("feature_flags", function (Blueprint $table) {
$table->timestamps(0);
$table->unsignedInteger("usage_count")->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
5 changes: 4 additions & 1 deletion src/FeatureFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class FeatureFlag extends Model
'variants' => 'json',
];

public $timestamps = false;
protected $fillable = [
"usage_count", "variants"
];


protected static function boot()
{
Expand Down
10 changes: 8 additions & 2 deletions src/FeatureFlagSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function store(Request $request)
$flag->save();
return redirect()->route('laravel-feature-flag.index')->withMessage("Created Feature");
} catch (\Exception $e) {
return redirect()->route('laravel-feature-flag.index')->withMessage("Could not find feature flag");
\Log::error("Error storing feature flags");
\Log::error($e);
return redirect()->route('laravel-feature-flag.index')->withMessage("Could save feature flag");
}
}

Expand All @@ -81,7 +83,9 @@ public function update(Request $request, $id)
'laravel-feature-flag.index'
)->withMessage(sprintf("Feature Flag Updated %d", $id));
} catch (\Exception $e) {
return redirect()->route('laravel-feature-flag.index')->withMessage("Could not find feature flag");
\Log::error("Error updating feature flags");
\Log::error($e);
return redirect()->route('laravel-feature-flag.index')->withMessage("Could not update feature flag");
}
}

Expand All @@ -96,6 +100,8 @@ public function destroy($id)
'laravel-feature-flag.index'
)->withMessage(sprintf("Feature Flag deleted %d", $id));
} catch (\Exception $e) {
\Log::error("Error deleting feature flags");
\Log::error($e);
return redirect()->route('laravel-feature-flag.index')
->withMessage("Could not find feature flag");
}
Expand Down
5 changes: 2 additions & 3 deletions tests/FeatureFlagSettingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testShouldStoreFail()

$example_controller = \App::make(FeatureFlagSettingsController::class);
$data = $example_controller->store($request);
$this->assertEquals($data->getSession()->get('message'), 'Could not find feature flag');
$this->assertEquals($data->getSession()->get('message'), 'Could save feature flag');
}


Expand Down Expand Up @@ -159,7 +159,6 @@ public function testShouldUpdate()
$request = new Request();
$request->merge(['variants' => '["on"]']);
$feature_flag = FeatureFlag::where('key', 'add-twitter-field')->first();

$example_controller = \App::make(FeatureFlagSettingsController::class);
$data = $example_controller->update($request, $feature_flag->id);

Expand All @@ -177,7 +176,7 @@ public function testShouldUpdateFail()
$example_controller = \App::make(FeatureFlagSettingsController::class);
$data = $example_controller->update($request, null);

$this->assertEquals($data->getSession()->get('message'), "Could not find feature flag");
$this->assertEquals($data->getSession()->get('message'), "Could not update feature flag");
}

public function testShouldDestroy()
Expand Down
11 changes: 10 additions & 1 deletion tests/FeatureFlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function testOff()
$this->assertFalse($this->app->get(Gate::class)->allows('feature-flag', 'testing'));
}

public function testTimeStamp()
{
$feature = factory(FeatureFlag::class)->create(
['usage_count' => 2, "variants" => "off"]
);

$this->assertNotNull($feature->created_at);
$this->assertNotNull($feature->updated_at);
}


public function testOnForUserEmail()
{
Expand Down Expand Up @@ -110,5 +120,4 @@ public function testForNotFindFeature()

$this->assertFalse($this->app->get(Gate::class)->allows('feature-flag', 'testing'));
}

}
8 changes: 8 additions & 0 deletions views/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<td>ID</td>
<td>Key</td>
<td>Variant</td>
<td>Created At</td>
<td>Updated</td>
<td>Edit</td>
<td>Delete</td>
</tr>
Expand All @@ -42,6 +44,12 @@
<td>#{{ $setting->id }}</td>
<td>{{ $setting->key }}</td>
<td>{{ json_encode($setting->variants, JSON_PRETTY_PRINT) }}</td>
<td>
@if($setting->created_at) {{ $setting->created_at->toFormattedDateString() }} @else "empty" @endif
</td>
<td>
@if($setting->updated_at) {{ $setting->updated_at->diffForHumans()}} @else "empty" @endif
</td>
<td>
<a class="btn btn-success" href="/admin/feature_flags/{{ $setting->id }}/edit">Edit</a>
</td>
Expand Down

0 comments on commit fcdd0b2

Please sign in to comment.