我无法在特定地址的测试特定邮政编码的钢轨方法。我有一个在模型中被继承和验证的问题。它修复了用户输入查询不匹配,他们位于美国默认邮政编码的另一个问题。不过,我最终需要运行迁移来解决已存在缺陷直到这一点任何邮政编码。这给我带来了我的问题。有没有办法通过控制台来测试特定的关注点或方法?如何测试通过轨道控制台
我关心的是下面。
module StateMatchesZipCodeConcern
extend ActiveSupport::Concern
def verify_zip_matches_state
return unless zip.present? && state.present?
state_search_result = query_zip_code
unless state_search_result.nil?
return if state_search_result.upcase == state.upcase
return if validate_against_multi_state_zip_codes
end
errors[:base] << "Please verify the address you've submitted. The postal code #{zip.upcase} is not valid for the state of #{state.upcase}"
false
end
private
def query_zip_code
tries ||= 3
Geocoder.search(zip).map(&:state_code).keep_if { |x| Address::STATES.values.include?(x) }.first
rescue Geocoder::OverQueryLimitError, Timeout::Error
retry unless (tries -= 1).zero?
end
def validate_against_multi_state_zip_codes
::Address::MULTI_STATE_ZIP_CODES[zip].try(:include?, state)
end
end
我试过User.last.address.validate_against_multi_state_zip_codes?
和风与方法失踪。有人会知道我在这里错过了什么吗?
你是真棒!非常感谢! – kdweber89
http://i.imgur.com/9ld8MlW.gif – DiegoSalazar