1
0
Fork 0

Refactor page header code

This commit is contained in:
Andrew Tomaka 2015-08-06 16:31:08 -04:00
parent c880ba31b8
commit b68960efe5
7 changed files with 25 additions and 3 deletions

View File

@ -3,6 +3,10 @@ module ApplicationHelper
bootstrap_classes[flash_type] || flash_type.to_s
end
def page_header
content_for(:title) || ''
end
private
def bootstrap_classes

View File

@ -10,8 +10,7 @@
= link_to 'Creddit', root_path, class: 'navbar-brand'
.collapse.navbar-collapse
ul.nav.navbar-nav
- if @subcreddit && @subcreddit.name
li= link_to @subcreddit.name, @subcreddit
li= page_header
ul.nav.navbar-nav.navbar-right
- if logged_in?
li= link_to 'Sign Out', signout_path

View File

@ -1,3 +1,4 @@
- content_for(:title, link_to(@subcreddit.name, @subcreddit))
== render 'posts/post', post: @post
.alert.alert-info.in-page
p you are viewing a single comment's thread.

View File

@ -1,3 +1,4 @@
- content_for(:title, link_to(@subcreddit.name, @subcreddit))
== render 'post', post: @post
- if @post.comments?
.title= "all #{@post.comments_count} comments"

View File

@ -1,3 +1,4 @@
- content_for(:title) { link_to @subcreddit.name, @subcreddit }
- if @subcreddit.closed?
= "Board has been closed"
- else

View File

@ -1,4 +1,4 @@
h1 #{@user.username}
- content_for(:title, link_to(@user.username, @user))
.comments.contents
- @comments.each do |comment|

View File

@ -26,4 +26,20 @@ describe ApplicationHelper do
end
end
end
describe '#page_header' do
context 'when title is provided' do
it 'should return the set title' do
allow(helper).to receive(:content_for).with(:title).and_return('Test')
expect(helper.page_header).to eq 'Test'
end
end
context 'when title is not provided' do
it 'should return blank' do
expect(helper.page_header).to be_blank
end
end
end
end