Skip to content

Commit

Permalink
Fix User::avatar_url + add Id display tests
Browse files Browse the repository at this point in the history
User::avatar_url was formatting the user's Id as a mention, rather than
the inner u64.
  • Loading branch information
Austin Hellyer committed Dec 15, 2016
1 parent 16bd765 commit 0708ccf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/model/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl CurrentUser {
/// Returns the formatted URL of the user's icon, if one exists.
pub fn avatar_url(&self) -> Option<String> {
self.avatar.as_ref().map(|av|
format!(cdn!("/avatars/{}/{}.jpg"), self.id, av))
format!(cdn!("/avatars/{}/{}.jpg"), self.id.0, av))
}

/// Edits the current user's profile settings.
Expand Down Expand Up @@ -101,7 +101,7 @@ impl User {
/// Returns the formatted URL of the user's icon, if one exists.
pub fn avatar_url(&self) -> Option<String> {
self.avatar.as_ref().map(|av|
format!(cdn!("/avatars/{}/{}.jpg"), self.id, av))
format!(cdn!("/avatars/{}/{}.jpg"), self.id.0, av))
}

/// Gets user as `Member` of a guild.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_formatters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extern crate serenity;

use serenity::model::*;

#[test]
fn test_formatters() {
assert_eq!(format!("{}", ChannelId(1)), "<#1>");
assert_eq!(format!("{}", EmojiId(2)), "2");
assert_eq!(format!("{}", GuildId(3)), "3");
assert_eq!(format!("{}", RoleId(4)), "<@&4>");
assert_eq!(format!("{}", UserId(5)), "<@5>");
}
24 changes: 24 additions & 0 deletions tests/test_user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern crate serenity;

use serenity::model::{User, UserId};

fn gen() -> User {
User {
id: UserId(210),
avatar: Some("abc".to_owned()),
bot: true,
discriminator: "1432".to_owned(),
name: "test".to_owned(),
}
}

#[test]
fn test_core() {
let mut user = gen();

assert!(user.avatar_url().unwrap().ends_with("/avatars/210/abc.jpg"));

user.avatar = None;

assert!(user.avatar_url().is_none());
}

0 comments on commit 0708ccf

Please sign in to comment.