cats_core 1.2.10 → 1.2.14

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: 5cd22f5d1828025591dc9c478cac117524de3bf179379ce32f8866d5b7765b50
4
- data.tar.gz: d4aa1ad82b39cbe515bd06508abac047cdb28f0acb6b508a132bc5cf84e30ac5
3
+ metadata.gz: 7b9dc1890545dec4869aee94fb842abbc54a673f6f84ecc8ef96b927800e70c5
4
+ data.tar.gz: 9f0186a8c840f424da193d6c1c9e15bdaec9d1e29a72628094db7de9007c14b2
5
5
  SHA512:
6
- metadata.gz: f8210d5329e61312fc0150fe91e99330740e0a31d33078aa140c215b706ac329fb6fed6958d852942ab354fc4ffaee0200f313dc4f8c46d448ae0eb129ec2f5d
7
- data.tar.gz: 830891e351410797b6b882905db148df50912bf3903dc29a8041c0f22563ce5c50970150c7cd743881abff66bfd80138e6feab34b181d4af0bcf4ddb1bc1526a
6
+ metadata.gz: b82245e6eba1c6ead0156d91fb28273b49747e880b333fbbc04de3e2a9cfb3caa23d3bade2109bb65c01d4c91aaddcb4089623e816e83f4a05b03c3146e055c7
7
+ data.tar.gz: a76b70cf682be9e03d61f349356bd6dc3eaf6b16325af7fed988a9ffd43e83d2c9a7c3c590b4298f28c06da90a64814785247e42e4f4eb09b74ce9b86c04fec6
@@ -5,8 +5,24 @@ module Cats
5
5
  belongs_to :transporter
6
6
 
7
7
  validates :price, presence: true, numericality: { greater_than: 0 }
8
+ validates :rank, numericality: { greater_than: 0 }, allow_nil: true
9
+ validate :validate_winner_is_set_for_rank
8
10
 
9
11
  delegate(:name, to: :transporter, prefix: true)
12
+
13
+ def mark_as_winner(rank)
14
+ raise(StandardError, 'Offer already marked as winner.') if winner
15
+
16
+ self.rank = rank
17
+ self.winner = true
18
+ save!
19
+ end
20
+
21
+ def validate_winner_is_set_for_rank
22
+ return if winner
23
+
24
+ errors.add(:rank, 'cannot be set for a non-winning offer.') if rank
25
+ end
10
26
  end
11
27
  end
12
28
  end
@@ -3,10 +3,13 @@ module Cats
3
3
  class TransportRequest < ApplicationRecord
4
4
  DRAFT = 'Draft'.freeze
5
5
  APPROVED = 'Approved'.freeze
6
- STATUSES = [DRAFT, APPROVED].freeze
6
+ OPEN = 'Open'.freeze
7
+ CLOSED = 'Closed'.freeze
8
+ STATUSES = [DRAFT, APPROVED, OPEN, CLOSED].freeze
7
9
 
8
10
  belongs_to :requested_by, class_name: 'Cats::Core::User'
9
11
  belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
12
+ has_many :transport_request_items
10
13
 
11
14
  validates :reference_no, :request_date, :status, presence: true
12
15
  validates :reference_no, uniqueness: true
@@ -14,6 +17,30 @@ module Cats
14
17
 
15
18
  delegate(:full_name, to: :requested_by, prefix: true, allow_nil: true)
16
19
  delegate(:full_name, to: :approved_by, prefix: true, allow_nil: true)
20
+
21
+ def approve(approver)
22
+ raise(StandardError, 'Request is not open for approval.') unless status == DRAFT
23
+
24
+ raise(StandardError, 'Request is empty.') if transport_request_items.count.zero?
25
+
26
+ self.approved_by = approver
27
+ self.status = APPROVED
28
+ save!
29
+ end
30
+
31
+ def open
32
+ raise(StandardError, 'Request is not approved for opening.') unless status == APPROVED
33
+
34
+ self.status = OPEN
35
+ save!
36
+ end
37
+
38
+ def close
39
+ raise(StandardError, 'Request is not open.') unless status == OPEN
40
+
41
+ self.status = CLOSED
42
+ save!
43
+ end
17
44
  end
18
45
  end
19
46
  end
@@ -10,6 +10,8 @@ class CreateCatsCoreTransportOffers < ActiveRecord::Migration[6.1]
10
10
  index: { name: 'to_on_transporter_indx' },
11
11
  foreign_key: { to_table: :cats_core_transporters }
12
12
  t.float :price, null: false
13
+ t.boolean :winner, null: false, default: false
14
+ t.integer :rank
13
15
 
14
16
  t.timestamps
15
17
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.10'.freeze
3
+ VERSION = '1.2.14'.freeze
4
4
  end
5
5
  end
@@ -3,5 +3,7 @@ FactoryBot.define do
3
3
  transport_request_item
4
4
  transporter
5
5
  price { 100 }
6
+ winner { false }
7
+ rank { nil }
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 1.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.