views:

244

answers:

1

I have the following function in controller

def by_xy
        @obj = BldPoly::find_by_xy(:x => params['x'], :y => params['y'])

        respond_to do |format|
            format.html { render :layout => false  }
            format.xml { render :layout => false }
            format.json { render :layout => false }
end

and planning to write the automatic test in the following way

xml = nil
get :by_xy, {:x => 4831, :y => 3242, :format => :json} 
assert_nothing_thrown { xml = REXML::Document.new(@response.body) }

td = REXML::XPath.first(xml, "//result/item")
assert_equal need_value, td.value

and I get Completed in 50ms (View: 0, DB: 230) | 406 Not Acceptable [http://test.host/search/by%5Fxy/4831/3242.json%5D

when I missed format in testing code - all works correctly,

how should I write the test?

A: 

I figured this out, actually; this is how it should be

get :by_xy, {:x => i[:x], :y => i[:y]}, :format => :json
se_pavel