You are my last resort for solving this issue as I have tried and tried
to
solve it myself but can’t.
I’m not even sure if it’s an RSpec issue but the thing is, if I run the
request from the browser, it works. Sadly, my test fails. So either
there’s
something about Rails I don’t know about (but should) or I’m doing
something
wrong in RSpec.
Here is my test …
let(:charity) { mock_model(Charity).as_null_object }
…
context “params[:term] has data” do
it “calls Charity::fulltext_search” do
Charity.should_receive(:fulltext_search).with(String).and_return([charity])
xhr :get, :autocomplete_index, :term => String, :format => :json
end
end
And this is my controller …
def autocomplete_index
@charities = (params[:term].blank?) ? [] :
Charity.fulltext_search(params[:term])
render :json => @charities ##.to_json(:only => [:name,
:official_website])
end
As I said, this works from the browser but I get into a ‘stack level too
deep’ with RSpec.
I looked in to gems/actionpack-2.3.8/lib/action_view/paths.rb and it’s
responsible for finding the template.
It raises MissingTemplate.new(self, original_template_path, format) and
I
printed the original_template_path (charities/) and the format (json)
If anyone can me in the right direction, I would be v grateful. Thank
you.
-ants
This is a snippet of the output (the bit between [[ ]] is repeated until
the
program quits with the ‘stack level too deep’ message.
[[
gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in
each' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in
map’
gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in
to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in
to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:38:in
to_json' *gems/actionpack-2.3.8/lib/action_view/paths.rb:74:in
map’*
]]
gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in
each' gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in
map’
gems/activesupport-2.3.8/lib/active_support/json/encoders/hash.rb:37:in
to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoders/object.rb:4:in
to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in
to_json' gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in
map’
gems/activesupport-2.3.8/lib/active_support/json/encoders/enumerable.rb:11:in
to_json' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:79:in
encode’
gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
__send__' gems/activesupport-2.3.8/lib/active_support/json/encoding.rb:18:in
encode’
gems/actionpack-2.3.8/lib/action_controller/base.rb:954:in
render_without_benchmark' gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in
render’
gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in
ms' gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in
ms’
gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in
render' */home/anthony/Development/websites/ruby/project/trunk/app/controllers/charities_controller.rb:23:in
autocomplete_index’*
gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in send' gems/actionpack-2.3.8/lib/action_controller/base.rb:1331:in
perform_action_without_filters’
gems/actionpack-2.3.8/lib/action_controller/filters.rb:617:in
call_filters' gems/actionpack-2.3.8/lib/action_controller/filters.rb:610:in
perform_action_without_benchmark’
gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in
ms’
gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in
ms' gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue’
gems/actionpack-2.3.8/lib/action_controller/rescue.rb:160:in
perform_action_without_flash' gems/actionpack-2.3.8/lib/action_controller/flash.rb:151:in
perform_action’
gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in send' gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in
process_without_filters’
gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in process' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:567:in
process_with_test’
gems/actionpack-2.3.8/lib/action_controller/test_process.rb:447:in
process' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:398:in
get’
gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in
__send__' gems/actionpack-2.3.8/lib/action_controller/test_process.rb:453:in
xhr’