Create models for EnterpriseGroups

This commit is contained in:
Rohan Mitchell
2013-10-24 13:53:36 +11:00
parent 8d0f192ca7
commit e78815c2d3
6 changed files with 67 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ class Enterprise < ActiveRecord::Base
acts_as_gmappable :process_geocoding => false
has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup'
has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy
has_many :distributed_orders, :class_name => 'Spree::Order', :foreign_key => 'distributor_id'
belongs_to :address, :class_name => 'Spree::Address'

View File

@@ -0,0 +1,5 @@
class EnterpriseGroup < ActiveRecord::Base
has_and_belongs_to_many :enterprises
validates :name, presence: true
end

View File

@@ -0,0 +1,13 @@
class CreateEnterpriseGroups < ActiveRecord::Migration
def change
create_table :enterprise_groups do |t|
t.string :name
t.boolean :on_front_page
end
create_table :enterprise_groups_enterprises, id: false do |t|
t.references :enterprise_group
t.references :enterprise
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 => 20131016230055) do
ActiveRecord::Schema.define(:version => 20131024005253) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"
@@ -170,6 +170,16 @@ ActiveRecord::Schema.define(:version => 20131016230055) do
t.datetime "updated_at", :null => false
end
create_table "enterprise_groups", :force => true do |t|
t.string "name"
t.boolean "on_front_page"
end
create_table "enterprise_groups_enterprises", :id => false, :force => true do |t|
t.integer "enterprise_group_id"
t.integer "enterprise_id"
end
create_table "enterprise_roles", :force => true do |t|
t.integer "user_id"
t.integer "enterprise_id"
@@ -470,9 +480,9 @@ ActiveRecord::Schema.define(:version => 20131016230055) do
t.string "email"
t.text "special_instructions"
t.integer "distributor_id"
t.integer "order_cycle_id"
t.string "currency"
t.string "last_ip_address"
t.integer "order_cycle_id"
t.integer "cart_id"
end

View File

@@ -95,6 +95,11 @@ FactoryGirl.define do
is_distributor true
end
factory :enterprise_group, :class => EnterpriseGroup do
name 'Enterprise group'
on_front_page false
end
sequence(:calculator_amount)
factory :enterprise_fee, :class => EnterpriseFee do
ignore { amount nil }

View File

@@ -0,0 +1,31 @@
require 'spec_helper'
describe EnterpriseGroup do
describe "validations" do
it "is valid when built from factory" do
e = build(:enterprise_group)
e.should be_valid
end
it "requires a name" do
e = build(:enterprise_group, name: '')
e.should_not be_valid
end
end
describe "relations" do
it "habtm enterprises" do
e = create(:supplier_enterprise)
eg = create(:enterprise_group)
eg.enterprises << e
eg.reload.enterprises.should == [e]
end
# it "can have an image" do
# eg = create(:enterprise_group)
# image_file = File.open(File.expand_path('../../../app/assets/images/logo.jpg', __FILE__))
# image = Spree::Image.create(viewable_id: eg.id, viewable_type: 'EnterpriseGroup', attachment: image_file)
# eg.reload.image.should == image
# end
end
end