ruby on rails - Rspec controller spec returning undefined method 'where' -
trying build controller spec using rspec on rails controller have named "api::zipscontroller".
the controller accepts parameter called "zip_code" , returns active record model , 200 status.
however, when run rspec test fails nomethoderror:
undefined method 'where' zip:module
. believe because 'where' instance method, not class method need stub/mock it? unfortunately have not had luck in resolving problem of yet.
zips_controller_spec.rb:
describe api::zipscontroller require 'spec_helper' "returns 200 status zones data" 'show', zip_code: "v9a1b2" response.should be_success end end
api/zips_controller.rb - (working):
class api::zipscontroller < applicationcontroller def show zip = zip.where(zip_code: params[:zip_code].upcase.slice(0..2)) render json: zip, status: 200 end end
zip.rb (model):
class zip < activerecord::base def as_json(options) super(:only => [:zip_code]) end end
you have zip
module defined somewhere conflicting zip
model. somewhere in code or trickier use of rubyzip
gem.
you namespace model in module suggested in answer or rename model else zipcode
.
Comments
Post a Comment