From 82ca7112c2c630852f1ad2b3a8516c455d2cff90 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 18 Jun 2012 17:01:08 +1000 Subject: [PATCH] Remove distributor association from orders and from the checkout process --- app/models/spree/distributor.rb | 1 - app/models/spree/order_decorator.rb | 30 ++++++++----------- ..._move_distributor_from_order_to_product.rb | 12 ++++++++ db/schema.rb | 4 +-- spec/request/consumer/checkout_spec.rb | 2 +- spec/spec_helper.rb | 4 +++ 6 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 db/migrate/20120618061537_move_distributor_from_order_to_product.rb diff --git a/app/models/spree/distributor.rb b/app/models/spree/distributor.rb index d261335a0f..6024684207 100644 --- a/app/models/spree/distributor.rb +++ b/app/models/spree/distributor.rb @@ -1,7 +1,6 @@ module Spree class Distributor < ActiveRecord::Base self.table_name = 'distributors' - has_many :orders belongs_to :country belongs_to :state diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 4a38447903..0ab2f2b892 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -1,22 +1,18 @@ Spree::Order.class_eval do - attr_accessible :distributor_id - - belongs_to :distributor - - before_validation :shipping_address_from_distributor + # before_validation :shipping_address_from_distributor private - def shipping_address_from_distributor - if distributor - ship_address.firstname = bill_address.firstname - ship_address.lastname = bill_address.lastname - ship_address.phone = bill_address.phone + # def shipping_address_from_distributor + # if distributor + # ship_address.firstname = bill_address.firstname + # ship_address.lastname = bill_address.lastname + # ship_address.phone = bill_address.phone - ship_address.address1 = distributor.pickup_address - ship_address.city = distributor.city - ship_address.zipcode = distributor.post_code - ship_address.state = distributor.state - ship_address.country_id = distributor.country_id - end - end + # ship_address.address1 = distributor.pickup_address + # ship_address.city = distributor.city + # ship_address.zipcode = distributor.post_code + # ship_address.state = distributor.state + # ship_address.country_id = distributor.country_id + # end + # end end diff --git a/db/migrate/20120618061537_move_distributor_from_order_to_product.rb b/db/migrate/20120618061537_move_distributor_from_order_to_product.rb new file mode 100644 index 0000000000..c7d3343292 --- /dev/null +++ b/db/migrate/20120618061537_move_distributor_from_order_to_product.rb @@ -0,0 +1,12 @@ +class MoveDistributorFromOrderToProduct < ActiveRecord::Migration + def change + remove_column :spree_orders, :distributor_id + add_column :spree_products, :distributor_id, :integer + Spree::Order.reset_column_information + Spree::Product.reset_column_information + + # Associate all products with the first distributor so they'll be valid + distributor = Spree::Distributor.first + Spree::Product.update_all("distributor_id = #{distributor.id}") if distributor + end +end diff --git a/db/schema.rb b/db/schema.rb index 83f327c9a8..b881d00e3c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120520062061) do +ActiveRecord::Schema.define(:version => 20120618061537) do create_table "distributors", :force => true do |t| t.string "name" @@ -248,7 +248,6 @@ ActiveRecord::Schema.define(:version => 20120520062061) do t.string "payment_state" t.string "email" t.text "special_instructions" - t.integer "distributor_id" end add_index "spree_orders", ["number"], :name => "index_orders_on_number" @@ -354,6 +353,7 @@ ActiveRecord::Schema.define(:version => 20120520062061) do t.datetime "updated_at" t.integer "count_on_hand", :default => 0, :null => false t.integer "supplier_id" + t.integer "distributor_id" end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" diff --git a/spec/request/consumer/checkout_spec.rb b/spec/request/consumer/checkout_spec.rb index b298f7fce2..57bae7846e 100644 --- a/spec/request/consumer/checkout_spec.rb +++ b/spec/request/consumer/checkout_spec.rb @@ -23,7 +23,7 @@ feature %q{ end context "Given I am buying a product", :js => true do - scenario "I should be able choose a distributor to pick up from" do + scenario "I should be able choose a distributor to pick up from", :skip => true do login_to_consumer_section click_link 'Fuji apples' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a5daba09a7..d8884ab2d2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,6 +37,10 @@ RSpec.configure do |config| # rspec-rails. config.infer_base_class_for_anonymous_controllers = false + # ## Filters + # + config.filter_run_excluding :skip => true + config.before(:suite) do DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_states'] } end