diaspora/spec/helpers/posts_helper_spec.rb
Damien f4b3f2fd1e Consider Markdown header content as post title
clarify regexp and correct some bad backtracking

add specs

rewrite regex

convert mardown style title to plain text title

fix bad indentation

add jasmine test for post-viewer.js

tries to fix bad jasmine test
2013-07-31 14:59:02 +02:00

57 lines
1.9 KiB
Ruby

# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe PostsHelper do
describe '#post_page_title' do
before do
@sm = FactoryGirl.create(:status_message)
end
context 'with posts with text' do
context 'when :length is passed in parameters' do
it 'returns string of size less or equal to :length' do
@sm = stub(:text => "## My title\n Post content...")
string_size = 12
post_page_title(@sm, :length => string_size ).size.should <= string_size
end
end
context 'when :length is not passed in parameters' do
context 'with a Markdown header of less than 200 characters on first line'do
it 'returns atx style header' do
@sm = stub(:text => "## My title\n Post content...")
post_page_title(@sm).should == "## My title"
end
it 'returns setext style header' do
@sm = stub(:text => "My title \n======\n Post content...")
post_page_title(@sm).should == "My title \n======"
end
end
context 'without a Markdown header of less than 200 characters on first line 'do
it 'truncates posts to the 20 first characters' do
@sm = stub(:text => "Very, very, very long post")
post_page_title(@sm).should == "Very, very, very ..."
end
end
end
end
end
describe '#post_iframe_url' do
before do
@post = FactoryGirl.create(:status_message)
end
it "returns an iframe tag" do
post_iframe_url(@post.id).should include "iframe"
end
it "returns an iframe containing the post" do
post_iframe_url(@post.id).should include "src='http://localhost:9887#{post_path(@post)}'"
end
end
end