From 7ea0f733984f2e08fce12e287dfc6d831d4407e3 Mon Sep 17 00:00:00 2001 From: Andrew Spinks Date: Sun, 22 Apr 2012 14:51:24 +1000 Subject: [PATCH] begin adding suppliers --- Gemfile | 2 +- .../spree/admin/suppliers_controller.rb | 12 ++++++ app/models/spree/supplier.rb | 17 +++++++++ app/overrides/distributors_admin_tab.rb | 6 +++ .../spree/admin/suppliers/index.html.erb | 37 +++++++++++++++++++ config/initializers/spree.rb | 2 +- config/routes.rb | 1 + db/migrate/20120422042134_add_supplier.rb | 16 ++++++++ spec/models/distributors_spec.rb | 9 +++++ spec/models/suppliers_spec.rb | 9 +++++ 10 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 app/controllers/spree/admin/suppliers_controller.rb create mode 100644 app/models/spree/supplier.rb create mode 100644 app/views/spree/admin/suppliers/index.html.erb create mode 100644 db/migrate/20120422042134_add_supplier.rb create mode 100644 spec/models/distributors_spec.rb create mode 100644 spec/models/suppliers_spec.rb diff --git a/Gemfile b/Gemfile index f300c4cc36..1469eab74e 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,7 @@ gem 'jquery-rails' # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' -group :test do +group :test, :development do # Pretty printed test output gem 'turn', '~> 0.8.3', :require => false gem 'rspec-rails' diff --git a/app/controllers/spree/admin/suppliers_controller.rb b/app/controllers/spree/admin/suppliers_controller.rb new file mode 100644 index 0000000000..6f80b2ffeb --- /dev/null +++ b/app/controllers/spree/admin/suppliers_controller.rb @@ -0,0 +1,12 @@ +module Spree + module Admin + class SuppliersController < ResourceController + # before_filter :load_data, :except => [:index] + + private + def collection + super.order(:name) + end + end + end +end \ No newline at end of file diff --git a/app/models/spree/supplier.rb b/app/models/spree/supplier.rb new file mode 100644 index 0000000000..df73a6c630 --- /dev/null +++ b/app/models/spree/supplier.rb @@ -0,0 +1,17 @@ +module Spree + class Supplier < ActiveRecord::Base + set_table_name 'suppliers' + belongs_to :address + # has_many :orders + # belongs_to :country + # belongs_to :state + + # validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true + + # after_initialize :initialize_country + + # def initialize_country + # self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) + # end + end +end diff --git a/app/overrides/distributors_admin_tab.rb b/app/overrides/distributors_admin_tab.rb index 66e4946b40..ff19b8b1e9 100644 --- a/app/overrides/distributors_admin_tab.rb +++ b/app/overrides/distributors_admin_tab.rb @@ -3,3 +3,9 @@ Deface::Override.new(:virtual_path => "spree/layouts/admin", :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]", :text => "<%= tab(:distributors, :url => spree.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 => spree.admin_suppliers_path) %>", + :disabled => false) \ No newline at end of file diff --git a/app/views/spree/admin/suppliers/index.html.erb b/app/views/spree/admin/suppliers/index.html.erb new file mode 100644 index 0000000000..82e5bc927c --- /dev/null +++ b/app/views/spree/admin/suppliers/index.html.erb @@ -0,0 +1,37 @@ + +
+ +
+
+ + + + + + + + + + + <% @suppliers.each do |supplier| %> + + + + + + <% end %> + <% if @suppliers.empty? %> + + <% end %> + +
Name + Description + +
<%= link_to supplier.name, spree.admin_supplier_path(supplier) %><%=supplier.description %> + <%= link_to_edit supplier, :class => 'edit' %>   + <%= link_to_delete supplier %> +
<%= t(:none) %>
\ No newline at end of file diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 475a484c2c..b3030f0abe 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -13,5 +13,5 @@ Spree.config do |config| # config.shipping_instructions = true config.checkout_zone = 'Australia' config.address_requires_state = true - config.default_country_id = Spree::Country.find_by_name('Australia').id + config.default_country_id = Spree::Country.find_by_name('Australia').id if Spree::Country.find_by_name('Australia') end diff --git a/config/routes.rb b/config/routes.rb index 2e31e3ab44..c4ffbaf86d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,5 +65,6 @@ end Spree::Core::Engine.routes.prepend do namespace :admin do resources :distributors + resources :suppliers end end diff --git a/db/migrate/20120422042134_add_supplier.rb b/db/migrate/20120422042134_add_supplier.rb new file mode 100644 index 0000000000..85add9901a --- /dev/null +++ b/db/migrate/20120422042134_add_supplier.rb @@ -0,0 +1,16 @@ +class AddSupplier < ActiveRecord::Migration + def change + create_table :suppliers do |t| + t.string :name + t.string :description + t.string :url + t.string :email + t.string :twitter + t.string :website + + t.integer :address_id + + t.timestamps + end + end +end diff --git a/spec/models/distributors_spec.rb b/spec/models/distributors_spec.rb new file mode 100644 index 0000000000..d7935b8cb5 --- /dev/null +++ b/spec/models/distributors_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Spree::Distributor do + + it "should default the country to the default spree country" do + + end + +end diff --git a/spec/models/suppliers_spec.rb b/spec/models/suppliers_spec.rb new file mode 100644 index 0000000000..15672d666f --- /dev/null +++ b/spec/models/suppliers_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Spree::Supplier do + + it "should have an address" + + it "should add an address on save" + +end