Users can change their own username at any time if they have no posts

This commit is contained in:
Neil Lalonde 2013-08-23 11:23:00 -04:00
parent 6a3c849067
commit 663adde90e
2 changed files with 13 additions and 4 deletions
lib
spec/components

View file

@ -273,7 +273,7 @@ class Guardian
end end
def can_edit_username?(user) def can_edit_username?(user)
is_staff? || (is_me?(user) && user.created_at > SiteSetting.username_change_period.days.ago) is_staff? || (is_me?(user) && (user.post_count == 0 || user.created_at > SiteSetting.username_change_period.days.ago))
end end
# Deleting Methods # Deleting Methods

View file

@ -1162,13 +1162,22 @@ describe Guardian do
let(:target_user) { build(:user, created_at: 4.days.ago) } let(:target_user) { build(:user, created_at: 4.days.ago) }
context 'with no posts' do
include_examples "staff can always change usernames" include_examples "staff can always change usernames"
it "is true for the user to change his own username" do
Guardian.new(target_user).can_edit_username?(target_user).should be_true
end
end
context 'with posts' do
before { target_user.stubs(:post_count).returns(1) }
include_examples "staff can always change usernames"
it "is false for the user to change his own username" do it "is false for the user to change his own username" do
Guardian.new(target_user).can_edit_username?(target_user).should be_false Guardian.new(target_user).can_edit_username?(target_user).should be_false
end end
end end
end end
end
end end