Skip to content

Commit 6a07b28

Browse files
bobbybouwmanndriesvints
authored andcommitted
Set the max length of the subject to 60 (#324)
* Set the max length of the subject to 60 + add tests * Remove constant for max thread size * Add maxlength attribute to subject text field * Remove unused import
1 parent 4ee1a95 commit 6a07b28

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

app/Http/Requests/ThreadRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ThreadRequest extends Request
1111
public function rules()
1212
{
1313
return [
14-
'subject' => 'required|'.DoesNotContainUrlRule::NAME.'|'.SpamRule::NAME,
14+
'subject' => 'required|max:60|'.DoesNotContainUrlRule::NAME.'|'.SpamRule::NAME,
1515
'body' => 'required|'.SpamRule::NAME,
1616
'tags' => 'array',
1717
'tags.*' => 'exists:tags,id',

resources/views/forum/threads/_form.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{!! Form::open(['route' => $route, 'method' => $method ?? 'POST']) !!}
22
@formGroup('subject')
33
{!! Form::label('subject') !!}
4-
{!! Form::text('subject', isset($thread) ? $thread->subject() : null, ['class' => 'form-control', 'required']) !!}
4+
{!! Form::text('subject', isset($thread) ? $thread->subject() : null, ['class' => 'form-control', 'required', 'maxlength' => '60']) !!}
55
@error('subject')
66
@endFormGroup
77

tests/Feature/ForumTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,45 @@ public function users_cannot_delete_a_thread_they_do_not_own()
122122
$this->delete('/forum/my-first-thread')
123123
->assertForbidden();
124124
}
125+
126+
/** @test */
127+
public function users_cannot_create_a_thread_with_a_subject_that_is_too_long()
128+
{
129+
$tag = factory(Tag::class)->create(['name' => 'Test Tag']);
130+
131+
$this->login();
132+
133+
$this->visit('/forum/create-thread')
134+
->submitForm('Create Thread', [
135+
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
136+
'body' => 'This is a thread with 82 characters in the subject',
137+
'tags' => [$tag->id()],
138+
])
139+
->seePageIs('/forum/create-thread')
140+
->see('Something went wrong. Please review the fields below.')
141+
->see('The subject may not be greater than 60 characters.');
142+
}
143+
144+
/** @test */
145+
public function users_cannot_edit_a_thread_with_a_subject_that_is_too_long()
146+
{
147+
$user = $this->createUser();
148+
$tag = factory(Tag::class)->create(['name' => 'Test Tag']);
149+
factory(Thread::class)->create([
150+
'author_id' => $user->id(),
151+
'slug' => 'my-first-thread',
152+
]);
153+
154+
$this->loginAs($user);
155+
156+
$this->visit('/forum/my-first-thread/edit')
157+
->submitForm('Update Thread', [
158+
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
159+
'body' => 'This is a thread with 82 characters in the subject',
160+
'tags' => [$tag->id()],
161+
])
162+
->seePageIs('/forum/my-first-thread/edit')
163+
->see('Something went wrong. Please review the fields below.')
164+
->see('The subject may not be greater than 60 characters.');
165+
}
125166
}

0 commit comments

Comments
 (0)