Hi all. Apologies if this is an easy one, but I''ve spent a while
Googling and trying trial-and-error, and can''t find the solution.
I''m trying to spec a controller.
It accepts an HTML array, then processes items matching the id param.
So I''m passing (in meta form)
controller/action/id?thing[thing_id]=value
The controller looks at the id, finds the ActiveRecord object which
matches id, then looks for the thing with a thing_id matching id and
processes it
The real example is a little involved, but a simpler example would be
something like
comments/rate/4?score[4]=10&score[5]=9
so that comment 4 is rated 10, and comment 5 is untouched
In my controller spec I''ve been trying (for the above easy example)
post ''comments/rate'', :id=>4, :score=>{4=>10}
but my params array doesn''t appear to be going through the test
This doesn''t do it:
post ''comments/rate'', :id=>4, :score[4]=>10
Nor this:
post ''comments/rate'', :id=>4,
:score[''4'']=>10
Nor this:
post ''comments/rate'', :id=>4,
"score[4]".to_sym=>10
Any ideas? Have I given enough info? Trying to give relevant details
without too much extraneous info.
Thanks in advance for any help!
Your first attempt is the correct way to go about it
post ''comments/rate'', :id=>4, :score=>{4=>10}
However, note that in your controller, the parameters are stringified /
symbolized.
params["score"]["4"] will get you 10, but
params["score"][4] will get you
nil
On Wed, Dec 2, 2009 at 8:40 AM, itsterry <itsterry at gmail.com> wrote:
> Hi all. Apologies if this is an easy one, but I''ve spent a while
> Googling and trying trial-and-error, and can''t find the solution.
>
> I''m trying to spec a controller.
>
> It accepts an HTML array, then processes items matching the id param.
>
> So I''m passing (in meta form)
>
> controller/action/id?thing[thing_id]=value
>
> The controller looks at the id, finds the ActiveRecord object which
> matches id, then looks for the thing with a thing_id matching id and
> processes it
>
> The real example is a little involved, but a simpler example would be
> something like
>
> comments/rate/4?score[4]=10&score[5]=9
>
> so that comment 4 is rated 10, and comment 5 is untouched
>
> In my controller spec I''ve been trying (for the above easy
example)
>
> post ''comments/rate'', :id=>4, :score=>{4=>10}
>
> but my params array doesn''t appear to be going through the test
>
> This doesn''t do it:
> post ''comments/rate'', :id=>4, :score[4]=>10
>
> Nor this:
> post ''comments/rate'', :id=>4,
:score[''4'']=>10
>
> Nor this:
> post ''comments/rate'', :id=>4,
"score[4]".to_sym=>10
>
> Any ideas? Have I given enough info? Trying to give relevant details
> without too much extraneous info.
>
> Thanks in advance for any help!
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
--
// anything worth taking seriously is worth making fun of
// http://blog.devcaffeine.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20091203/4be8510d/attachment.html>
Aha! That explains it. Thank you ! On Dec 3, 4:35?pm, Chris Flipse <cfli... at gmail.com> wrote:> Your first attempt is the correct way to go about it > ? ?post ''comments/rate'', :id=>4, :score=>{4=>10} > > However, note that in your controller, the parameters are stringified / > symbolized. > params["score"]["4"] ?will get you 10, but params["score"][4] will get you > nil > > > > On Wed, Dec 2, 2009 at 8:40 AM, itsterry <itste... at gmail.com> wrote: > > Hi all. Apologies if this is an easy one, but I''ve spent a while > > Googling and trying trial-and-error, and can''t find the solution. > > > I''m trying to spec a controller. > > > It accepts an HTML array, then processes items matching the id param. > > > So I''m passing (in meta form) > > > controller/action/id?thing[thing_id]=value > > > The controller looks at the id, finds the ActiveRecord object which > > matches id, then looks for the thing with a thing_id matching id and > > processes it > > > The real example is a little involved, but a simpler example would be > > something like > > > comments/rate/4?score[4]=10&score[5]=9 > > > so that comment 4 is rated 10, and comment 5 is untouched > > > In my controller spec I''ve been trying (for the above easy example) > > > post ''comments/rate'', :id=>4, :score=>{4=>10} > > > but my params array doesn''t appear to be going through the test > > > This doesn''t do it: > > post ''comments/rate'', :id=>4, :score[4]=>10 > > > Nor this: > > post ''comments/rate'', :id=>4, :score[''4'']=>10 > > > Nor this: > > post ''comments/rate'', :id=>4, "score[4]".to_sym=>10 > > > Any ideas? Have I given enough info? Trying to give relevant details > > without too much extraneous info. > > > Thanks in advance for any help! > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > // anything worth taking seriously is worth making fun of > //http://blog.devcaffeine.com/ > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users