Browse files

Add a title helper

  • Loading branch information...
1 parent f1a3927 commit 0788f0d787b80de48369a5b4128e3e74f6a59547 @dgussin committed Apr 24, 2012
Showing with 17 additions and 3 deletions.
  1. +10 −0 app/helpers/application_helper.rb
  2. +0 −1 app/views/static_pages/home.html.erb
  3. +7 −2 spec/requests/static_pages_spec.rb
View
10 app/helpers/application_helper.rb
@@ -1,2 +1,12 @@
module ApplicationHelper
+
+ # returns the full title on a per-page basis
+ def full_title(page_title)
+ base_title = "Ruby on Rails Tutorial Sample App"
+ if page_title.empty?
+ base_title
+ else
+ "#{base_title} | #{page_title}"
+ end
+ end
end
View
1 app/views/static_pages/home.html.erb
@@ -1,4 +1,3 @@
-<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
View
9 spec/requests/static_pages_spec.rb
@@ -10,11 +10,16 @@
page.should have_selector('h1', :text => 'Sample App')
end
- it "should have the title 'Home'" do
+ it "should have the base title" do
visit '/static_pages/home'
page.should have_selector('title',
- :text => "#{base_title} | Home")
+ :text => "#{base_title}")
end
+
+ it "should not have a custom page title" do
+ visit "/static_pages/home"
+ page.should_not have_selector('title', :text => '| Home')
+ end
end
describe "Help page" do

0 comments on commit 0788f0d

Please sign in to comment.