Skip to content

Commit

Permalink
Remove ReactionObserver::creating method (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored Apr 9, 2023
1 parent 6bf6cd6 commit d24e2b9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
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

0 comments on commit d24e2b9

Please sign in to comment.