2012-07-17 3 views
19

죄송하지만,이 오류에 대해 많은 질문이 있습니다. 처음이 PG :: 오류 : 오류 : 관계 "사용자"가 존재하지 않습니다.

이 내 UserController

class UserController < ApplicationController 
    def create 
    @users = User.new 
    if @users.save 
     flash[:notice] = 'new user was successfully created.' 
    else 
     render :action => :new 
    end 
    end 

    def new 
    @user = User.new 
    end 
end 

내 routes.rb (내가 문제가 여기에있다 생각입니다

describe UserController do 

it "create new user" do 
    post "create" 
    assigns[:users].should_not be_new_record 
end 
end 

'스펙/spec_helper'을 필요로 내 user_controller의 RSpec에 파일

이다, 변명 나하지만이 언어로 새로운 것)

Estaciones::Application.routes.draw do 
    devise_for :users 

    root :to => "home#index" 
    resources :user 
end 

내 테스트하려고 할 때

내가 그것을 고칠 수있는 방법
1) UserController create new user 
    Failure/Error: post "create" 
    ActiveRecord::StatementInvalid: 
    PG::Error: ERROR: relation "users" does not exist 
    LINE 4:    WHERE a.attrelid = '"users"'::regclass 
              ^
    :    SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull 
        FROM pg_attribute a LEFT JOIN pg_attrdef d 
        ON a.attrelid = d.adrelid AND a.attnum = d.adnum 
        WHERE a.attrelid = '"users"'::regclass 
        AND a.attnum > 0 AND NOT a.attisdropped 
        ORDER BY a.attnum 
# ./app/controllers/user_controller.rb:3:in `new' 
# ./app/controllers/user_controller.rb:3:in `create' 
# ./spec/controllers/user_controller_spec.rb:6 

Finished in 0.01722 seconds 
1 example, 1 failure 

Failed examples: 

rspec ./spec/controllers/user_controller_spec.rb:5 # UserController create new user 

... 감사

+0

아래에 정답이 있습니다. 당신은 그것을 받아 들여야한다 – panzhuli

답변

45

실행이

rake db:migrate 

다음이

rake db:test:prepare 
+0

나는 부엉 rspec 일하는거야 상관 없어 ?? – Asantoya

+0

예 rspec에 대해이 작업을 수행해야합니다 – drhenner

+1

질문을 실제 코드처럼 편집했습니다 ... 다음 번에 코드 앞에 4 칸을 추가하십시오. 게시물 : : ActionView :: MissingTemplate를 만들 : 당신이 promopt 지금 내게 준 thah – drhenner

3

: user_controller_rspec는이 오류를

실패를 얻을 수 얼터너티브 형 nt

RAILS_ENV=test rake db:migrate

관련 문제