Skip to content

Commit

Permalink
finished chapter 3 exerises
Browse files Browse the repository at this point in the history
  • Loading branch information
thirotan committed Nov 9, 2015
1 parent b8b124b commit ce20c7c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -2,9 +2,9 @@ source 'https://rubygems.org'


gem 'rails', '4.2.4'
gem 'pg'

group :development, :test do
gem 'sqlite3'
gem 'rspec-rails'
end

Expand All @@ -26,7 +26,6 @@ gem 'sdoc', '~> 0.4.0', group: :doc


group :production do
gem 'pg'
gem 'rails_12factor'
end

2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -155,7 +155,6 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.11)
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
Expand Down Expand Up @@ -188,7 +187,6 @@ DEPENDENCIES
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
selenium-webdriver
sqlite3
therubyracer
turbolinks
uglifier (>= 1.3.0)
Expand Down
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -41,4 +41,16 @@ http://qiita.com/hirolog/items/eefda94756f547ea08f2

spec/spec_helper.rbじゃなくて、 spec/rails_helper.rbに config.include Capybara::DSL を追記する。


== 3章: 演習
3.5.3
posgresql-server postgresql postgresql-libs 辺りを yum で入れる

# su - postgres
-bash-4.1$ createuser dev
Shall the new role be a superuser? (y/n) y
-bash-4.1$ logout

と、 postgresユーザになって、 devという(開発で使ってるユーザと同じ名前の)ユーザを作成し、
rake db:create
rake db:migrate
する
3 changes: 3 additions & 0 deletions app/controllers/static_pages_controller.rb
Expand Up @@ -7,4 +7,7 @@ def help

def about
end

def contact
end
end
6 changes: 6 additions & 0 deletions app/views/static_pages/contact.html.erb
@@ -0,0 +1,6 @@
<% provide(:title, 'Contact') %>
<h1>Contact</h1>
<p>
Contact Ruby on Rails Tutorial about the sample app at the
<a href="http://railstutorial.jp/contact">contact page</a>.
</p>
42 changes: 33 additions & 9 deletions config/database.yml
Expand Up @@ -10,16 +10,40 @@ default: &default
timeout: 5000

development:
<<: *default
database: db/development.sqlite3
adapter: postgresql
encoding: unicode
database: SampleApp_development
pool: 5
username: dev
password:

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
adapter: postgresql
encoding: unicode
database: SampleApp_test
pool: 5
username: dev
password:

production:
<<: *default
database: db/production.sqlite3
adapter: postgresql
encoding: unicode
database: SampleApp_production
pool: 5
username: dev
password:

#development:
# <<: *default
# database: db/development.sqlite3
#
## Warning: The database defined as "test" will be erased and
## re-generated from your development database when you run "rake".
## Do not set this db to the same as development or production.
#test:
# <<: *default
# database: db/test.sqlite3
#
#production:
# <<: *default
# database: db/production.sqlite3
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -2,6 +2,7 @@
get 'static_pages/home'
get 'static_pages/help'
get 'static_pages/about'
get 'static_pages/contact'

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down
21 changes: 18 additions & 3 deletions spec/requests/static_pages_spec.rb
@@ -1,6 +1,9 @@
require 'rails_helper'

RSpec.describe "StaticPages", type: :request 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'
Expand All @@ -9,7 +12,7 @@

it "should have the title 'Home'" do
visit '/static_pages/home'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
expect(page).to have_title("#{base_title} | Home")
end
end

Expand All @@ -21,7 +24,7 @@

it "should have the title 'Help'" do
visit '/static_pages/help'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
expect(page).to have_title("#{base_title} | Help")
end
end

Expand All @@ -33,7 +36,19 @@

it "should have the title 'About Us'" do
visit '/static_pages/about'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
expect(page).to have_title("#{base_title} | About Us")
end
end

describe "Contact" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
end

it "should have the title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("#{base_title} | Contact")
end
end
end

0 comments on commit ce20c7c

Please sign in to comment.