diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index c74144446b..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,6 +29,7 @@ class Enterprise < ActiveRecord::Base validates_presence_of :address validates_associated :address + before_create :initialize_country before_validation :set_unused_address_fields after_validation :geocode_address @@ -206,6 +206,12 @@ 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? + end + def set_unused_address_fields address.firstname = address.lastname = address.phone = 'unused' if address.present? end diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index 2d4c834191..5cde67a512 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -1,35 +1,35 @@ = inject_enterprises --#.producers{"ng-controller" => "ProducersCtrl"} - -#.row - -#.small-12.columns.text-center.pad-top - -#%h1 Producers - -#%div - -#Select a - -#%ofn-modal{title: "producer"} - -#= render partial: "modals/producers" - -#from the list below: +.producers{"ng-controller" => "ProducersCtrl"} + .row + .small-12.columns.text-center.pad-top + %h1 Producers + %div + Select a + %ofn-modal{title: "producer"} + = render partial: "modals/producers" + from the list below: - -##active-table-search.row.pad-top - -#.small-12.columns - -#%i.ofn-i_020-search - -#%input{type: :text, - -#"ng-model" => "query", - -#placeholder: "Search postcode, suburb or producer name...", - -#"ng-debounce" => "150", - -#"ofn-disable-enter" => true} + #active-table-search.row.pad-top + .small-12.columns + %i.ofn-i_020-search + %input{type: :text, + "ng-model" => "query", + placeholder: "Search postcode, suburb or producer name...", + "ng-debounce" => "150", + "ofn-disable-enter" => true} - -#.row{bindonce: true} - -#.small-12.columns - -#.active_table - -#%producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", - -#"scroll-after-load" => true, - -#"ng-repeat" => "producer in filteredProducers = (Producers.visible | filterProducers:query)", - -#"ng-controller" => "ProducerNodeCtrl", - -#"ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", - -#id: "{{producer.hash}}"} + .row{bindonce: true} + .small-12.columns + .active_table + %producer.active_table_node.row.animate-repeat{id: "{{producer.path}}", + "scroll-after-load" => true, + "ng-repeat" => "producer in filteredProducers = (Producers.visible | filterProducers:query)", + "ng-controller" => "ProducerNodeCtrl", + "ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !producer.active}", + id: "{{producer.hash}}"} - -#.small-12.columns - -#= render partial: 'producers/skinny' - -#= render partial: 'producers/fat' + .small-12.columns + = render partial: 'producers/skinny' + = render partial: 'producers/fat' --#= render partial: "shared/footer" += render partial: "shared/footer" 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