From 47684c2a2c44186b0b7eac3002582875efa6855b Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 22 May 2017 18:10:50 +0200 Subject: [PATCH] Make email and nickname case insensitive. --- .../20170522160642_case_insensivtivity.exs | 19 +++++++++++++++++++ test/user_test.exs | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 priv/repo/migrations/20170522160642_case_insensivtivity.exs diff --git a/priv/repo/migrations/20170522160642_case_insensivtivity.exs b/priv/repo/migrations/20170522160642_case_insensivtivity.exs new file mode 100644 index 000000000..c7565946e --- /dev/null +++ b/priv/repo/migrations/20170522160642_case_insensivtivity.exs @@ -0,0 +1,19 @@ +defmodule Pleroma.Repo.Migrations.CaseInsensivtivity do + use Ecto.Migration + + def up do + execute ("create extension if not exists citext") + alter table(:users) do + modify :email, :citext + modify :nickname, :citext + end + end + + def down do + alter table(:users) do + modify :email, :string + modify :nickname, :string + end + execute ("drop extension if exists citext") + end +end diff --git a/test/user_test.exs b/test/user_test.exs index b87d31862..6a7ecca27 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -114,6 +114,13 @@ test "gets an existing user" do assert user == fetched_user end + test "gets an existing user, case insensitive" do + user = insert(:user, nickname: "nick") + fetched_user = User.get_or_fetch_by_nickname("NICK") + + assert user == fetched_user + end + test "fetches an external user via ostatus if no user exists" do fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la") assert fetched_user.nickname == "shp@social.heldscal.la"