Merge pull request #583 from wpp/add_some_user_specs

Add a few specs to user model
This commit is contained in:
Robin Ward 2013-03-29 10:01:32 -07:00
commit 3d615ada12

View File

@ -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