transloadit/rails-sdk — pull request #22 by jstirk (2012-06-11 03:36:05+00:00)
Title: RSpec request spec helpers to stub the params[:transloadit] data

Hi!

I'm currently using transloadit in a Rails + rspec project, and I need to test the Ruby-side of the upload process in a request spec. Obviously I don't want my specs to be dependent on the network, so I wanted to stub out the data that would normally be populated by the JS library.

However, because of how the `Transloadit::Rails::ParamsDecoder` code is structured, it is very difficult to stub.

This PR includes a refactor to `Transloadit::Rails::ParamsDecoder` to make it easier to stub, and a request spec helper to make it trivial for my request spec use case. I've structured it so it shouldn't require RSpec to be used, but I haven't tested this case.

This refactor also starts to provide a pathway to deprecate the `params[:transloadit]` value, which seems to me to be a bit of a hack to expose to data to the actions.

I would have liked to put some test cases around all this code, but it looks like the test suite is a bit light on at the moment :) If I get a chance I'll start setting some up.

TIA.