Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def truncate(message, length)
end

def twitter_message
base_message = strip_tags(body)
base_message = CGI.unescapeHTML strip_tags(html(:all))
if too_long?("#{base_message} (#{short_link})")
max_length = 140 - "... (#{redirect.from_url})".length - 1
"#{truncate(base_message, max_length)}... (#{redirect.from_url})"
Expand Down
26 changes: 26 additions & 0 deletions spec/models/note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,32 @@
it { expect(note.twitter_message.length).to eq(140) }
end

context "with a message containing codes interpreted by the text filter" do
let(:tweet) do
"I am **not** a crook"
end
let(:expected_tweet) do
"I am not a crook (#{note.short_link})"
end

it "does not include the text filter codes" do
expect(note.twitter_message).to eq(expected_tweet)
end
end

context "with a message containing literal HTML encodings" do
let(:tweet) do
"In HTML, & is encoded as `&`"
end
let(:expected_tweet) do
"In HTML, & is encoded as & (#{note.short_link})"
end

it "contains the bare text representation of the note body" do
expect(note.twitter_message).to eq(expected_tweet)
end
end

context "don't cut word" do
let(:tweet) do
"Le #mobprogramming c'est un peu comme faire un dojo sur une journée entière" \
Expand Down
Loading