Skip to content
Closed
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/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Story < ActiveRecord::Base
UNTITLED = "[untitled]"

def headline
self.title.nil? ? UNTITLED : self.title[0, 50]
self.title.nil? ? UNTITLED : Loofah::Helpers.strip_tags(self.title)[0, 50]
end

def lead
Expand Down
28 changes: 23 additions & 5 deletions spec/models/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,31 @@
end

describe "#headline" do
it "truncates to 50 chars" do
story.headline.size.should eq(50)
context "plain string title" do

it "truncates to 50 chars" do
story.headline.size.should eq(50)
end

it "uses a fallback string if story has no title" do
story.title = nil
story.headline.should eq(Story::UNTITLED)
end
end

it "uses a fallback string if story has no title" do
story.title = nil
story.headline.should eq(Story::UNTITLED)
context "title with HTML tags" do
before { story.title = "<a>#{Faker::Lorem.sentence(50)}</a>" }

it "strips HTML tags from story title" do
story.headline.should_not start_with('<a>')
story.headline.should_not end_with('</a>')
end

it "truncates to 50 chars after stripping tags" do
story.headline.should_not start_with('<a>')
story.headline.size.should eq(50)
end

end
end

Expand Down