From eed6374355a6f071ff9faf81af8d3ba32fe69ef2 Mon Sep 17 00:00:00 2001 From: Simone Date: Thu, 6 Dec 2012 13:09:29 +0100 Subject: [PATCH] Modify spec --- app/helpers/application_helper.rb | 10 ++++++++++ app/views/layouts/application.html.erb | 2 +- app/views/static_pages/home.html.erb | 1 - config/routes.rb | 2 +- spec/requests/static_pages_spec.rb | 6 +++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..e1c3516 100644 --- a/app/helpers/application_helper.rb +++ b/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 + "#{page_title} | #{base_title}" + end + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f55fb96..6467bdb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,7 +2,7 @@ - <%= yield(:title) %> | Ruby on Rails Tutorial Sample App + <%= full_title yield(:title) %> <%= stylesheet_link_tag "application", media: "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index 01bfa68..d2f81bf 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -1,3 +1,2 @@ -<% provide(:title, 'Home') %>

Home

Welcome.

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2ecf51d..50696f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,7 +52,7 @@ # You can have the root of your site routed with "root" # just remember to delete public/index.html. - # root :to => 'welcome#index' + root :to => 'static_pages#home' # See how all your routes lay out with "rake routes" diff --git a/spec/requests/static_pages_spec.rb b/spec/requests/static_pages_spec.rb index cdd7900..97d08af 100644 --- a/spec/requests/static_pages_spec.rb +++ b/spec/requests/static_pages_spec.rb @@ -11,8 +11,12 @@ end it "should have the right title" do visit '/static_pages/home' - page.should have_selector('title', text: "Home | #{base_title}") + page.should have_selector('title', 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 it "should have the content 'Help'" do