cats_core 1.2.27 → 1.2.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dd652b6eeefe39811487b8fa993471b4f61c3692a8a1400ff929612ae7a6138
4
- data.tar.gz: 224e2b50ff72bf811c3a9a9acaf34f1bd24eeab09729e7ad0a04503e7d671785
3
+ metadata.gz: 6c2bd0f123f3f3c2ea21cd6987d61a19839bd8b60519ee8853ae00b163a2ff9c
4
+ data.tar.gz: e6825f6847ea16a205fbee1bcfe5d74bf546cbad91dd5ae2c0b42e38d33eb806
5
5
  SHA512:
6
- metadata.gz: a6d3e915bb2150d9d6cbeb62e571b100970ac74b8517cf96cc94f2b9c3517d0a40328aca7c55cab359991f27b090ce28d732e062a74d2188112839c61cc13f47
7
- data.tar.gz: c25d23f1eb76225dbb67bedcd439fc11ae1f2aaa6bd951f72af81bd00f6647a69861415f2c6da247a1f709da75fde33bb31e702f08228b6424018967996ea5d6
6
+ metadata.gz: d62649ef9300dbcac14b73ea849e1cda359b4e78a2d62ece62bb4df13d623c0e6f0ed435dabd48e35cae417baaaa5476975d8bdc5b6d9d7be05b4a972e4c9b7a
7
+ data.tar.gz: 535bc18ed18dd49dfeba9e8f58b966ee46690a7218293380658e9aa5ded0812ac20f47d9c474deaacc7f174ad3aae76d8da7e61f023f1bd376b4946ac5dc611a
@@ -6,7 +6,7 @@ module Cats
6
6
  private
7
7
 
8
8
  def model_params
9
- params.require(:payload).permit(:source_id, :destination_id)
9
+ params.require(:payload).permit(:region_id, :source_id, :destination_id)
10
10
  end
11
11
  end
12
12
  end
@@ -8,6 +8,8 @@ module Cats
8
8
  validates :price, presence: true, numericality: { greater_than: 0 }
9
9
 
10
10
  delegate(:name, to: :route, prefix: true)
11
+ delegate(:contract_no, to: :transport_contract, prefix: false)
12
+ delegate(:name, to: :unit, prefix: true)
11
13
  end
12
14
  end
13
15
  end
@@ -3,16 +3,36 @@ module Cats
3
3
  class Route < ApplicationRecord
4
4
  before_validation :set_name, on: %i[create update]
5
5
 
6
+ belongs_to :region, class_name: 'Cats::Core::Location'
6
7
  belongs_to :source, class_name: 'Cats::Core::Location'
7
8
  belongs_to :destination, class_name: 'Cats::Core::Location'
8
9
 
9
10
  validates :source_id, uniqueness: { scope: :destination_id }
11
+ validate :validate_region, :validate_source, :validate_destination
10
12
 
11
13
  def set_name
12
14
  return unless source && destination
13
15
 
14
16
  self.name = "#{source.name} - #{destination.name}"
15
17
  end
18
+
19
+ def validate_region
20
+ return unless region
21
+
22
+ errors.add(:region, 'should be a valid region.') unless region.location_type == Location::REGION
23
+ end
24
+
25
+ def validate_source
26
+ return unless source
27
+
28
+ errors.add(:source, 'cannot be a region.') if source.location_type == Location::REGION
29
+ end
30
+
31
+ def validate_destination
32
+ return unless destination
33
+
34
+ errors.add(:destination, 'cannot be a region.') if destination.location_type == Location::REGION
35
+ end
16
36
  end
17
37
  end
18
38
  end
@@ -4,7 +4,9 @@ module Cats
4
4
  belongs_to :region, class_name: 'Cats::Core::Location'
5
5
  belongs_to :transporter
6
6
  belongs_to :transport_bid
7
+ has_many :contract_items
7
8
 
9
+ validates :contract_no, presence: true, uniqueness: true
8
10
  validates :contract_date, :expires_on, presence: true
9
11
 
10
12
  delegate(:name, to: :region, prefix: true)
@@ -2,6 +2,10 @@ class CreateCatsCoreRoutes < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_routes do |t|
4
4
  t.string :name, null: false
5
+ t.references :region,
6
+ null: false,
7
+ index: { name: 'region_on_routes_indx' },
8
+ foreign_key: { to_table: :cats_core_locations }
5
9
  t.references :source,
6
10
  null: false,
7
11
  index: { name: 'source_on_routes_indx' },
@@ -13,7 +17,7 @@ class CreateCatsCoreRoutes < ActiveRecord::Migration[6.1]
13
17
 
14
18
  t.timestamps
15
19
 
16
- t.index [:source_id, :destination_id], unique: true
20
+ t.index %i[source_id destination_id], unique: true
17
21
  end
18
22
  end
19
23
  end
@@ -1,6 +1,7 @@
1
1
  class CreateCatsCoreTransportContracts < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_transport_contracts do |t|
4
+ t.string :contract_no, unique: true
4
5
  t.references :region,
5
6
  null: false,
6
7
  index: { name: 'region_on_tc_indx' },
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.27'.freeze
3
+ VERSION = '1.2.31'.freeze
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :route, class: 'Cats::Core::Route' do
3
- source factory: :location
4
- destination factory: :location
3
+ region factory: :location
4
+ source factory: :woreda
5
+ destination factory: :woreda
5
6
  end
6
7
  end
@@ -1,5 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :transport_contract, class: 'Cats::Core::TransportContract' do
3
+ contract_no { FFaker::Name.name }
3
4
  region factory: :location
4
5
  transporter
5
6
  transport_bid
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.27
4
+ version: 1.2.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-22 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers