Re: spec for view with Searchlogic

Hi,

for using rspec with the SearchLogic plugin we found the following
solutions to mock/stub
the necessary objects/methods:

Views:

create search logic values

@search = mock(“search”)
@search.stub!(:page_count).and_return(2)
assigns[:search] = @search
@plannings_count = 20
assigns[:plannings_count] = @item_categories_count

stub the search form, otherwise the following error:

undefined method `spec_mocks_mock_path’ for

#ActionView::Base:0x6ac1470

template.stub(:remote_form_for).and_return(true)

stub search logic helpers, otherwise the following errors:

@search object could not be inferred, please specify:

:search_obj => @search or :params_scope => :search_obj_name

template.stub(:remote_per_page_select).and_return(true)
template.stub(:remote_page_links).and_return(true)

Controllers:

scopes

@search =

Planning.with_associations.not_deleted.new_search(params[:search])

Planning.stub!(:with_associations).and_return(@search)
@search.stub!(:not_deleted).and_return(@search)
@search.stub!(:new_search).and_return(@search)

Andrea

Von: “Andrea J.” [email protected]
Gesendet: 25.03.09 15:50:06
An: [email protected]
Betreff: [rspec-users] spec for view with Searchlogic

Hi,

I’m using the Searchlogic plugin. Since I have added the search form in
the index template,
the view spec doesn’t work anymore.

Controller

def index
@search = PlPlanning.new_search(params[:search])
@search.order_by = :id
@pl_plannings, @count = @search.all, @search.count
end

view

<% remote_form_for [:planning, @search] do |f| %> Search <%= PlPlanning::DISPLAY_NAME.pluralize %> &nbsp ; <% f.fields_for @search.conditions do |pl_plannings| %> <%= pl_plannings.label :id, PlPlanning::DISPLAY_NAME + " Id:", :class => "search_label" %> <%= pl_plannings.text_field :id %>
<%= f.submit "Search" %> <% end %> <% end %>

spec

class Searchlogic::Cache::PlPlanningSearch; end

before(:each) do
@pl_plannings = []
assigns[:pl_plannings] = @pl_plannings

@search = Searchlogic::Cache::PlPlanningSearch.new ???
assigns[:search] = @search

& nbsp; render “/planning/pl_plannings/index”
end

=> Error in the line containing the remote_form_for call
undefined method `planning_searchlogic_cache_pl_planning_search_path’
for #ActionView::Base:0x6b6bf38

Has anybody experience with Searchlogic + rspec ? Can I stub
search_paths ?

Thanks
Andrea

Verschicken Sie SMS direkt vom Postfach aus - in alle deutschen und
viele
ausländische Netze zum gleichen Preis!

_______________________________________________rspec-users mailing
[email protected]://rubyforge.org/mailman/listinfo/rspec-users

WEB.DE FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und
Telefonanschluss für 17,95 Euro/mtl.! WEB.DE Produkte Übersicht: Apps, Browser, MailCheck & Co.
[WEB.DE Produkte Übersicht: Apps, Browser, MailCheck & Co.]