Adam Wiggins
2008-Apr-26 03:34 UTC
[rspec-users] restful controllers with different content types
Simplified example of a controller which takes a POST with a non-xml and non-form-urlencoded content type: class PhotosController < ApplicationController def create Photo.create :binary_data => request.body.read, :content_type => ''image/jpg'' head :ok end end How can I spec this? The way that I''d like to do it would be something like: it "creates a new photo from a posted image file" do Photo.should_receive(:create).with(:binary_data => ''the data'', :content_type => ''image/jpg'') post :create, :body => ''the data'' end Adam
David Chelimsky
2008-Apr-26 08:33 UTC
[rspec-users] restful controllers with different content types
On Apr 25, 2008, at 11:34 PM, "Adam Wiggins" <adam at heroku.com> wrote:> Simplified example of a controller which takes a POST with a non-xml > and non-form-urlencoded content type: > > class PhotosController < ApplicationController > def create > Photo.create :binary_data => request.body.read, :content_type => > ''image/jpg'' > head :ok > end > end > > How can I spec this? The way that I''d like to do it would be > something like: > > it "creates a new photo from a posted image file" do > Photo.should_receive(:create).with(:binary_data => ''the data'', > :content_type => ''image/jpg'') > post :create, :body => ''the data'' > endWhat happens when you try this?
Adam Wiggins
2008-Apr-26 22:35 UTC
[rspec-users] restful controllers with different content types
On Sat, Apr 26, 2008 at 1:33 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Apr 25, 2008, at 11:34 PM, "Adam Wiggins" <adam at heroku.com> wrote: > > it "creates a new photo from a posted image file" do > > Photo.should_receive(:create).with(:binary_data => ''the data'', > > :content_type => ''image/jpg'') > > post :create, :body => ''the data'' > > end > > What happens when you try this?It treats :body as a regular urlencoded parameter. i.e., the body of the POST sent through to the controller is "body=the+data", when I want it to be "the data". There''s the matter of content-type too; I left that out in hopes if simplifying the question. The more complete version might be: post :create, :content_type => ''image/jpg'', :body => ''the data'' But :content_type and :body are not treated as special parameters, so I was wondering if there is some other mechanism for doing this. Adam