Commit f4c463e1 by Tô Ngọc Ánh

Add static pages and full_title helper

parent 0cfd0e17
Pipeline #658 canceled with stages
in 0 seconds
...@@ -35,7 +35,13 @@ group :development, :test do ...@@ -35,7 +35,13 @@ group :development, :test do
gem 'byebug' gem 'byebug'
# Use sqlite3 as the database for Active Record # Use sqlite3 as the database for Active Record
gem 'sqlite3', '1.3.11' gem 'sqlite3', '1.3.11'
gem 'rspec-rails', '2.13.1' gem 'rspec-rails', '2.99'
gem 'test-unit'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end end
group :development do group :development do
......
...@@ -40,6 +40,13 @@ GEM ...@@ -40,6 +40,13 @@ GEM
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.2.4) builder (3.2.4)
byebug (11.1.3) byebug (11.1.3)
capybara (2.1.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (4.0.0)
coffee-rails (4.1.1) coffee-rails (4.1.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x) railties (>= 4.0.0, < 5.1.x)
...@@ -70,12 +77,17 @@ GEM ...@@ -70,12 +77,17 @@ GEM
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.1) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.0512)
mini_mime (1.0.2) mini_mime (1.0.2)
mini_portile2 (2.4.0) mini_portile2 (2.4.0)
minitest (5.14.1) minitest (5.14.1)
multi_json (1.14.1)
nokogiri (1.10.9) nokogiri (1.10.9)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
pg (0.15.1) pg (0.15.1)
power_assert (1.2.0)
rack (1.6.13) rack (1.6.13)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
...@@ -113,17 +125,22 @@ GEM ...@@ -113,17 +125,22 @@ GEM
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
rdoc (4.3.0) rdoc (4.3.0)
rspec-core (2.13.1) rspec-collection_matchers (1.2.0)
rspec-expectations (2.13.0) rspec-expectations (>= 2.99.0.beta1)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1) rspec-mocks (2.99.4)
rspec-rails (2.13.1) rspec-rails (2.99.0)
actionpack (>= 3.0) actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
rspec-core (~> 2.13.0) rspec-collection_matchers
rspec-expectations (~> 2.13.0) rspec-core (~> 2.99.0)
rspec-mocks (~> 2.13.0) rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rubyzip (0.9.9)
sass (3.7.4) sass (3.7.4)
sass-listen (~> 4.0.0) sass-listen (~> 4.0.0)
sass-listen (4.0.0) sass-listen (4.0.0)
...@@ -138,6 +155,11 @@ GEM ...@@ -138,6 +155,11 @@ GEM
sdoc (0.4.2) sdoc (0.4.2)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0) rdoc (~> 4.0)
selenium-webdriver (2.35.1)
childprocess (>= 0.2.5)
multi_json (~> 1.0)
rubyzip (< 1.0.0)
websocket (~> 1.0.4)
spring (2.1.0) spring (2.1.0)
sprockets (3.7.2) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
...@@ -147,6 +169,8 @@ GEM ...@@ -147,6 +169,8 @@ GEM
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.11) sqlite3 (1.3.11)
test-unit (3.3.6)
power_assert
thor (1.0.1) thor (1.0.1)
thread_safe (0.3.6) thread_safe (0.3.6)
tilt (2.0.10) tilt (2.0.10)
...@@ -162,23 +186,29 @@ GEM ...@@ -162,23 +186,29 @@ GEM
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (>= 4.0) railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
websocket (1.0.7)
xpath (2.1.0)
nokogiri (~> 1.3)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
byebug byebug
capybara (= 2.1.0)
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
pg (= 0.15.1) pg (= 0.15.1)
rails (= 4.2.11) rails (= 4.2.11)
rails_12factor (= 0.0.2) rails_12factor (= 0.0.2)
rspec-rails (= 2.13.1) rspec-rails (= 2.99)
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
selenium-webdriver (= 2.35.1)
spring spring
sqlite3 (= 1.3.11) sqlite3 (= 1.3.11)
test-unit
turbolinks turbolinks
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (~> 2.0) web-console (~> 2.0)
......
...@@ -4,4 +4,7 @@ class StaticPagesController < ApplicationController ...@@ -4,4 +4,7 @@ class StaticPagesController < ApplicationController
def help def help
end end
def about
end
end end
module ApplicationHelper 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 end
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><%= full_title(yield(:title)) %></title>
<title>SampleApp</title> <title>SampleApp</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body>
<%= yield %>
</body> <body>
<%= yield %>
</body>
</html> </html>
\ No newline at end of file
<% provide(:title, 'About Us') %>
<h1>About Us</h1>
<p>
The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
is a project to make a book and screencasts to teach web development
with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This
is the sample application for the tutorial.
</p>
\ No newline at end of file
<h1>StaticPages#help</h1> <% provide(:title, 'Help') %>
<p>Find me in app/views/static_pages/help.html.erb</p> <h1>Help</h1>
<p>
Get help on the Ruby on Rails Tutorial at the
<a href="http://railstutorial.org/help">Rails Tutorial help page</a>.
To get help on this sample app, see the
<a href="http://railstutorial.org/book">Rails Tutorial book</a>.
</p>
\ No newline at end of file
<h1>StaticPages#home</h1> <h1>Sample App</h1>
<p>Find me in app/views/static_pages/home.html.erb</p> <p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
\ No newline at end of file
Rails.application.routes.draw do Rails.application.routes.draw do
root to: 'static_pages#home'
get 'static_pages/home' get 'static_pages/home'
get 'static_pages/help' get 'static_pages/help'
get 'static_pages/about'
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
......
require 'spec_helper'
describe "StaticPages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the right title" do
visit '/static_pages/home'
expect(page).to have_title("#{base_title}")
end
it "should not have a custom page title" do
visit '/static_pages/home'
expect(page).not_to have_title('| Home')
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
expect(page).to have_title("#{base_title} | Help")
end
end
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
visit '/static_pages/about'
expect(page).to have_title("#{base_title} | About Us")
end
end
end
...@@ -2,15 +2,19 @@ ...@@ -2,15 +2,19 @@
ENV["RAILS_ENV"] ||= 'test' ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__) require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails' require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc, # Requires supporting ruby files with custom matchers and macros, etc, in
# in spec/support/ and its subdirectories. # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run. # Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line. # If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config| RSpec.configure do |config|
# ## Mock Framework # ## Mock Framework
...@@ -20,7 +24,7 @@ RSpec.configure do |config| ...@@ -20,7 +24,7 @@ RSpec.configure do |config|
# config.mock_with :mocha # config.mock_with :mocha
# config.mock_with :flexmock # config.mock_with :flexmock
# config.mock_with :rr # config.mock_with :rr
config.include Capybara::DSL
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures" config.fixture_path = "#{::Rails.root}/spec/fixtures"
...@@ -39,4 +43,19 @@ RSpec.configure do |config| ...@@ -39,4 +43,19 @@ RSpec.configure do |config|
# the seed, which is printed after each run. # the seed, which is printed after each run.
# --seed 1234 # --seed 1234
config.order = "random" config.order = "random"
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explictly tag your specs with their type, e.g.:
#
# describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/v/3-0/docs
config.infer_spec_type_from_file_location!
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment