Skip to content

Commit

Permalink
Normalize login
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Oct 12, 2023
1 parent 6117d43 commit 873f822
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 1 addition & 5 deletions app/models/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Editor < ApplicationRecord
has_many :track_aeics, dependent: :destroy
has_many :managed_tracks, through: :track_aeics, source: :track

normalizes :login, with: -> login { login.gsub(/^@/, "") }
before_save :clear_title, if: :board_removed?
before_save :format_login, if: :login_changed?
before_save :add_default_avatar_url

ACTIVE_EDITOR_STATES = [
Expand Down Expand Up @@ -95,10 +95,6 @@ def board_removed?
kind_changed? && kind_was == "board"
end

def format_login
login.gsub!(/^@/, "")
end

def add_default_avatar_url
if avatar_url.blank? && login.present?
self.avatar_url = "https://github.com/#{login}.png"
Expand Down
9 changes: 4 additions & 5 deletions spec/models/editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@
end
end

describe "#format_login" do
let(:editor) { build(:editor, login: "@somebody") }

it "removes @'s" do
expect { editor.save }.to change { editor.login }.to "somebody"
describe "normalize login" do
it "removes initial @'s" do
editor = create(:editor, login: "@somebody")
expect(editor.login).to eq("somebody")
end
end

Expand Down

0 comments on commit 873f822

Please sign in to comment.