Skip to content

Commit 254d653

Browse files
committed
Fix IP address storage
1 parent 8d1f111 commit 254d653

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Models/VisitModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function makeFromRequest(IncomingRequest $request): Visit
7272
public function findSimilar(Visit $visit): ?Visit
7373
{
7474
$config = config('Visits');
75-
$tracking = $visit->{$config->trackingMethod};
75+
$tracking = $visit->toRawArray()[$config->trackingMethod] ?? null;
7676

7777
// Required fields
7878
if (empty($tracking) || empty($visit->host) || empty($visit->path)) {

tests/FilterTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,21 @@ public function testRecords(): void
2727
$this->seeInDatabase('visits', ['path' => '/index.php']);
2828
}
2929

30-
public function testIncrements(): void
30+
public function testIpAddressIncrements(): void
31+
{
32+
config('Visits')->trackingMethod = 'ip_address';
33+
$_SERVER['REMOTE_ADDR'] = '192.168.0.1';
34+
$this->request = single_service('request');
35+
36+
$this->call();
37+
$this->call();
38+
39+
$this->seeInDatabase('visits', ['views' => 2]);
40+
41+
unset($_SERVER['REMOTE_ADDR']);
42+
}
43+
44+
public function testUserIdIncrements(): void
3145
{
3246
config('Visits')->trackingMethod = 'user_id';
3347
service('auth')->login(42);

tests/ModelTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function testMakeFromRequestConvertsIp(): void
125125
$result = $this->model->makeFromRequest(single_service('request'));
126126

127127
$this->assertSame($expected, $result->ipAddress);
128+
$this->assertSame(ip2long($expected), $result->toRawArray()['ip_address']);
128129

129130
unset($_SERVER['REMOTE_ADDR']);
130131
}

0 commit comments

Comments
 (0)