FIX: couldn't start a 4-spaces block on the first line of a post

This commit is contained in:
Régis Hanol 2014-09-02 01:18:06 +02:00
parent 22fbae8556
commit 61db6c95d2
4 changed files with 14 additions and 3 deletions

View File

@ -203,7 +203,7 @@ class PostCreator
end end
def setup_post def setup_post
@opts[:raw] = TextCleaner.normalize_whitespaces(@opts[:raw]).strip @opts[:raw] = TextCleaner.normalize_whitespaces(@opts[:raw]).gsub(/\s+\z/, "")
post = @topic.posts.new(raw: @opts[:raw], post = @topic.posts.new(raw: @opts[:raw],
user: @user, user: @user,

View File

@ -19,7 +19,7 @@ class PostRevisor
def revise!(editor, new_raw, opts = {}) def revise!(editor, new_raw, opts = {})
@editor = editor @editor = editor
@opts = opts @opts = opts
@new_raw = TextCleaner.normalize_whitespaces(new_raw).strip @new_raw = TextCleaner.normalize_whitespaces(new_raw).gsub(/\s+\z/, "")
# TODO this is not in a transaction - dangerous! # TODO this is not in a transaction - dangerous!
return false unless should_revise? return false unless should_revise?

View File

@ -468,7 +468,6 @@ describe PostCreator do
end end
end end
describe "suspended users" do describe "suspended users" do
it "does not allow suspended users to create topics" do it "does not allow suspended users to create topics" do
user = Fabricate(:user, suspended_at: 1.month.ago, suspended_till: 1.month.from_now) user = Fabricate(:user, suspended_at: 1.month.ago, suspended_till: 1.month.from_now)
@ -479,5 +478,10 @@ describe PostCreator do
end end
end end
it "doesn't strip starting whitespaces" do
post = PostCreator.new(user, { title: "testing whitespace stripping", raw: " <-- whitespaces --> " }).create
post.raw.should == " <-- whitespaces -->"
end
end end

View File

@ -272,5 +272,12 @@ describe PostRevisor do
}.to_not change { topic.excerpt } }.to_not change { topic.excerpt }
end end
end end
it "doesn't strip starting whitespaces" do
subject.revise!(post.user, " <-- whitespaces --> ")
post.reload
post.raw.should == " <-- whitespaces -->"
end
end end
end end