Refactor page header code
This commit is contained in:
parent
c880ba31b8
commit
b68960efe5
7 changed files with 25 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
- content_for(:title) { link_to @subcreddit.name, @subcreddit }
|
||||
- if @subcreddit.closed?
|
||||
= "Board has been closed"
|
||||
- else
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
h1 #{@user.username}
|
||||
- content_for(:title, link_to(@user.username, @user))
|
||||
|
||||
.comments.contents
|
||||
- @comments.each do |comment|
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue