<commit_before><?php

use Illuminate\Foundation\Testing\DatabaseMigrations;
use App\User;
use App\Role;

class AdminUsersControllerTest extends BrowserKitTest
{
    use DatabaseMigrations;

    public function testIndex()
    {
        $admin = factory(User::class)->create();
        $admin->roles()->attach(factory(Role::class)->states('admin')->create());

        $response = $this->actingAs($admin)->call('GET', route('admin.users.index'));

        $this->assertResponseOk();
        $this->assertViewHas('users');
    }

    public function testEdit()
    {
        $admin = factory(User::class)->create();
        $admin->roles()->attach(factory(Role::class)->states('admin')->create());

        $response = $this->actingAs($admin)->call('GET', route('admin.users.edit', $admin));

        $this->assertResponseOk();
        $this->assertViewHas('roles');
        $this->assertViewHas('user');
    }
}
<commit_msg>Adding tests to update method<commit_after><?php

use Illuminate\Foundation\Testing\DatabaseMigrations;
use App\User;
use App\Role;

class AdminUsersControllerTest extends BrowserKitTest
{
    use DatabaseMigrations;

    public function testIndex()
    {
        $admin = factory(User::class)->create();
        $admin->roles()->attach(factory(Role::class)->states('admin')->create());

        $response = $this->actingAs($admin)->call('GET', route('admin.users.index'));

        $this->assertResponseOk();
        $this->assertViewHas('users');
    }

    public function testEdit()
    {
        $admin = factory(User::class)->create();
        $admin->roles()->attach(factory(Role::class)->states('admin')->create());

        $response = $this->actingAs($admin)->call('GET', route('admin.users.edit', $admin));

        $this->assertResponseOk();
        $this->assertViewHas('roles');
        $this->assertViewHas('user');
    }

    public function testUpdate()
    {
        $admin = factory(User::class)->create();
        $admin->roles()->attach(factory(Role::class)->states('admin')->create());
        $user = factory(User::class)->create();

        $params = [
            'name' => 'luke',
            'email' => '<EMAIL>'
        ];

        $response = $this->actingAs($admin)->call('PATCH', route('admin.users.update', $user->id), $params);

        $user = $user->fresh();
        $this->seeInDatabase('users', $params);
        $this->assertEquals($params['email'], $user->email);
        $this->assertResponseStatus('302');
    }

    public function testUpdateRoles()
    {
        $admin = factory(User::class)->create();
        $admin->roles()->attach(factory(Role::class)->states('admin')->create());
        $user = factory(User::class)->create();

        $role_editor = factory(Role::class)->states('editor')->create();

        $params = [
            'name' => 'luke',
            'email' => '<EMAIL>',
            'roles' => ['editor' => $role_editor->id]
        ];

        $response = $this->actingAs($admin)->call('PATCH', route('admin.users.update', $user->id), $params);

        $this->assertRedirectedToRoute('admin.users.edit', ['id' => $user->id]);
        $this->assertTrue($user->roles->pluck('id')->contains($role_editor->id));
    }
}

{'fraction_non_alphanumeric': 0.206487835308796, 'fraction_numerical': 0.0009357454772301934, 'mean_word_length': 3.1976439790575917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3393473', 'n_tokens_mistral': 947, 'n_tokens_neox': 921, 'n_words': 130}