diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e5250309b4..e6279bf226 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -17,7 +17,6 @@ class Enterprise < ActiveRecord::Base has_many :distributor_shipping_methods, foreign_key: :distributor_id has_many :shipping_methods, through: :distributor_shipping_methods - delegate :latitude, :longitude, :city, :state_name, :to => :address accepts_nested_attributes_for :address @@ -30,7 +29,7 @@ class Enterprise < ActiveRecord::Base validates_presence_of :address validates_associated :address - after_initialize :initialize_country + before_create :initialize_country before_validation :set_unused_address_fields after_validation :geocode_address @@ -207,6 +206,7 @@ class Enterprise < ActiveRecord::Base url.andand.sub /(https?:\/\/)?(www\.)?/, '' end + # Give us an empty address on create, and set the country to the default def initialize_country self.address ||= Spree::Address.new self.address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record? diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 0fa57d19d3..aa655bebfc 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -68,7 +68,7 @@ describe Enterprise do end it "should default address country to system country" do - subject.address.country.should == Spree::Country.find_by_id(Spree::Config[:default_country_id]) + create(:distributor_enterprise).address.country.should == Spree::Country.find_by_id(Spree::Config[:default_country_id]) end describe "scopes" do