mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Move patch to address class - much simpler
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
require 'open_food_web/notify_invalid_address_save'
|
||||
|
||||
Spree::Address.class_eval do
|
||||
has_one :enterprise
|
||||
|
||||
@@ -13,4 +11,30 @@ Spree::Address.class_eval do
|
||||
filtered_address = full_address.select{ |field| !field.nil? && field != '' }
|
||||
filtered_address.compact.join(', ')
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
# We have a hard-to-track-down bug around invalid addresses with all-nil fields finding
|
||||
# their way into the database. I don't know what the source of them is, so this patch
|
||||
# is designed to track them down.
|
||||
# This is intended to be a temporary investigative measure, and should be removed from the
|
||||
# code base shortly.
|
||||
#
|
||||
#-- Rohan, 17-9-2913
|
||||
def create
|
||||
if self.zipcode.nil?
|
||||
Bugsnag.notify RuntimeError.new('Creating a Spree::Address with nil values')
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update(attribute_names = @attributes.keys)
|
||||
if self.zipcode.nil?
|
||||
Bugsnag.notify RuntimeError.new('Updating a Spree::Address with nil values')
|
||||
end
|
||||
|
||||
super(attribute_names)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
module OpenFoodWeb
|
||||
|
||||
# We have a hard-to-track-down bug around invalid addresses with all-nil fields finding
|
||||
# their way into the database. I don't know what the source of them is, so this patch
|
||||
# is designed to track them down.
|
||||
# This is intended to be a temporary investigative measure, and should be removed from the
|
||||
# code base shortly.
|
||||
#
|
||||
#-- Rohan, 17-9-2913
|
||||
module NotifyInvalidAddressSave
|
||||
def create
|
||||
if self.class == Spree::Address && self.zipcode.nil?
|
||||
Bugsnag.notify RuntimeError.new('Saving a Spree::Address with nil values')
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
if self.class == Spree::Address && self.zipcode.nil?
|
||||
Bugsnag.notify RuntimeError.new('Saving a Spree::Address with nil values')
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module ActiveRecord
|
||||
class Base
|
||||
include OpenFoodWeb::NotifyInvalidAddressSave
|
||||
end
|
||||
end
|
||||
@@ -1,20 +0,0 @@
|
||||
require 'open_food_web/notify_invalid_address_save'
|
||||
|
||||
module OpenFoodWeb
|
||||
describe NotifyInvalidAddressSave do
|
||||
describe "notifying bugsnag when a Spree::Address is saved with missing data" do
|
||||
it "notifies on create" do
|
||||
Bugsnag.should_receive(:notify)
|
||||
a = Spree::Address.new zipcode: nil
|
||||
a.save validate: false
|
||||
end
|
||||
|
||||
it "notifies on update" do
|
||||
Bugsnag.should_receive(:notify)
|
||||
a = create(:address)
|
||||
a.zipcode = nil
|
||||
a.save validate: false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -28,4 +28,19 @@ describe Spree::Address do
|
||||
address.full_address.split(',').length.should eql(4)
|
||||
end
|
||||
end
|
||||
|
||||
describe "notifying bugsnag when saved with missing data" do
|
||||
it "notifies on create" do
|
||||
Bugsnag.should_receive(:notify)
|
||||
a = Spree::Address.new zipcode: nil
|
||||
a.save validate: false
|
||||
end
|
||||
|
||||
it "notifies on update" do
|
||||
Bugsnag.should_receive(:notify)
|
||||
a = create(:address)
|
||||
a.zipcode = nil
|
||||
a.save validate: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user