Hello all,
My first question, in my controllers, do I need to test respond_to is
returning the correct data for its mime-type?
In my controller spec I have
it “creates a list of available types for that category” do
xhr :get, :index_available, :category_id => 1, :format => :json
assigns[:types].should have(1).record
end
and in my logs I see (406 Not acceptable…)
Processing TypesController#index_available to json (for 0.0.0.0 at
2011-05-02 13:20:01) [GET]
Parameters: {“category_id”=>“1”}
Completed in 1ms (View: 0, DB: 0) | 406 Not Acceptable [
http://test.host/categories/1/types/index_available.json]
SQL (0.1ms) ROLLBACK
SQL (0.0ms) BEGIN
But I get a green pass.
If I change :format => :json to ‘json’, I get a load of errors (which I
have
mentioned before on this list but haven’t had time to address the
situation)
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/hash.rb:37:in
each' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/hash.rb:37:in
map’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/hash.rb:37:in
to_json' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoding.rb:79:in
encode’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoding.rb:18:in
__send__' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoding.rb:18:in
encode’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/object.rb:4:in
to_json' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoding.rb:79:in
encode’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoding.rb:18:in
__send__' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoding.rb:18:in
encode’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/enumerable.rb:11:in
to_json' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/enumerable.rb:11:in
map’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/json/encoders/enumerable.rb:11:in
to_json' /home/anthony/Development/websites/ruby/GMFT/trunk/app/controllers/types_controller.rb:30:in
index_available’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:135:in
call' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:135:in
custom’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:179:in
call' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:179:in
respond’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:173:in
each' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:173:in
respond’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/mime_responds.rb:107:in
respond_to' /home/anthony/Development/websites/ruby/GMFT/trunk/app/controllers/types_controller.rb:29:in
index_available’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/base.rb:1333:in
send' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/base.rb:1333:in
perform_action_without_filters’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/filters.rb:617:in
call_filters' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/filters.rb:610:in
perform_action_without_benchmark’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in
ms’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in
ms' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/rescue.rb:160:in
perform_action_without_flash' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/flash.rb:151:in
perform_action’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/base.rb:532:in
send' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/base.rb:532:in
process_without_filters’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/filters.rb:606:in
process' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/test_process.rb:567:in
process_with_test’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/test_process.rb:447:in
process' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/test_process.rb:398:in
get’
/home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/test_process.rb:453:in
__send__' /home/anthony/.rvm/gems/ruby-1.8.7-p302@rails2311/gems/actionpack-2.3.11/lib/action_controller/test_process.rb:453:in
xhr’
./spec/controllers/types_controller_spec.rb:34:
So, two pronged question, do I need to test :json (seeing as I’m not
testing
the contents) and can anyone shed any light on my 406 and/or the errors
when
changing the format to ‘json’
Many thanks
-ants