diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e6b5d2ee8ca..798d721e6fe 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,6 +14,9 @@ describe User do it { should have_many :views } it { should have_many :user_visits } it { should belong_to :approved_by } + it { should have_many :email_logs } + it { should have_many :topic_allowed_users } + it { should have_many :invites } it { should validate_presence_of :username } it { should validate_presence_of :email } @@ -165,7 +168,30 @@ describe User do user.reload user.username_lower.should == new_username.downcase end + end + context 'failure' do + let(:wrong_username) { "" } + let(:username_before_change) { user.username } + let(:username_lower_before_change) { user.username_lower } + + before do + @result = user.change_username(wrong_username) + end + + it 'returns false' do + @result.should be_false + end + + it 'should not change the username' do + user.reload + user.username.should == username_before_change + end + + it 'should not change the username_lower' do + user.reload + user.username_lower.should == username_lower_before_change + end end end @@ -191,6 +217,20 @@ describe User do end end end + + it 'does not allow non moderators to delete all posts' do + invalid_guardian = Guardian.new(Fabricate(:user)) + + expect do + @user.delete_all_posts!(invalid_guardian) + end.to raise_error Discourse::InvalidAccess + + @posts.each do |p| + p.reload + p.should be_present + p.topic.should be_present + end + end end describe 'new' do