[webrat] Getting A String Instead Of An Array

7 views
Skip to first unread message

Frank

unread,
May 4, 2010, 2:22:29 PM5/4/10
to webrat
Hi Guys,

I'm new to webrat and I've encountered a problem. I have a nested form
that I've created using the steps similar to the Rails Casts
http://railscasts.com/episodes/75-complex-forms-part-3

As context, I have a form for programming exercises with a title and
description. The form also has fields for the associated Hint object,
just a regular text area field for the hint text.

When I submit a form using webrat and cucumber my application receives
'params' with:

"new_hint_attributes"=>"[{\"text\"=>\"This is hint 1\"}]"

The key 'new_hint_attributes' maps to a string causing the application
to crash during a cucumber test.

But when I submit the form using the browser my application receives
'params' with:

"new_hint_attributes"=>[{"text"=>"This is hint 1"}]

The key 'new_hint_attributes' maps to an array and everything works
fine.

I was wondering what I might be doing wrong.

Also, I was wondering if this ticket my be related:
https://webrat.lighthouseapp.com/projects/10503/tickets/259-webratmechanize-treats-array-as-string

--
You received this message because you are subscribed to the Google Groups "webrat" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to webrat+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webrat?hl=en.

Damian Janowski

unread,
May 6, 2010, 9:29:52 PM5/6/10
to web...@googlegroups.com
On Tue, May 4, 2010 at 3:22 PM, Frank <francis...@gmail.com> wrote:
> Hi Guys,
>
> I'm new to webrat and I've encountered a problem. I have a nested form
> that I've created using the steps similar to the Rails Casts
> http://railscasts.com/episodes/75-complex-forms-part-3
>
> As context, I have a form for programming exercises with a title and
> description. The form also has fields for the associated Hint object,
> just a regular text area field for the hint text.
>
> When I submit a form using webrat and cucumber my application receives
> 'params' with:
>
>     "new_hint_attributes"=>"[{\"text\"=>\"This is hint 1\"}]"
>
> The key 'new_hint_attributes' maps to a string causing the application
> to crash during a cucumber test.
>
> But when I submit the form using the browser my application receives
> 'params' with:
>
>     "new_hint_attributes"=>[{"text"=>"This is hint 1"}]
>
> The key 'new_hint_attributes' maps to an array and everything works
> fine.
>
> I was wondering what I might be doing wrong.
>
> Also, I was wondering if this ticket my be related:
> https://webrat.lighthouseapp.com/projects/10503/tickets/259-webratmechanize-treats-array-as-string

Maybe you can create a gist with the relevant parts of your app and
tests so that we can reproduce it?

Frank

unread,
May 7, 2010, 2:22:08 AM5/7/10
to webrat
Right, excuse me.

Here are the relevant code snippets

http://gist.github.com/393116

Here is the entire html generated by the template

http://gist.github.com/393134

Notice that all the array params are strings instead of arrays in
'params' but all the hashed stay hashes.



On May 6, 7:29 pm, Damian Janowski <damian.janow...@gmail.com> wrote:
> On Tue, May 4, 2010 at 3:22 PM, Frank <francisco.li...@gmail.com> wrote:
> > Hi Guys,
>
> > I'm new to webrat and I've encountered a problem. I have a nested form
> > that I've created using the steps similar to the Rails Casts
> >http://railscasts.com/episodes/75-complex-forms-part-3
>
> > As context, I have a form for programming exercises with a title and
> > description. The form also has fields for the associated Hint object,
> > just a regular text area field for the hint text.
>
> > When I submit a form using webrat and cucumber my application receives
> > 'params' with:
>
> >     "new_hint_attributes"=>"[{\"text\"=>\"This is hint 1\"}]"
>
> > The key 'new_hint_attributes' maps to a string causing the application
> > to crash during a cucumber test.
>
> > But when I submit the form using the browser my application receives
> > 'params' with:
>
> >     "new_hint_attributes"=>[{"text"=>"This is hint 1"}]
>
> > The key 'new_hint_attributes' maps to an array and everything works
> > fine.
>
> > I was wondering what I might be doing wrong.
>
> > Also, I was wondering if this ticket my be related:
> >https://webrat.lighthouseapp.com/projects/10503/tickets/259-webratmec...

Frank

unread,
May 10, 2010, 5:45:52 PM5/10/10
to webrat
I've made some slight progress towards solving this. I switched from
Ruby 1.9.1 to ruby 1.8.7 and it solved the issue for several nested
file fields.
However, now I'm struggling with nested 'file_field'(s). I'm using
webrat 0.7.1, cucumber 0.7.2, rails 2.3.5 and ruby 1.8.7-p249

It is the same kind of error. I'm expecting an array of file fields in
'params'

'key'=>["#<ActionController::TestUploadedFile:0x267bec8>"]

but instead I get one string that looks like:

key=>"#<ActionController::TestUploadedFile:0x267bec8>"

I tried writing a few webrat specs to try and reproduce the problem
but I haven't had any luck. I was wondering if anyone is familiar with
what can cause "Expecting array but getting string" type errors.

I'm experiencing something similar to this closed ticket:
https://webrat.lighthouseapp.com/projects/10503/tickets/341-attach_file-with-nested-attributes

And this past post:
http://groups.google.com/group/webrat/browse_thread/thread/a08a1cf4e870de26

Frank

unread,
May 11, 2010, 6:07:58 PM5/11/10
to webrat
Hi Guys,

I've been trying to figure this out for a few days now. To better
describe what I'm experiencing
I've created a very simple github rails project at http://github.com/flsafe/test

Check out the README on the github project page.

This project has just two models. A user and and Image. A user has
many images.

To see what I'm talking about one would clone the project with:

git clone g...@github.com:flsafe/test.git

Then run:

rake cucumber

The output will contain a description of the values I'm expecting in
the
'params' variable in the controller.

I know it's a lot to ask to checkout the project. I'm sure everyone is
very busy.
But I would really appreciate it after trying to figure this out for a
few days.

Thanks


On May 10, 3:45 pm, Frank <francisco.li...@gmail.com> wrote:
> I've made some slight progress towards solving this. I switched from
> Ruby 1.9.1 to ruby 1.8.7 and it solved the issue for several nested
> file fields.
> However, now I'm struggling with nested 'file_field'(s). I'm using
> webrat 0.7.1, cucumber 0.7.2, rails 2.3.5 and ruby 1.8.7-p249
>
> It is the same kind of error. I'm expecting an array of file fields in
> 'params'
>
>  'key'=>["#<ActionController::TestUploadedFile:0x267bec8>"]
>
> but instead I get one string that looks like:
>
>  key=>"#<ActionController::TestUploadedFile:0x267bec8>"
>
> I tried writing a few webrat specs to try and reproduce the problem
> but I haven't had any luck. I was wondering if anyone is familiar with
> what can cause "Expecting array but getting string" type errors.
>
> I'm experiencing something similar to this closed ticket:https://webrat.lighthouseapp.com/projects/10503/tickets/341-attach_fi...
>
> And this past post:http://groups.google.com/group/webrat/browse_thread/thread/a08a1cf4e8...

Matt Wynne

unread,
May 12, 2010, 4:28:14 AM5/12/10
to web...@googlegroups.com

On 11 May 2010, at 23:07, Frank wrote:

> Hi Guys,
>
> I've been trying to figure this out for a few days now. To better
> describe what I'm experiencing
> I've created a very simple github rails project at http://github.com/flsafe/test
>
> Check out the README on the github project page.
>
> This project has just two models. A user and and Image. A user has
> many images.
>
> To see what I'm talking about one would clone the project with:
>
> git clone g...@github.com:flsafe/test.git
>
> Then run:
>
> rake cucumber
>
> The output will contain a description of the values I'm expecting in
> the
> 'params' variable in the controller.
>
> I know it's a lot to ask to checkout the project. I'm sure everyone is
> very busy.
> But I would really appreciate it after trying to figure this out for a
> few days.
>
> Thanks

Just quickly Frank, you might have more luck with Capybara. It's basically a re-write of Webrat with a very similar API, but there seems to be a more active community around it.

I would try using capybara and see if your problem goes away. Then I'd try asking the capybara mailing list for help. There are a lot more people active in there.

Damian Janowski

unread,
May 14, 2010, 12:26:52 PM5/14/10
to web...@googlegroups.com
On Tue, May 11, 2010 at 7:07 PM, Frank <francis...@gmail.com> wrote:
> Hi Guys,
>
> I've been trying to figure this out for a few days now. To better
> describe what I'm experiencing
> I've created a very simple github rails project at http://github.com/flsafe/test

Hello Frank,

Thanks for providing a repo for the test.

After a couple of hours debugging this isssue, I added a branch that
shows that the behavior you're trying to use actually works. However,
in your sample app, you're using what I think is a strange flavor of
fields_for. Although I haven't done any Rails in a while, the docs
show that the usage should be like this:
http://github.com/brynary/webrat/blob/rails_attach_file/spec/integration/rails/app/views/webrat/file.html.erb#L5-8

Can you please check if there's anything missing in the branch I
created? http://github.com/brynary/webrat/blob/rails_attach_file
Note that under ./spec/integration/rails there's a fully fledged Rails
app that tests Webrat's integration with Rails.

If you see anything missing that would cause the integration test to
break, please provide a patch for the branch and we'll look into it.

Thank you.
Reply all
Reply to author
Forward
0 new messages