Commit edd4edf8 authored by Vipul Basapati's avatar Vipul Basapati

Added update validation for name in Blog and added test for it

parent a24f5e10
...@@ -39,6 +39,7 @@ class UpdateBlogTagsRequest extends Request ...@@ -39,6 +39,7 @@ class UpdateBlogTagsRequest extends Request
public function messages() public function messages()
{ {
return [ return [
'name.unique' => 'Blog Tag name already exists, please enter a different name.',
'name.required' => 'Blog Tag name is a required field.', 'name.required' => 'Blog Tag name is a required field.',
'name.max' => 'Blog Tag may not be greater than 191 characters.', 'name.max' => 'Blog Tag may not be greater than 191 characters.',
]; ];
......
...@@ -27,7 +27,7 @@ class UpdateBlogsRequest extends Request ...@@ -27,7 +27,7 @@ class UpdateBlogsRequest extends Request
public function rules() public function rules()
{ {
return [ return [
'name' => 'required|max:191', 'name' => 'required|max:191|unique:blogs,name,' . $this->segment(3),
'content' => 'required', 'content' => 'required',
'categories' => 'required', 'categories' => 'required',
'tags' => 'required', 'tags' => 'required',
...@@ -42,6 +42,7 @@ class UpdateBlogsRequest extends Request ...@@ -42,6 +42,7 @@ class UpdateBlogsRequest extends Request
public function messages() public function messages()
{ {
return [ return [
'name.unique' => 'Blog name already exists, please enter a different name.',
'name.required' => 'Please insert Blog Title', 'name.required' => 'Please insert Blog Title',
'name.max' => 'Blog Title may not be greater than 191 characters.', 'name.max' => 'Blog Title may not be greater than 191 characters.',
]; ];
......
...@@ -196,4 +196,17 @@ class ManageBlogsTest extends TestCase ...@@ -196,4 +196,17 @@ class ManageBlogsTest extends TestCase
$this->assertDatabaseMissing(config('module.blogs.table'), ['id' => $this->blog->id, 'deleted_at' => null]); $this->assertDatabaseMissing(config('module.blogs.table'), ['id' => $this->blog->id, 'deleted_at' => null]);
} }
/** @test */
public function a_user_can_not_update_a_blog_with_same_name()
{
$this->actingAs($this->admin)->withExceptionHandling();
$catCategory = create(Blog::class, ['name' => 'Cat']);
$dogCategory = create(Blog::class, ['name' => 'Dog']);
$this->patch(route('admin.blogs.update', $dogCategory),
['name' => 'Cat']
)->assertSessionHasErrors('name'); ;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment