Remove old supplier and distributor routes, models, controllers, views, specs

This commit is contained in:
Rohan Mitchell
2012-11-01 09:55:45 +11:00
parent d927906934
commit 34588e6141
27 changed files with 38 additions and 692 deletions

View File

@@ -1,28 +0,0 @@
module Admin
class DistributorsController < ResourceController
before_filter :load_distributor_set, :only => :index
before_filter :load_countries, :except => :index
def bulk_update
@distributor_set = DistributorSet.new(params[:distributor_set])
if @distributor_set.save
redirect_to main_app.admin_distributors_path, :notice => 'Distributor collection times updated.'
else
render :index
end
end
private
def load_distributor_set
@distributor_set = DistributorSet.new :distributors => collection
end
def load_countries
@countries = Spree::Country.order(:name)
end
def collection
super.order(:name)
end
end
end

View File

@@ -1,16 +0,0 @@
module Admin
class SuppliersController < ResourceController
before_filter :load_data, :except => [:index]
helper 'spree/products'
private
def load_data
@countries = Spree::Country.order(:name)
end
def collection
super.order(:name)
end
end
end

View File

@@ -1,35 +0,0 @@
class DistributorsController < BaseController
def show
options = {:distributor_id => params[:id]}
options.merge(params.reject { |k,v| k == :id })
@distributor = Distributor.find params[:id]
@searcher = Spree::Config.searcher_class.new(options)
@products = @searcher.retrieve_products
end
def select
distributor = Distributor.find params[:id]
order = current_order(true)
if order.can_change_distributor?
order.distributor = distributor
order.save!
end
redirect_to distributor
end
def deselect
order = current_order(true)
if order.can_change_distributor?
order.distributor = nil
order.save!
end
redirect_to root_path
end
end

View File

@@ -1,15 +0,0 @@
class SuppliersController < BaseController
def index
@suppliers = Supplier.all
end
def show
options = {:supplier_id => params[:id]}
options.merge(params.reject { |k,v| k == :id })
@supplier = Supplier.find params[:id]
@searcher = Spree::Config.searcher_class.new(options)
@products = @searcher.retrieve_products
end
end

View File

@@ -1,31 +0,0 @@
class Distributor < ActiveRecord::Base
belongs_to :pickup_address, :foreign_key => 'pickup_address_id', :class_name => 'Spree::Address'
has_many :orders, :class_name => 'Spree::Order'
has_many :product_distributions, :dependent => :destroy
has_many :products, :through => :product_distributions
accepts_nested_attributes_for :pickup_address
validates_presence_of :name, :pickup_address
validates_associated :pickup_address
scope :by_name, order('name')
scope :with_active_products_on_hand, lambda { joins(:products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(distributors.*)') }
after_initialize :initialize_country
before_validation :set_unused_address_fields
def initialize_country
self.pickup_address ||= Spree::Address.new
self.pickup_address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) if self.pickup_address.new_record?
end
def set_unused_address_fields
pickup_address.firstname = pickup_address.lastname = pickup_address.phone = 'unused' if pickup_address.present?
end
def to_param
"#{id}-#{name.parameterize}"
end
end

View File

@@ -1,33 +0,0 @@
class Supplier < ActiveRecord::Base
has_many :products, :class_name => 'Spree::Product'
belongs_to :address, :class_name => 'Spree::Address'
accepts_nested_attributes_for :address
validates_presence_of :name, :address
validates_associated :address
after_initialize :initialize_country
before_validation :set_unused_address_fields
def has_products_on_hand?
self.products.where('count_on_hand > 0').present?
end
def to_param
"#{id}-#{name.parameterize}"
end
private
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
end

View File

@@ -1,11 +0,0 @@
Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "distributors_admin_tabs",
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= tab(:distributors, :url => main_app.admin_distributors_path) %>",
:disabled => false)
Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "suppliers_admin_tabs",
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= tab(:suppliers, :url => main_app.admin_suppliers_path) %>",
:disabled => false)

View File

@@ -1,42 +0,0 @@
- content_for :head do
= render 'shared/cms_elrte_head'
%table{"data-hook" => "distributors"}
%tr{"data-hook" => "name"}
%td Name:
%td= f.text_field :name
%tr{"data-hook" => "description"}
%td Description:
%td= f.text_field :description
%tr{'data-hook' => "long_description"}
%td Extended Description:
%td= f.text_area :long_description, :class => 'rich_text'
%tr{"data-hook" => "contact"}
%td Contact:
%td= f.text_field :contact
%tr{"data-hook" => "phone"}
%td Phone:
%td= f.text_field :phone
%tr{"data-hook" => "email"}
%td Email:
%td= f.text_field :email
%tr{"data-hook" => "url"}
%td URL:
%td= f.text_field :url
%tr{"data-hook" => "abn"}
%td ABN:
%td= f.text_field :abn
%tr{"data-hook" => "acn"}
%td ACN:
%td= f.text_field :acn
%fieldset
%legend Pickup details
%table{"data-hook" => "distributors_pickup_details"}
%tr{"data-hook" => "next_collection_at"}
%td Next collection date/time:
%td= f.text_field :next_collection_at
%tr{"data-hook" => "pickup_times"}
%td Regular pickup times:
%td= f.text_field :pickup_times
= f.fields_for :pickup_address do |pickup_address_form|
= render 'spree/admin/shared/address_form', :f => pickup_address_form

View File

@@ -1,6 +0,0 @@
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @distributor } %>
<%= form_for [:admin, @distributor] do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
<% end %>

View File

@@ -1,40 +0,0 @@
<div class="toolbar" data-hook="toolbar">
<ul class="actions">
<li>
<%= button_link_to "New Distributor", main_app.new_admin_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
</li>
</ul>
<br class="clear" />
</div>
<%= form_for @distributor_set, :url => main_app.bulk_update_admin_distributors_path do |f| %>
<table class="index" id="listing_distributors">
<thead>
<tr data-hook="distributors_header">
<th>Name</th>
<th>Next Collection Date/Time</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tbody>
<%= f.fields_for :distributors do |distributor_form| %>
<% distributor = distributor_form.object %>
<tr>
<td><%= link_to distributor.name, main_app.admin_distributor_path(distributor) %></td>
<td><%= distributor_form.text_field :next_collection_at %></td>
<td><%= distributor.description %></td>
<td data-hook="admin_users_index_row_actions">
<%= link_to_edit distributor, :class => 'edit' %> &nbsp;
<%= link_to_delete distributor %>
</td>
</tr>
<% end %>
<% if @distributors.empty? %>
<tr><td colspan="4"><%= t(:none) %></td></tr>
<% end %>
</tbody>
</table>
<%= f.submit 'Update' %>
<% end %>

View File

@@ -1,7 +0,0 @@
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @distributor } %>
<%= form_for [main_app, :admin, @distributor] do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= render :partial => 'spree/admin/shared/new_resource_links' %>
<% end %>

View File

@@ -1,42 +0,0 @@
%h1 Distributor
%table
%tr
%th Name:
%td= @distributor.name
%tr
%th Description:
%td= @distributor.description
%tr
%th Extended Description:
%td= @distributor.long_description.andand.html_safe
%tr
%th Contact person:
%td= @distributor.contact
%tr
%th Phone number:
%td= @distributor.phone
%tr
%th Email:
%td= @distributor.email
%tr
%th Pickup address:
%td= render 'spree/shared/address', :address => @distributor.pickup_address
%tr
%th Next collection date/time:
%td= @distributor.next_collection_at
%tr
%th Regular pickup times:
%td= @distributor.pickup_times
%tr
%th ABN:
%td= @distributor.abn
%tr
%th ACN:
%td= @distributor.acn
%tr
%th URL:
%td= @distributor.url
%p
= link_to :Edit, main_app.edit_admin_distributor_path(@distributor), :class => 'edit_distributor'
= t(:or)
= link_to t(:back), main_app.admin_distributors_path

View File

@@ -1,24 +0,0 @@
- content_for :head do
= render 'shared/cms_elrte_head'
%table{'data-hook' => "suppliers"}
%tr{'data-hook' => "name"}
%td Name:
%td= f.text_field :name
%tr{'data-hook' => "description"}
%td Description:
%td= f.text_field :description
%tr{'data-hook' => "long_description"}
%td Extended Description:
%td= f.text_area :long_description, :class => 'rich_text'
= f.fields_for :address do |address_form|
= render 'spree/admin/shared/address_form', :f => address_form
%tr{'data-hook' => "email"}
%td Email:
%td= f.text_field :email
%tr{'data-hook' => "website"}
%td Website:
%td= f.text_field :website
%tr{'data-hook' => "twitter"}
%td Twitter:
%td= f.text_field :twitter

View File

@@ -1,5 +0,0 @@
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
= form_for [:admin, @supplier] do |f|
= render :partial => 'form', :locals => { :f => f }
= render :partial => 'spree/admin/shared/edit_resource_links'

View File

@@ -1,22 +0,0 @@
.toolbar{'data-hook' => "suppliers"}
%ul.actions
%li= button_link_to "New Supplier", main_app.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link'
%br.clear
%table#listing_suppliers.index
%thead
%tr{'data-hook' => "suppliers_header"}
%th Name
%th Description
%th
%tbody
- @suppliers.each do |supplier|
%tr
%td= link_to supplier.name, main_app.admin_supplier_path(supplier)
%td= supplier.description
%td{'data-hook' => "admin_supplier_index_row_actions"}
= link_to_edit supplier, :class => 'edit'
&nbsp;
= link_to_delete supplier
- if @suppliers.empty?
%tr
%td{:colspan => "2"}= t(:none)

View File

@@ -1,5 +0,0 @@
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
= form_for [main_app, :admin, @supplier] do |f|
= render :partial => 'form', :locals => { :f => f }
= render :partial => 'spree/admin/shared/new_resource_links'

View File

@@ -1,27 +0,0 @@
%h1 Supplier
%table
%tr
%th Name:
%td= @supplier.name
%tr
%th Description:
%td= @supplier.description
%tr
%th Extended Description:
%td= @supplier.long_description.andand.html_safe
%tr
%th Address:
%td= render 'spree/shared/address', :address => @supplier.address
%tr
%th Email:
%td= @supplier.email
%tr
%th Website:
%td= @supplier.website
%tr
%th Twitter:
%td= @supplier.twitter
%p
= link_to :Edit, main_app.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
= t(:or)
= link_to t(:back), main_app.admin_suppliers_path

View File

@@ -1,7 +0,0 @@
%h2= @distributor.name
.distributor-description= @distributor.long_description.andand.html_safe
%h3 Available Now
= render :template => 'spree/products/index'

View File

@@ -1,12 +0,0 @@
- content_for :sidebar do
%div{'data-hook' => "homepage_sidebar_navigation"}
= render 'spree/sidebar'
%h1 Suppliers
= cms_page_content(:content, Cms::Page.find_by_full_path('/suppliers'))
%ul.suppliers
- @suppliers.each do |supplier|
%li= link_to supplier.name, supplier

View File

@@ -1,7 +0,0 @@
%h2= @supplier.name
.supplier-description= @supplier.long_description.andand.html_safe
%h3 Available Now
= render :template => 'spree/products/index'

View File

@@ -7,25 +7,10 @@ Openfoodweb::Application.routes.draw do
get :deselect_distributor, :on => :collection
end
# Deprecated
resources :suppliers
# Deprecated
resources :distributors do
get :select, :on => :member
get :deselect, :on => :collection
end
namespace :admin do
resources :enterprises do
post :bulk_update, :on => :collection, :as => :bulk_update
end
# Deprecated
resources :distributors do
post :bulk_update, :on => :collection, :as => :bulk_update
end
# Deprecated
resources :suppliers
end
# Mount Spree's routes

View File

@@ -0,0 +1,37 @@
class RemoveSuppliersAndDistributors < ActiveRecord::Migration
def up
drop_table :suppliers
drop_table :distributors
end
def down
create_table "distributors" do |t|
t.string :name
t.string :contact
t.string :phone
t.string :email
t.string :pickup_times
t.string :url
t.string :abn
t.string :acn
t.string :description
t.datetime :created_at
t.datetime :updated_at
t.integer :pickup_address_id
t.string :next_collection_at
t.text :long_description
end
create_table "suppliers" do |t|
t.string :name
t.string :description
t.string :email
t.string :twitter
t.string :website
t.datetime :created_at
t.datetime :updated_at
t.integer :address_id
t.text :long_description
end
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121028070200) do
ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "cms_blocks", :force => true do |t|
t.integer "page_id", :null => false
@@ -130,23 +130,6 @@ ActiveRecord::Schema.define(:version => 20121028070200) do
add_index "cms_snippets", ["site_id", "identifier"], :name => "index_cms_snippets_on_site_id_and_identifier", :unique => true
add_index "cms_snippets", ["site_id", "position"], :name => "index_cms_snippets_on_site_id_and_position"
create_table "distributors", :force => true do |t|
t.string "name"
t.string "contact"
t.string "phone"
t.string "email"
t.string "pickup_times"
t.string "url"
t.string "abn"
t.string "acn"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "pickup_address_id"
t.string "next_collection_at"
t.text "long_description"
end
create_table "enterprises", :force => true do |t|
t.string "name"
t.string "description"
@@ -793,16 +776,4 @@ ActiveRecord::Schema.define(:version => 20121028070200) do
t.integer "zone_members_count", :default => 0
end
create_table "suppliers", :force => true do |t|
t.string "name"
t.string "description"
t.string "email"
t.string "twitter"
t.string "website"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "address_id"
t.text "long_description"
end
end

View File

@@ -1,75 +0,0 @@
require 'spec_helper'
require 'spree/core/current_order'
describe DistributorsController do
include Spree::Core::CurrentOrder
before :each do
stub!(:before_save_new_order)
stub!(:after_save_new_order)
create(:itemwise_shipping_method)
end
it "selects distributors" do
d = create(:distributor)
spree_get :select, :id => d.id
response.should be_redirect
order = current_order(false)
order.distributor.should == d
end
it "deselects distributors" do
d = create(:distributor)
order = current_order(true)
order.distributor = d
order.save!
spree_get :deselect
response.should be_redirect
order.reload
order.distributor.should be_nil
end
context "when a product has been added to the cart" do
it "does not allow selecting another distributor" do
# Given some distributors and an order with a product
d1 = create(:distributor)
d2 = create(:distributor)
p = create(:product, :distributors => [d1])
o = current_order(true)
o.distributor = d1
o.save!
o.add_variant(p.master, 1)
# When I attempt to select a distributor
spree_get :select, :id => d2.id
# Then my distributor should remain unchanged
o.reload
o.distributor.should == d1
end
it "does not allow deselecting distributors" do
# Given a distributor and an order with a product
d = create(:distributor)
p = create(:product, :distributors => [d])
o = current_order(true)
o.distributor = d
o.save!
o.add_variant(p.master, 1)
# When I attempt to deselect the distributor
spree_get :deselect
# Then my distributor should remain unchanged
o.reload
o.distributor.should == d
end
end
end

View File

@@ -20,27 +20,6 @@ FactoryGirl.define do
is_distributor true
end
factory :supplier, :class => Supplier do
sequence(:name) { |n| "Supplier #{n}" }
description 'supplier'
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
email 'supplier@example.com'
address { Spree::Address.first || FactoryGirl.create(:address) }
end
factory :distributor, :class => Distributor do
sequence(:name) { |n| "Distributor #{n}" }
contact 'Mr Turing'
phone '1000100100'
description 'The creator'
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
email 'alan@somewhere.com'
url 'http://example.com'
pickup_times "Whenever you're free"
next_collection_at 'Thursday 10am'
pickup_address { Spree::Address.first || FactoryGirl.create(:address) }
end
factory :product_distribution, :class => ProductDistribution do
product { |pd| Spree::Product.first || FactoryGirl.create(:product) }
distributor { |pd| Enterprise.is_distributor.first || FactoryGirl.create(:distributor_enterprise) }

View File

@@ -1,80 +0,0 @@
require "spec_helper"
feature %q{
As an administration
I want manage the distributors of products
} do
include AuthenticationWorkflow
include WebHelper
scenario "listing distributors" do
d = create(:distributor)
login_to_admin_section
click_link 'Distributors'
page.should have_content d.name
end
scenario "viewing a distributor" do
d = create(:distributor)
login_to_admin_section
click_link 'Distributors'
click_link d.name
page.should have_content d.name
end
scenario "creating a new distributor" do
login_to_admin_section
click_link 'Distributors'
click_link 'New Distributor'
fill_in 'distributor_name', :with => 'Eaterprises'
fill_in 'distributor_description', :with => 'Connecting farmers and eaters'
fill_in 'distributor_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
fill_in 'distributor_contact', :with => 'Kirsten or Ren'
fill_in 'distributor_phone', :with => '0413 897 321'
fill_in 'distributor_pickup_address_attributes_address1', :with => '35 Ballantyne St'
fill_in 'distributor_pickup_address_attributes_city', :with => 'Thornbury'
fill_in 'distributor_pickup_address_attributes_zipcode', :with => '3072'
select('Australia', :from => 'distributor_pickup_address_attributes_country_id')
select('Victoria', :from => 'distributor_pickup_address_attributes_state_id')
fill_in 'distributor_next_collection_at', :with => 'Thursday, 22nd Feb, 6 - 9 PM'
fill_in 'distributor_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
fill_in 'distributor_email', :with => 'info@eaterprises.com.au'
fill_in 'distributor_url', :with => 'http://eaterprises.com.au'
fill_in 'distributor_abn', :with => '09812309823'
fill_in 'distributor_acn', :with => ''
click_button 'Create'
flash_message.should == 'Distributor "Eaterprises" has been successfully created!'
end
scenario "updating many distributor next collection times at once" do
# Given three distributors
3.times { create(:distributor) }
# When I go to the distributors page
login_to_admin_section
click_link 'Distributors'
# And I fill in some new collection times and save them
fill_in 'distributor_set_distributors_attributes_0_next_collection_at', :with => 'One'
fill_in 'distributor_set_distributors_attributes_1_next_collection_at', :with => 'Two'
fill_in 'distributor_set_distributors_attributes_2_next_collection_at', :with => 'Three'
click_button 'Update'
# Then my times should have been saved
flash_message.should == 'Distributor collection times updated.'
Distributor.all.map { |d| d.next_collection_at }.should == %w(One Two Three)
end
end

View File

@@ -1,56 +0,0 @@
require "spec_helper"
feature %q{
As an administration
I want manage the suppliers of products
} do
include AuthenticationWorkflow
include WebHelper
background do
end
scenario "listing suppliers" do
s = create(:supplier)
login_to_admin_section
click_link 'Suppliers'
page.should have_content s.name
end
scenario "viewing a supplier" do
s = create(:supplier)
login_to_admin_section
click_link 'Suppliers'
click_link s.name
page.should have_content s.name
end
scenario "creating a new supplier" do
login_to_admin_section
click_link 'Suppliers'
click_link 'New Supplier'
fill_in 'supplier_name', :with => 'David Arnold'
fill_in 'supplier_description', :with => 'A farmer with a difference'
fill_in 'supplier_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
fill_in 'supplier_address_attributes_address1', :with => '35 Byron Ave'
fill_in 'supplier_address_attributes_city', :with => 'Ararat'
fill_in 'supplier_address_attributes_zipcode', :with => '1112'
select('Australia', :from => 'supplier_address_attributes_country_id')
select('Victoria', :from => 'supplier_address_attributes_state_id')
fill_in 'supplier_email', :with => 'david@here.com'
fill_in 'supplier_website', :with => 'http://somewhere.com'
fill_in 'supplier_twitter', :with => 'davida'
click_button 'Create'
flash_message.should == 'Supplier "David Arnold" has been successfully created!'
end
end