[rspec-users] Testing arbitrary post action parameters

Pat Maddox pergesu at gmail.com
Sat Jan 17 19:22:26 EST 2009

On Sat, Jan 17, 2009 at 3:34 PM, James Byrne <lists at ruby-forum.com> wrote:
> James Byrne wrote:
>> I have spent a good deal of time trying to get this to work with no
>> success.  I have read the api regarding the put method in:
>>  ActionController::Integration::Session
>> If I read this aright then in your example user should be a hash, but a
>> hash of what? Where would I create it in my test and what should it
>> contain?
> I ended up with this:
>  :user => User.find(:first)
> When /user named "(.*)" enables the administrator role/ do |name|
>  put users_url( :user => User.find_by_username!(name) ), :user =>
> {:administrator => true}
> end
> Which at least does not blow up on me.  But it does not set the
> administrator flag to true either.

Okay well it's been a little frustrating watching this thread, after
I've made suggestions and I don't think you've tried them.  So, I
decided to verify this myself and I made a little demo app to see if
it works...

put user_url(@user), :user => {:admin => true}

does in fact work.  So, yeah.  Last post I'm making in this thread.

Also, to easily get the behavior you want, you can do

class User < ActiveRecord::Base
  attr_protected :admin

which will ignore the admin key when bulk-updating attributes (such as
using update_attributes).


More information about the rspec-users mailing list