2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

merge master

This commit is contained in:
xdite 2013-02-13 15:16:39 +08:00
commit a7908e07d1
260 changed files with 3643 additions and 759 deletions

View file

@ -61,4 +61,34 @@ describe Mothership do
Mothership.current_discourse_version().should == 1.0
end
end
describe '#change_nickname' do
it 'should return true when nickname is changed successfully' do
RestClient.stubs(:put).returns( {success: 'OK'}.to_json )
Mothership.change_nickname('MacGyver', 'MacG').should be_true
end
it 'should return raise NicknameUnavailable when nickname is not available' do
RestClient.stubs(:put).returns( {failed: -200}.to_json )
expect {
Mothership.change_nickname('MacGyver', 'MacG')
}.to raise_error(Mothership::NicknameUnavailable)
end
# TODO: General error handling in mothership.rb
# it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do
# RestClient.stubs(:put).returns( {failed: -13}.to_json )
# expect {
# Mothership.change_nickname('MacGyver', 'MacG')
# }.to raise_error(Mothership::ActionForbidden)
# end
# it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do
# RestClient.stubs(:put).returns( {failed: -13}.to_json )
# expect {
# Mothership.change_nickname('MacGyver', 'MacG')
# }.to raise_error(Mothership::ActionForbidden)
# end
end
end

View file

@ -26,6 +26,62 @@ describe TopicView do
lambda { TopicView.new(topic.id, nil) }.should raise_error(Discourse::NotLoggedIn)
end
describe "#get_canonical_path" do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
let(:path) { "/1234" }
before do
topic.expects(:relative_url).returns(path)
described_class.any_instance.expects(:find_topic).with(1234).returns(topic)
end
context "without a post number" do
context "without a page" do
it "generates a canonical path for a topic" do
described_class.new(1234, user).canonical_path.should eql(path)
end
end
context "with a page" do
let(:path_with_page) { "/1234?page=5" }
it "generates a canonical path for a topic" do
described_class.new(1234, user, page: 5).canonical_path.should eql(path_with_page)
end
end
end
context "with a post number" do
let(:path_with_page) { "/1234?page=10" }
before { SiteSetting.stubs(:posts_per_page).returns(5) }
it "generates a canonical path for a topic" do
described_class.new(1234, user, post_number: 50).canonical_path.should eql(path_with_page)
end
end
end
describe "#next_page" do
let(:posts) { [stub(post_number: 1), stub(post_number: 2)] }
let(:topic) do
topic = Fabricate(:topic)
topic.stubs(:posts).returns(posts)
topic.stubs(:highest_post_number).returns(5)
topic
end
let(:user) { Fabricate(:user) }
before do
described_class.any_instance.expects(:find_topic).with(1234).returns(topic)
described_class.any_instance.stubs(:filter_posts)
SiteSetting.stubs(:posts_per_page).returns(2)
end
it "should return the next page" do
described_class.new(1234, user).next_page.should eql(1)
end
end
context '.posts_count' do
it 'returns the two posters with their counts' do
topic_view.posts_count.to_a.should =~ [[first_poster.id, 2], [coding_horror.id, 1]]
@ -111,29 +167,24 @@ describe TopicView do
context '.posts' do
context 'near a post_number' do
context 'with a valid post_number' do
before do
topic.reload
topic_view.filter_posts_near(p2.post_number)
end
let (:near_topic_view) { TopicView.new(topic.id, coding_horror, post_number: p2.post_number) }
it 'returns posts around a post number' do
topic_view.posts.should == [p1, p2, p3]
end
it 'has a min of the 1st post number' do
topic_view.min.should == p1.post_number
end
it 'has a max of the 3rd post number' do
topic_view.max.should == p3.post_number
end
it 'is the inital load' do
topic_view.should be_initial_load
end
it 'returns posts around a post number' do
near_topic_view.posts.should == [p1, p2, p3]
end
it 'has a min of the 1st post number' do
near_topic_view.min.should == p1.post_number
end
it 'has a max of the 3rd post number' do
near_topic_view.max.should == p3.post_number
end
it 'is the inital load' do
near_topic_view.should be_initial_load
end
end
context 'before a post_number' do

View file

@ -267,15 +267,9 @@ describe TopicsController do
it "reviews the user for a promotion if they're new" do
user.update_column(:trust_level, TrustLevel.Levels[:new])
promotion.expects(:review)
Promotion.any_instance.expects(:review)
get :show, id: topic.id
end
it "doesn't reviews the user for a promotion if they're basic" do
promotion.expects(:review).never
get :show, id: topic.id
end
end
context 'filters' do

View file

@ -379,6 +379,28 @@ describe UsersController do
let(:create_params) { {:name => @user.name, :username => @user.username, :password => "strongpassword", :email => @user.email, :challenge => 'abc'} }
it_should_behave_like 'honeypot fails'
end
shared_examples_for 'failed signup due to password problem' do
it 'should not create a new User' do
expect { xhr :post, :create, create_params }.to_not change { User.count }
end
it 'should report failed' do
xhr :post, :create, create_params
json = JSON::parse(response.body)
json["success"].should_not be_true
end
end
context 'when password is blank' do
let(:create_params) { {:name => @user.name, :username => @user.username, :password => "", :email => @user.email} }
it_should_behave_like 'failed signup due to password problem'
end
context 'when password param is missing' do
let(:create_params) { {:name => @user.name, :username => @user.username, :email => @user.email} }
it_should_behave_like 'failed signup due to password problem'
end
end
context '.username' do

View file

@ -37,11 +37,6 @@ describe PostAlertObserver do
context 'quotes' do
it 'notifies a user by display username' do
lambda {
Fabricate(:post, raw: '[quote="Evil Trout, post:1"]whatup[/quote]')
}.should change(evil_trout.notifications, :count).by(1)
end
it 'notifies a user by username' do
lambda {

View file

@ -86,7 +86,8 @@ describe Post do
let(:post_no_images) { Fabricate.build(:post, post_args) }
let(:post_one_image) { Fabricate.build(:post, post_args.merge(raw: "![sherlock](http://bbc.co.uk/sherlock.jpg)")) }
let(:post_two_images) { Fabricate.build(:post, post_args.merge(raw: "<img src='http://discourse.org/logo.png'> <img src='http://bbc.co.uk/sherlock.jpg'>")) }
let(:post_with_emoticons) { Fabricate.build(:post, post_args.merge(raw: '<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="emoji"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="emoji">')) }
let(:post_with_avatars) { Fabricate.build(:post, post_args.merge(raw: '<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="avatar"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="avatar">')) }
let(:post_with_two_classy_images) { Fabricate.build(:post, post_args.merge(raw: "<img src='http://discourse.org/logo.png' class='classy'> <img src='http://bbc.co.uk/sherlock.jpg' class='classy'>")) }
it "returns 0 images for an empty post" do
Fabricate.build(:post).image_count.should == 0
@ -100,10 +101,14 @@ describe Post do
post_two_images.image_count.should == 2
end
it "doesn't count emoticons as images" do
post_with_emoticons.image_count.should == 0
it "doesn't count avatars as images" do
post_with_avatars.image_count.should == 0
end
it "doesn't count whitelisted images" do
Post.stubs(:white_listed_image_classes).returns(["classy"])
post_with_two_classy_images.image_count.should == 0
end
context "validation" do
it "allows a new user to make a post with one image" do

View file

@ -638,7 +638,7 @@ describe User do
it 'should return false' do
user.email_tokens.each {|t| t.destroy}
user.reload
user.email_confirmed?.should be_false
user.email_confirmed?.should be_true
end
end
end