mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: word_count wasn't working with non-latin sentences
This commit is contained in:
parent
61650edfd4
commit
cf4cb2126a
@ -172,7 +172,7 @@ class PostCreator
|
|||||||
def self.before_create_tasks(post)
|
def self.before_create_tasks(post)
|
||||||
set_reply_info(post)
|
set_reply_info(post)
|
||||||
|
|
||||||
post.word_count = post.raw.scan(/\w+/).size
|
post.word_count = post.raw.scan(/[[:word:]]+/).size
|
||||||
post.post_number ||= Topic.next_post_number(post.topic_id, post.reply_to_post_number.present?)
|
post.post_number ||= Topic.next_post_number(post.topic_id, post.reply_to_post_number.present?)
|
||||||
|
|
||||||
cooking_options = post.cooking_options || {}
|
cooking_options = post.cooking_options || {}
|
||||||
|
@ -229,7 +229,7 @@ class PostRevisor
|
|||||||
end
|
end
|
||||||
|
|
||||||
@post.last_editor_id = @editor.id
|
@post.last_editor_id = @editor.id
|
||||||
@post.word_count = @fields[:raw].scan(/\w+/).size if @fields.has_key?(:raw)
|
@post.word_count = @fields[:raw].scan(/[[:word:]]+/).size if @fields.has_key?(:raw)
|
||||||
@post.self_edits += 1 if self_edit?
|
@post.self_edits += 1 if self_edit?
|
||||||
|
|
||||||
remove_flags_and_unhide_post
|
remove_flags_and_unhide_post
|
||||||
|
@ -595,12 +595,12 @@ describe PostCreator do
|
|||||||
|
|
||||||
describe "word_count" do
|
describe "word_count" do
|
||||||
it "has a word count" do
|
it "has a word count" do
|
||||||
creator = PostCreator.new(user, title: 'some inspired poetry for a rainy day', raw: 'mary had a little lamb, little lamb, little lamb. mary had a little lamb')
|
creator = PostCreator.new(user, title: 'some inspired poetry for a rainy day', raw: 'mary had a little lamb, little lamb, little lamb. mary had a little lamb. Здравствуйте')
|
||||||
post = creator.create
|
post = creator.create
|
||||||
expect(post.word_count).to eq(14)
|
expect(post.word_count).to eq(15)
|
||||||
|
|
||||||
post.topic.reload
|
post.topic.reload
|
||||||
expect(post.topic.word_count).to eq(14)
|
expect(post.topic.word_count).to eq(15)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -278,14 +278,14 @@ describe PostRevisor do
|
|||||||
|
|
||||||
describe 'with a new body' do
|
describe 'with a new body' do
|
||||||
let(:changed_by) { Fabricate(:coding_horror) }
|
let(:changed_by) { Fabricate(:coding_horror) }
|
||||||
let!(:result) { subject.revise!(changed_by, { raw: "lets update the body" }) }
|
let!(:result) { subject.revise!(changed_by, { raw: "lets update the body. Здравствуйте" }) }
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(result).to eq(true)
|
expect(result).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates the body' do
|
it 'updates the body' do
|
||||||
expect(post.raw).to eq("lets update the body")
|
expect(post.raw).to eq("lets update the body. Здравствуйте")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the invalidate oneboxes attribute' do
|
it 'sets the invalidate oneboxes attribute' do
|
||||||
@ -306,9 +306,9 @@ describe PostRevisor do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "updates the word count" do
|
it "updates the word count" do
|
||||||
expect(post.word_count).to eq(4)
|
expect(post.word_count).to eq(5)
|
||||||
post.topic.reload
|
post.topic.reload
|
||||||
expect(post.topic.word_count).to eq(4)
|
expect(post.topic.word_count).to eq(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'second poster posts again quickly' do
|
context 'second poster posts again quickly' do
|
||||||
|
Loading…
Reference in New Issue
Block a user