Rails测试:使用死锁控制器失败“创建”规范

时间:2013-06-06 03:57:08

标签: ruby-on-rails controller rspec-rails

我有控制器 - 调查,问题和选项。 我不能先保存调查而不先创建问题。反过来,无法创建问题,首先创建选项。如何获得"创造"规范通过调查控制器...... Surveys_Controller_spec.rb

describe "POST 'create'" do
before(:each) do
  @user = FactoryGirl.create(:activated_user)
  login_user(@user)
end

context "with valid parameters" do      
  let(:parameters) { { :title => "Title of the Survey", :description => "description", :activated      => "false", :participant_info => "0", :is_draft => "true",  :thank_you_message => "Thank You", :user_id => @user.id } }

  it "creates a new survey" do
    expect { post :create, :survey => parameters }.to change(Survey, :count).by(1)
  end

Surveys_Controller.rb

def create
  @survey = convert_enums(current_user.surveys.new(params[:survey]), params)
  respond_to do |format|
  if @survey.save
    format.html { redirect_to dashboard_path, :notice => "Survey was successfully created!"}
  else
    format.html { render :new }
  end
 end

0 个答案:

没有答案