Merge branch 'master' of github.com:discourse/discourse

This commit is contained in:
Sam
2013-12-20 16:17:52 +11:00
31 changed files with 325 additions and 82 deletions

View File

@@ -10,6 +10,7 @@ describe ComposerMessagesFinder do
it "calls all the message finders" do
finder.expects(:check_education_message).once
finder.expects(:check_new_user_many_replies).once
finder.expects(:check_avatar_notification).once
finder.expects(:check_sequential_replies).once
finder.expects(:check_dominating_topic).once
@@ -56,6 +57,24 @@ describe ComposerMessagesFinder do
finder.check_education_message.should be_blank
end
end
end
context '.check_new_user_many_replies' do
let(:user) { Fabricate.build(:user) }
context 'replying' do
let(:finder) { ComposerMessagesFinder.new(user, composerAction: 'reply') }
it "has no message when `posted_too_much_in_topic?` is false" do
user.expects(:posted_too_much_in_topic?).returns(false)
finder.check_new_user_many_replies.should be_blank
end
it "has a message when a user has posted too much" do
user.expects(:posted_too_much_in_topic?).returns(true)
finder.check_new_user_many_replies.should be_present
end
end
end

View File

@@ -0,0 +1,60 @@
require 'spec_helper'
describe PasswordValidator do
let(:validator) { described_class.new({attributes: :password}) }
subject(:validate) { validator.validate_each(record,:password,@password) }
context "password required" do
let(:record) { u = Fabricate.build(:user, password: @password); u.password_required!; u }
context "min password length is 8" do
before { SiteSetting.stubs(:min_password_length).returns(8) }
it "doesn't add an error when password is good" do
@password = "weron235alsfn234"
validate
record.errors[:password].should_not be_present
end
it "adds an error when password is too short" do
@password = "p"
validate
record.errors[:password].should be_present
end
it "adds an error when password is blank" do
@password = ''
validate
record.errors[:password].should be_present
end
it "adds an error when password is nil" do
@password = nil
validate
record.errors[:password].should be_present
end
end
context "min password length is 12" do
before { SiteSetting.stubs(:min_password_length).returns(12) }
it "adds an error when password length is 11" do
@password = "gt38sdt92bv"
validate
record.errors[:password].should be_present
end
end
end
context "password not required" do
let(:record) { Fabricate.build(:user, password: @password) }
it "doesn't add an error if password is not required" do
@password = nil
validate
record.errors[:password].should_not be_present
end
end
end

View File

@@ -24,6 +24,20 @@ describe Validators::PostValidator do
end
end
context "too_many_posts" do
it "should be invalid when the user has posted too much" do
post.user.expects(:posted_too_much_in_topic?).returns(true)
validator.max_posts_validator(post)
expect(post.errors.count).to be > 0
end
it "should be valid when the user hasn't posted too much" do
post.user.expects(:posted_too_much_in_topic?).returns(false)
validator.max_posts_validator(post)
expect(post.errors.count).to be(0)
end
end
context "invalid post" do
it "should be invalid" do
validator.validate(post)

View File

@@ -87,6 +87,14 @@ describe Topic do
Then { scheduled_jobs_for(:close_topic).should have(2).jobs }
end
end
context 'a topic that has been auto-closed' do
Given(:admin) { Fabricate(:admin) }
Given!(:auto_closed_topic) { Fabricate(:topic, user: admin, closed: true, auto_close_at: 1.day.ago, auto_close_user_id: admin.id, auto_close_started_at: 6.days.ago) }
When { auto_closed_topic.update_status('closed', false, admin) }
Then { auto_closed_topic.reload.auto_close_at.should be_nil }
And { auto_closed_topic.auto_close_started_at.should be_nil }
end
end
end
end