Rspec View Issue

33 views
Skip to first unread message

John

unread,
Dec 16, 2014, 4:23:31 PM12/16/14
to rs...@googlegroups.com

Overview :

in my views i have a button(test) with action image.csv , when i am clicking( find_button('test').click) on that , it sending to controller image

Problem : 
It's not passing whole action to the server . so format option always getting html , not csv , in the test cases

please suggest me for the same

Jon Rowe

unread,
Dec 16, 2014, 4:26:20 PM12/16/14
to rs...@googlegroups.com
Can you paste your view code and your spec, without those it’s impossible to diagnose where you are going wrong. You also don’t mention what type of test this is which further complicates diagnosing the issue.

Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/3659fc68-3d51-40f6-b12a-01975ff6624c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John

unread,
Dec 16, 2014, 4:34:24 PM12/16/14
to rs...@googlegroups.com

To Reproduce Issue :

Views Code 
= f.submit 'test', 'data-action' => 'images.csv'
= link_to "test1", images_path(format: "csv")

Rspec code :

Case 1: 
scenario 'Should get valid CSV files' do
click_button('test')
end
Case 2: 
scenario 'Should get valid CSV files' do
click_link('test1')
end

check the log files , in case 1 request Url is images

in case 2 request Url is images.csv

John

unread,
Dec 16, 2014, 4:39:39 PM12/16/14
to rs...@googlegroups.com
@jonrowe 

i am using poltergeist driver 


On Tuesday, 16 December 2014 22:23:31 UTC+1, John wrote:

Jon Rowe

unread,
Dec 16, 2014, 4:44:11 PM12/16/14
to rs...@googlegroups.com
For the benefit of the people on the list part of the view code:

= f.submit 'test', 'data-action' => 'images.csv'
= link_to "test1", images_path(format: "csv")

Spec files:

scenario 'Should get valid CSV files' do
  click_button('test')
end

scenario 'Should get valid CSV files' do
  click_link('test1')
end
Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.

Jon Rowe

unread,
Dec 16, 2014, 4:48:40 PM12/16/14
to rs...@googlegroups.com
Looking at your code I’d suggest you check that `data-action` is actually being set on your page and not lost into Rails, I’m not sure Rails would recognise it passed in like that, you might have to add `html_options: { 'data-action' => 'images.csv }` additionally even if it is being passed in correctly theres still the possibility your JS is erroring.

Jon Rowe
---------------------------

John

unread,
Dec 16, 2014, 5:02:04 PM12/16/14
to rs...@googlegroups.com
This is my javascript code  

$('input[data-action]').click(function() {
    $('form#searchform').attr('action', $(this).data('action'));
  });

On Tuesday, 16 December 2014 22:23:31 UTC+1, John wrote:

Jon Rowe

unread,
Dec 16, 2014, 5:08:56 PM12/16/14
to rs...@googlegroups.com
I’m not a jQuery expert but that doesn’t look like it will work, the form is already firing at this point so even if you have the right form, with the right attributes (you haven’t pasted your generated view so it’s impossible to tell) you possibly can’t mutate it. I *think* you need to change the action, submit the form yourself, and then return false from the original JS event.

Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages