Help with rspec and javascript

I want to test an action called with javascript.
The action is:

def index
unless params[:customer_full_name].blank?
full_name = params[:customer_full_name]
@customers = Customer.search_full_name(full_name).paginate(:per_page
=> 10,
:page => params[:page])
else
@customers = Customer.all.paginate(:per_page => 10, :page =>
params[:page])
end
render :layout => false if request.xhr?
end

In the view I have a form with a search field.
When I put values in this field it calls a javascript function.
I’ve tried to write this test:

require ‘spec_helper’
require ‘capybara/rspec’

describe CustomersController do
include Devise::TestHelpers

describe “search with js”, :js => true do
before(:each) do
@customers = mock_model(Customer, :full_name => “User-1”)
end

context “when full_name is ‘user’” do
it “should find customers” do
login
page.should have_content “Customers”
page.should have_content “Dashboard”
click_link(‘Customers’)
fill_in “customer_full_name”, :with => “User”
@full_name = “User”
Customer.should_receive(:search_full_name).with(@full_name).and_return(@customers)
@customers.should_receive(:paginate)
do_get
assigns(:customers).should_not be_nil
end
end

def login
User.make!
visit ‘/d/users/sign_in/’
fill_in “user_email”, :with => “[email protected]
fill_in “user_password”, :with => “password”
click_button “Sign in”
end

def do_get page= nil, format = ‘html’
get ‘index’, :customer_full_name => @full_name, :format => format
end

Doesn’t work.
Any advise?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs