title: RSpec + FactoryGirl and controller specs
body: <p>I'm trying to add FactoryGirl support the default scaffolded specs in my controllers and I can't seem to find the correct syntax.</p>
  
  <p>Here's an example test:</p>
  
  <pre><code>describe "POST create" do
      describe "with valid params" do
     it "creates a new Course" do
          expect {
            post :create, {:course =&gt; valid_attributes}, valid_session
          }.to change(Course, :count).by(1)
        end
  do
  </code></pre>
  
  <p>Which I replace by:</p>
  
  <pre><code>describe "POST create" do
      describe "with valid params" do
        it "creates a new Course" do
          expect {
            post :create, course: FactoryGirl.build(:course)
          }.to change(Course, :count).by(1)
        end
  do
  </code></pre>
  
  <p>spec/factories/courses.rb</p>
  
  <pre><code>FactoryGirl.define do
    factory :course do
      association :provider
      name "Course name"
      description "course description"
    end
  end
  </code></pre>
  
  <p>app/models/course.rb</p>
  
  <pre><code>class Course &lt; ActiveRecord::Base
    validates :name, :presence =&gt; true
    validates :description, :presence =&gt; true
    validates :provider_id, :presence =&gt; true
    has_many :terms
    belongs_to :provider
  end
  </code></pre>
  
  <p>app/controllers/courses_controller.rb</p>
  
  <pre><code>  # POST /courses
    # POST /courses.json
  
    def create
      @course = Course.new(course_params)
  
      respond_to do |format|
        if @course.save
          format.html { redirect_to @course, notice: 'Course was successfully created.' }
          format.json { render action: 'show', status: :created, location: @course }
        else
          format.html { render action: 'new' }
          format.json { render json: @course.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>It usually fails with: "ActionController::ParameterMissing: param not found: course" does anyone have any idea?</p>
  
  <p>Thanks!
  Francis</p>