色々手を入れてみるなど

とりあえず rspec が動かない。Gemfile に rspec な記述が無かったので追記して bundle install してみます。その後、以下を実行で良いのかな。

$ rails g rspec:install

ええと、config.active_support.deprecation が云々とか言われてます。曰く、以下。

You did not specify how you would like Rails to report deprecation notices for your development environment, please set config.active_support.deprecation to :log at config/environments/development.rb

とりあえず spec/spec_helper.rb は自動生成されました。devise が自動で出力した pending な試験も実行はできるはず。できました。

ログインユーザなソレは current_user でアレなのか。つうかこれ、scaffold 削除したくなってきたのですが、どうしたものか。
index アクションについては

  def index
    @conns = current_user.conns

    respond_to do |format|
      format.html
      format.json { render json: @conns }
    end
  end

で良いと思うのですが

  • show
  • new
  • edit
  • create
  • update
  • destroy

全部手を入れないとアレだな。とりあえず舞波さん本 (これ、対象バージョンいくつなんだろ) を見つつ実装をでっちあげて試験を作れるのかどうか。
とりあえず、以下を盛り込んでみました。試験を作るのか。

class ConnsController < ApplicationController
  before_filter :authenticate_user!
  # GET /conns
  # GET /conns.json
  def index
#    @conns = Conn.all
    @conns = current_user.conns

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @conns }
    end
  end

  # GET /conns/1
  # GET /conns/1.json
  def show
#    @conn = Conn.find(params[:id])
    @conn = current_user.conns.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @conn }
    end
  end

  # GET /conns/new
  # GET /conns/new.json
  def new
#    @conn = Conn.new
    @conn = current_user.conns.build

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @conn }
    end
  end

  # GET /conns/1/edit
  def edit
#    @conn = Conn.find(params[:id])
    @connd = current_user.conns.find(:id)
  end

  # POST /conns
  # POST /conns.json
  def create
#    @conn = Conn.new(params[:conn])
    @conn = current_user.conns.build(params[:conn])

    respond_to do |format|
      if @conn.save
        format.html { redirect_to @conn, notice: 'Conn was successfully created.' }
        format.json { render json: @conn, status: :created, location: @conn }
      else
        format.html { render action: "new" }
        format.json { render json: @conn.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /conns/1
  # PUT /conns/1.json
  def update
#    @conn = Conn.find(params[:id])
    @conn = current_user.conns.find(params[:id])

    respond_to do |format|
      if @conn.update_attributes(params[:conn])
        format.html { redirect_to @conn, notice: 'Conn was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @conn.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /conns/1
  # DELETE /conns/1.json
  def destroy
#    @conn = Conn.find(params[:id])
    @conn = current_user.conns.find(params[:id])
    @conn.destroy

    respond_to do |format|
      format.html { redirect_to conns_url }
      format.json { head :no_content }
    end
  end
end

ええと、データ作らないと試験がアレですね。
この段階で scaffold な spec 作る方法ってどうするんだろ。とりあえずメイルの返信をせねば、な用件を思いだしたのでここで中断します。

と言いつつ

以下なのかな。

$ rails g rspec:controller ConnsController

で良いのかな。とりあえずやるだけやっとく。

$ rails g rspec:controller ConnsCOntroller
      create spec/controllers/cons_controller_controller_spec.rb

む。違うな。

$ rm -rf spec/controllers
$ rails g rspec:controler Conns
      create spec/controllers/cons_controller_spec.rb

とりあえず中身は空です。明日以降で対応の方向。