cats_core 1.2.11 → 1.2.15

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: d9f57a513afb90596f709408275f30e41f9b4e4b45fe5807db6c3ef743e11b72
4
- data.tar.gz: ecbdbe4277fa2d4fff4558a3936aa7cc6668a0bc62d1660ba86b6c90cfa44801
3
+ metadata.gz: '0259f4a23c09b64cad9bc0f1c1488eb6671590d9cb0b159943a9420644137f18'
4
+ data.tar.gz: 16af2ac84725a7fc0ce5fe87e485d6dbae46bca0d3b8f290a219175ff8c14a5c
5
5
  SHA512:
6
- metadata.gz: 568910a95c3524abeb0b0aa227d1bb8fb505e1474610c22ce23588572550fe978c099f5c1ec78c43895db16bb97653660580a9c516a7d53babda91445eaf5847
7
- data.tar.gz: 0257f48eef8cce083a1b1783d4a744ded17c39feac5c016950a4b4509b145a139eaeb4632e7f5c3b33f8a95ea6e811e061941e6051c2b2ede174c9087bc0ee09
6
+ metadata.gz: dc637444ec8abe5e3f00b3b540915d49458edf3b460658209d4ec95ac5db30a7ed070673dbbe40d9476be8c626cf503b86dac8d456f7d000a44928f1955bfd3a
7
+ data.tar.gz: 489b67dc9d9709d2d0bf93d653662eafb40faddff1659f5a7af122008cf0dd05a0270d89d2f4d29a1f44eb1efd15238085c994908c21f1c14767d067e556815d
@@ -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,7 +3,9 @@ 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
@@ -15,6 +17,30 @@ module Cats
15
17
 
16
18
  delegate(:full_name, to: :requested_by, prefix: true, allow_nil: true)
17
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
18
44
  end
19
45
  end
20
46
  end
@@ -6,6 +6,8 @@ module Cats
6
6
  belongs_to :destination, class_name: 'Cats::Core::Location'
7
7
  belongs_to :commodity
8
8
 
9
+ has_many :transport_offers
10
+
9
11
  delegate(:name, to: :source, prefix: true)
10
12
  delegate(:name, to: :destination, prefix: true)
11
13
  delegate(:name, to: :commodity, prefix: true)
@@ -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.11'.freeze
3
+ VERSION = '1.2.15'.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,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.11
4
+ version: 1.2.15
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-12 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers