title: Rails 'post' command in rspec controllers: Files aren't passing through. (Is there a multipart setting?)
body: <p>I'm trying to run the following spec</p>
  
  <pre><code>describe "POST create" do
    describe "with valid params" do
      it "redirects to the created banner" do
        post :create, :banner =&gt; valid_attributes
        response.should redirect_to(admin_banner_url(Banner.last))
      end
    end
  end
  
  
  def valid_attributes
    demo_image = File.open(File.join(Rails.root, "spec", "samples", "laptop1.jpg"))
    {
      :name =&gt; 'Test Spec Banner',
      :bannerimage =&gt; demo_image
    }
  end
  </code></pre>
  
  <p>The create is failing validation on validates_presence_of :bannerimage - I've narrowed it down as follows:</p>
  
  <ul>
  <li>If I take the validates_presence_of validation off of bannerimage, it works, but the banner is reported as 'missing.png'</li>
  <li>Banner.create!(valid_attributes) works</li>
  <li>I've shown only one spec above, but the problem occurs on any spec which involves that post :create, :banner => valid_attributes line</li>
  <li>I've taken out every reference to attr_accessible...no difference</li>
  <li>I've tried switching validate_attributes into Factory.attributes_for(:banner), with the same file info in :bannerimage</li>
  <li>Form works just fine through the browser, including image upload/processing</li>
  <li>File.exists? confirms the referenced file is indeed there.</li>
  </ul>
  
  <p>If anyone has any ideas on why post is failing, I'd be very appreciative. I'm guessing (and pardon - I haven't looked into the inner workings of the 'post' command and may be off here) that it's missing some sort of 'multipart' parameter on that call to accept files(?) ...couldn't find anything through google.</p>
  
  <p>Any ideas appreciated - I'm completely stumped.</p>
  
  <p>The controller is a completely unmodified Rails 3.1 scaffold resource. Model below.</p>
  
  <pre><code>class Banner &lt; ActiveRecord::Base
    # attr_accessible :name, :url, :bannerimage
  
    has_attached_file :bannerimage, :styles =&gt; { :full =&gt; "960x", :thumb =&gt; "100x" }
  
    validates_attachment_content_type :bannerimage, :content_type =&gt; [ 'image/jpg', 'image/jpeg', 'image/gif', 'image/png'], :message =&gt; 'file must be a gif, jpeg or png image'
  
    validates_attachment_size :bannerimage, :less_than =&gt; 3.megabytes
  
    validates_presence_of :name
    validates_attachment_presence :bannerimage
    validates_uniqueness_of :name
  
    has_many :pages, :dependent =&gt; :nullify
  
    def to_s
      name
    end
  end
  </code></pre>