0
0

More than 3 years have passed since last update.

Railsチュートリアル3章

Posted at

3.2.1 演習

1. Fooというコントローラを生成し、その中にbarとbazアクションを追加してみてください。
$ rails g controller Foo bar baz


2. コラム 3.1で紹介したテクニックを駆使して、Fooコントローラとそれに関連するアクションを削除してみてください。
$ rails destroy controller Foo bar baz


3.4.3 演習

1. サンプルアプリケーションにContact (問い合わせ先) ページを作成してください。

下記コードを追記しました。テストも問題なくクリアしています。

static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest

(中略)

  test "should get contact" do
    get static_pages_contact_url
    assert_response :success
    assert_select "title", "Contact | #{@base_title}"
  end
end
static_pages_controller.rb
class StaticPagesController < ApplicationController

(中略)

  def contact
  end
end
contact.html.erb
<% provide(:title, "Contact") %>
<h1>Contact</h1>
<p>
  Contact the Ruby on Rails Tutorial about the sample app at the
  <a href="https://railstutorial.jp/contact">contact page</a>.
</p>
routes.rb
Rails.application.routes.draw do
  get  'static_pages/home'
  get  'static_pages/help'
  get  'static_pages/about'
  get 'static_pages/contact' #この行を追記
end

3.4.4 演習

1. 〜FILL_INと記された部分を置き換えて、rootルーティングのテストを書いてみてください。
static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest

  def setup
    @base_title = "Ruby on Rails Tutorial Sample App"
  end

  test "should get root" do
    get root_url
    assert_response :success
  end

(中略)

end
2. 〜rootルーティングをコメントアウトして見て、 red になるかどうか確かめてみましょう〜(中略)〜テストが green になることを確認してみましょう。

無事確認できた。

今回調べた単語たち

プレースホルダ

【 placeholder 】
実際の内容を後から挿入するために、とりあえず仮に確保した場所のこと。また、そのことを示す標識などのこと。

テストスイート

【Test Suite】
ソフトウェアテストの目的や対象ごとに複数のテストケースをまとめたもの。

テスト駆動開発

【test-driven development; TDD】
プログラム開発手法の一種で、プログラムに必要な各機能について、最初にテストを書き(これをテストファーストと言う)、そのテストが動作する必要最低限な実装をとりあえず行った後、コードを洗練させる、という短い工程を繰り返すスタイル。

REFACTOR

リファクタリング (refactoring)
プログラムの動きを変えないまま、ソースコード(人間語で書いたプログラムの元ネタ)を書き換えること。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0