How to assert duplicate record while updating or inserting record Test case for API in ruby on rails using fakeweb
options = {:body => fixture_file("parse.xml"),:content_type => "application/xml",:status =>["200", "OK"]}
FakeWeb.register_uri(:get, @url, options)
doc = Nokogiri::XML(open(@url,:ssl_verify_mode => OpenSSL::SSL开发者_开发技巧::VERIFY_NONE))
should "cases should not insert duplicate record" do
doc.xpath('//cases/case').each do |case|
end
end
here inserting or updating record using Model.find_or_initialize_by_id(case['ixBug'])
, how i should check this condition in test case by putting assertion?
I think you should check for duplicate records using model validations. It seems you're doing integration testing (that is useful to test controller responses and/or test that all the environment is working well).
it doesn't make sense to test data duplication there.
精彩评论