Help us understand the problem. What is going on with this article?

"Railsのユーザ認証deviseを用いた簡単かつ突っ込んだ実装"を試してみる

More than 5 years have passed since last update.

こちらの記事「Railsのユーザ認証deviseを用いた簡単かつ突っ込んだ実装」をRails4で試している。
こちらの記事を書いたema25さんに感謝。
一部コードの編集が必要だったので備忘としてメモ。

修正点

  • factories.rbの変更
  • spec/factories/items.rbの削除
  • spec/controllers/welcome_controller_spec.rbの変更

factories.rbの変更

factory_girlの記載方法が変わっているので下記のように変更。

spec/factories.rb
require 'factory_girl'

FactoryGirl.define do
  factory :user, class: User do
    id 2
    name "Test User"
    email "user@test.com"
    password "foobar"
    password_confirmation "foobar"
  end

  factory :item, class: Item do
    name "Test Item"
    user_id 2
  end
end

spec/factories/items.rbの削除

上記を修正し、rake db:migrate RAILS_ENV=testを実行すると、"Factory already registered: item"というエラーとなる。

rake aborted!
Factory already registered: item

これはテスト用データが重複している、というメッセージ。
itemのデータについては、上記factories.rbで記載しているので、spec/factories/items.rbを削除。

spec/controllers/welcome_controller_spec.rbの変更

こちらもfactory_girlの記載方法が変わっているので下記のように変更。

spec/controllers/welcome_controller_spec.rb
require 'spec_helper'

describe WelcomeController do
  before (:each) do
    user = FactoryGirl.create(:user)
    sign_in user
  end

  describe "GET 'index'" do
    it "should be successful" do
      get 'index'
      response.should be_success
      assigns[:signin].should == "ok"
      # pp response
    end

    it "all items finded" do
      FactoryGirl.create(:item)
      get 'index'
      response.should be_success
      assigns[:items].count.should == 1
      assigns[:items].first.name.should == "Test Item"
    end
  end
end
fnta
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした