1

我有控制器 - 调查、问题和选​​项。如果不先创建问题,我将无法保存调查。反过来,不能先创建选项来创建问题。如何为调查控制器获得“创建”规范通过... 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
4

0 回答 0