Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ReactionObserver::creating method #248

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ All notable changes to `laravel-love` will be documented in this file.

### Removed

- ([#247]) Removed `ReactionCounterObserver`
- ([#247]) Removed `ReactionTotalObserver`
- ([#247]) Removed `ReactionCounterObserver` class
- ([#247]) Removed `ReactionTotalObserver` class
- ([#248]) Removed `ReactionObserver::creating` method

## [9.0.0] - 2023-02-24

Expand Down Expand Up @@ -588,6 +589,7 @@ Follow [upgrade instructions](UPGRADING.md#from-v5-to-v6) to migrate database to
[1.1.1]: https://github.com/cybercog/laravel-love/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/cybercog/laravel-love/compare/1.0.0...1.1.0

[#248]: https://github.com/cybercog/laravel-love/pull/248
[#247]: https://github.com/cybercog/laravel-love/pull/247
[#240]: https://github.com/cybercog/laravel-love/pull/240
[#234]: https://github.com/cybercog/laravel-love/pull/234
Expand Down
2 changes: 1 addition & 1 deletion src/Reaction/Models/Reaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function setRateAttribute(
throw RateOutOfRange::withValueBetween($rate, self::RATE_MIN, self::RATE_MAX);
}

$this->attributes['rate'] = $rate;
$this->attributes['rate'] = $rate ?? self::RATE_DEFAULT;
}

public function isOfType(
Expand Down
8 changes: 0 additions & 8 deletions src/Reaction/Observers/ReactionObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ public function __construct(
$this->eventDispatcher = $eventDispatcher;
}

public function creating(
Reaction $reaction,
): void {
if ($reaction->getAttributeValue('rate') === null) {
$reaction->setAttribute('rate', Reaction::RATE_DEFAULT);
}
}

public function created(
Reaction $reaction,
): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function it_can_check_is_not_reaction_of_type(): void
}

/** @test */
public function it_can_create_model_with_zero_count(): void
public function it_can_create_counter_with_zero_count(): void
{
$counter1 = ReactionCounter::factory()->create();
$counter2 = ReactionCounter::factory()->create([
Expand All @@ -244,7 +244,7 @@ public function it_can_create_model_with_zero_count(): void
}

/** @test */
public function it_can_create_model_with_zero_weight(): void
public function it_can_create_counter_with_zero_weight(): void
{
$counter1 = ReactionCounter::factory()->create();
$counter2 = ReactionCounter::factory()->create([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function it_throws_exception_on_get_reactant_when_reactant_is_null(): voi
}

/** @test */
public function it_can_create_model_with_zero_count(): void
public function it_can_create_total_with_zero_count(): void
{
$total1 = ReactionTotal::factory()->create();
$total2 = ReactionTotal::factory()->create([
Expand All @@ -167,7 +167,7 @@ public function it_can_create_model_with_zero_count(): void
}

/** @test */
public function it_can_create_model_with_zero_weight(): void
public function it_can_create_total_with_zero_weight(): void
{
$total1 = ReactionTotal::factory()->create();
$total2 = ReactionTotal::factory()->create([
Expand Down
14 changes: 13 additions & 1 deletion tests/Unit/Reaction/Models/ReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function it_casts_string_rate_to_float(): void
/** @test */
public function it_casts_null_rate_to_default_value(): void
{
$reaction = Reaction::factory()->create([
$reaction = new Reaction([
'rate' => null,
]);

Expand All @@ -131,6 +131,18 @@ public function it_casts_not_set_rate_to_default_value(): void
$this->assertSame(Reaction::RATE_DEFAULT, $reaction->getRate());
}

/** @test */
public function it_can_create_reaction_with_default_value(): void
{
$reaction1 = Reaction::factory()->create();
$reaction2 = Reaction::factory()->create([
'rate' => null,
]);

$this->assertSame(Reaction::RATE_DEFAULT, $reaction1->getRate());
$this->assertSame(Reaction::RATE_DEFAULT, $reaction2->getRate());
}

/** @test */
public function it_can_belong_to_type(): void
{
Expand Down