mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Data integrity
This commit is contained in:
@@ -9,7 +9,7 @@ class Enterprise < ActiveRecord::Base
|
||||
has_many :product_distributions, :foreign_key => 'distributor_id', :dependent => :destroy
|
||||
has_many :distributed_products, :through => :product_distributions, :source => :product
|
||||
has_many :enterprise_fees
|
||||
has_many :enterprise_roles
|
||||
has_many :enterprise_roles, :dependent => :destroy
|
||||
has_many :users, through: :enterprise_roles
|
||||
has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id'
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class EnsureShippingMethodsHaveDistributors < ActiveRecord::Migration
|
||||
def up
|
||||
d = Enterprise.is_distributor.first
|
||||
sms = Spree::ShippingMethod.where('distributor_id IS NULL')
|
||||
say "Assigning an arbitrary distributor (#{d.name}) to all shipping methods without one (#{sms.count} total)"
|
||||
|
||||
sms.update_all(distributor_id: d)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130912021938) do
|
||||
ActiveRecord::Schema.define(:version => 20130919010513) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
|
||||
@@ -7,6 +7,16 @@ describe Enterprise do
|
||||
it { should have_many(:distributed_orders) }
|
||||
it { should belong_to(:address) }
|
||||
it { should have_many(:product_distributions) }
|
||||
|
||||
it "should destroy enterprise roles upon its own demise" do
|
||||
e = create(:enterprise)
|
||||
u = create(:user)
|
||||
u.enterprise_roles.build(enterprise: e).save!
|
||||
|
||||
role = e.enterprise_roles.first
|
||||
e.destroy
|
||||
EnterpriseRole.where(id: role.id).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
|
||||
Reference in New Issue
Block a user