mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
SO: Adding StandingLineItem model
This commit is contained in:
8
app/models/standing_line_item.rb
Normal file
8
app/models/standing_line_item.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class StandingLineItem < ActiveRecord::Base
|
||||
belongs_to :standing_order
|
||||
belongs_to :variant, class_name: 'Spree::Variant'
|
||||
|
||||
validates :standing_order, presence: true
|
||||
validates :variant, presence: true
|
||||
validates :quantity, { presence: true, numericality: { only_integer: true } }
|
||||
end
|
||||
16
db/migrate/20160824013751_create_standing_line_items.rb
Normal file
16
db/migrate/20160824013751_create_standing_line_items.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class CreateStandingLineItems < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :standing_line_items do |t|
|
||||
t.references :standing_order, null: false
|
||||
t.references :variant, null: false
|
||||
t.integer :quantity, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :standing_line_items, :standing_order_id
|
||||
add_index :standing_line_items, :variant_id
|
||||
|
||||
add_foreign_key :standing_line_items, :standing_orders, name: 'oc_standing_line_items_standing_order_id_fk'
|
||||
add_foreign_key :standing_line_items, :spree_variants, name: 'oc_standing_line_items_variant_id_fk', column: :variant_id
|
||||
end
|
||||
end
|
||||
14
db/schema.rb
14
db/schema.rb
@@ -1063,6 +1063,17 @@ ActiveRecord::Schema.define(:version => 20170921065259) do
|
||||
t.integer "zone_members_count", :default => 0
|
||||
end
|
||||
|
||||
create_table "standing_line_items", :force => true do |t|
|
||||
t.integer "standing_order_id", :null => false
|
||||
t.integer "variant_id", :null => false
|
||||
t.integer "quantity", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "standing_line_items", ["standing_order_id"], :name => "index_standing_line_items_on_standing_order_id"
|
||||
add_index "standing_line_items", ["variant_id"], :name => "index_standing_line_items_on_variant_id"
|
||||
|
||||
create_table "standing_orders", :force => true do |t|
|
||||
t.integer "shop_id", :null => false
|
||||
t.integer "customer_id", :null => false
|
||||
@@ -1309,6 +1320,9 @@ ActiveRecord::Schema.define(:version => 20170921065259) do
|
||||
|
||||
add_foreign_key "spree_zone_members", "spree_zones", name: "spree_zone_members_zone_id_fk", column: "zone_id"
|
||||
|
||||
add_foreign_key "standing_line_items", "spree_variants", name: "oc_standing_line_items_variant_id_fk", column: "variant_id"
|
||||
add_foreign_key "standing_line_items", "standing_orders", name: "oc_standing_line_items_standing_order_id_fk"
|
||||
|
||||
add_foreign_key "standing_orders", "customers", name: "oc_standing_orders_customer_id_fk"
|
||||
add_foreign_key "standing_orders", "enterprises", name: "oc_standing_orders_shop_id_fk", column: "shop_id"
|
||||
add_foreign_key "standing_orders", "schedules", name: "oc_standing_orders_schedule_id_fk"
|
||||
|
||||
17
spec/models/standing_line_item_spec.rb
Normal file
17
spec/models/standing_line_item_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe StandingLineItem, model: true do
|
||||
describe "validations" do
|
||||
it "requires a standing_order" do
|
||||
expect(subject).to validate_presence_of :standing_order
|
||||
end
|
||||
|
||||
it "requires a variant" do
|
||||
expect(subject).to validate_presence_of :variant
|
||||
end
|
||||
|
||||
it "requires a integer for quantity" do
|
||||
expect(subject).to validate_numericality_of(:quantity).only_integer
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,31 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe StandingOrder, type: :model do
|
||||
let!(:standing_order) { create(:standing_order) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires a shop" do
|
||||
expect(standing_order).to validate_presence_of :shop
|
||||
expect(subject).to validate_presence_of :shop
|
||||
end
|
||||
|
||||
it "requires a customer" do
|
||||
expect(standing_order).to validate_presence_of :customer
|
||||
expect(subject).to validate_presence_of :customer
|
||||
end
|
||||
|
||||
it "requires a schedule" do
|
||||
expect(standing_order).to validate_presence_of :schedule
|
||||
expect(subject).to validate_presence_of :schedule
|
||||
end
|
||||
|
||||
it "requires a payment_method" do
|
||||
expect(standing_order).to validate_presence_of :payment_method
|
||||
expect(subject).to validate_presence_of :payment_method
|
||||
end
|
||||
|
||||
it "requires a shipping_method" do
|
||||
expect(standing_order).to validate_presence_of :shipping_method
|
||||
expect(subject).to validate_presence_of :shipping_method
|
||||
end
|
||||
|
||||
it "requires a begins_at date" do
|
||||
expect(standing_order).to validate_presence_of :begins_at
|
||||
expect(subject).to validate_presence_of :begins_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user