Add a few specs to user model

I noticed a few assertions of the has_many type were missing.
Also added a couple of specs which were testing in one direction only.
Just tipping my toes in discourse hope this helps a little.
This commit is contained in:
Philipp Weissensteiner 2013-03-29 00:24:35 +01:00
parent f2d61496af
commit 095cbaa093
1 changed files with 40 additions and 0 deletions

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