Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User bio #286

Merged
merged 14 commits into from
Jul 9, 2017
Merged

User bio #286

merged 14 commits into from
Jul 9, 2017

Conversation

eduardostuart
Copy link
Contributor

@eduardostuart eduardostuart commented Jul 8, 2017

Allow users to add a short bio of 140 characters. (reference: #283)

  1. Added User bio content into user profile page.
  2. New migration file - bio column (144 characters, nullable)
  3. Styles updated - add margins and max-width to bio text
  4. Feature tests updated
  5. UpdateProfileRequest updated. Added sometimes|max:144 for bio field.
  6. Add boot event handlers to remove html tags from bio

Preview

screen shot 2017-07-08 at 23 06 11
screen shot 2017-07-08 at 23 08 49
screen shot 2017-07-08 at 23 11 29

@eduardostuart eduardostuart changed the title User bio - #283 User bio Jul 8, 2017
@driesvints
Copy link
Member

@eduardostuart thank you for sending this in! I was already reviewing but saw you pushed some more commits. Request a review from me when you're done.

@eduardostuart
Copy link
Contributor Author

@driesvints ok!

Should I also add bio field into registration? What do you think?

@eduardostuart
Copy link
Contributor Author

@driesvints can you review?

Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: thank you for sending this in and helping out! The screenshots really helped, good job :)

I have some changes I'd like you to make. First, it might be best to increase the bio length to 160 characters to match Twitter's max bio length. Second, it's best if we just always have bio be a string, that way you don't need to deal with null values.

Also, something went wrong with the yarn.lock file, can you please revert those changes?

There is more feedback, feel free to take your time to go through it and get back to me when you made the changes 🙂

@@ -12,9 +12,15 @@ public function rules()
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,email,'.Auth::id(),
'username' => 'required|max:255|unique:users,username,'.Auth::id(),
'bio' => 'sometimes|max:144',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increase this to 160. I also don't think we need to use sometimes here?

];
}

public function bio(): ?string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the nullable return type

];
}

public function bio(): ?string
{
return $this->get('bio');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a default value of an empty string here

@@ -29,6 +29,7 @@ public static function fromRequest(User $user, UpdateProfileRequest $request): s
'name' => $request->name(),
'email' => $request->email(),
'username' => strtolower($request->username()),
'bio' => $request->bio(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with 'bio' => trim(strip_tags($request->bio()),

app/User.php Outdated
static::creating($eventHandler);
static::updating($eventHandler);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, we can do this in the job.

@@ -38,6 +38,7 @@ protected function createUser(array $attributes = []): User
'email' => 'john@example.com',
'password' => bcrypt('password'),
'github_username' => 'johndoe',
'bio' => 'John Doe bio content',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed here, remove it.

])
->seePageIs('/settings')
->see('Something went wrong. Please review the fields below.')
->see('The email has already been taken.')
->see('The username has already been taken.');
->see('The username has already been taken.')
->see('My short bio text');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this from this test.

@@ -46,11 +48,13 @@ public function users_cannot_choose_duplicate_usernames_or_email_addresses()
'name' => 'Freek Murze',
'email' => 'freek@example.com',
'username' => 'freekmurze',
'bio' => 'My short bio text',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this from this test.

yarn.lock Outdated
os-locale "^1.4.0"
window-size "^0.1.2"
y18n "^3.2.0"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what went wrong here but please revert the changes to the yarn.lock file.

app/User.php Outdated
public function hasBio(): bool
{
return ! empty($this->bio());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method.

@eduardostuart
Copy link
Contributor Author

@driesvints all done 😄

Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job. Some last feedback.

Btw, one more thing: when I said to remove those things from the SettingsTest feature test I meant only for the users_cannot_choose_duplicate_usernames_or_email_addresses method. You can add the changes of the users_can_update_their_profile back.

*/
public function down()
{
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the down method entirely :)

@@ -10,6 +10,12 @@
@endcan

<h2>{{ $user->name() }}</h2>
@if ($bio = $user->bio())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this white line.

@@ -10,6 +10,12 @@
@endcan

<h2>{{ $user->name() }}</h2>
@if ($bio = $user->bio())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a white line above the if statement.


$this->assertEquals('my bio', $user->bio());
$this->assertEquals('John Doe Junior', $user->name());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed to login the user. Since you're testing a component no "state" of the active user is needed. You can re-write this as follow:

    /** @test */
    public function we_can_update_a_user_profile()
    {
        $user = (new UpdateProfile($this->createUser(), ['bio' => 'my bio', 'name' => 'John Doe Junior']))->handle();

        $this->assertEquals('my bio', $user->bio());
        $this->assertEquals('John Doe Junior', $user->name());
    }

Make sure that the handle method returns the updated user.

@eduardostuart
Copy link
Contributor Author

@driesvints Done! 👍 Can you check?

@driesvints driesvints merged commit a911275 into laravelio:master Jul 9, 2017
@driesvints
Copy link
Member

Thank you for your work on this! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants