Skip to content

Commit 1a7f5d3

Browse files
committed
feat(invoice): replace enumerize state with enum
1 parent 8f01ee6 commit 1a7f5d3

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

spec/dummy/app/admin/invoices.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
]
5858
}
5959

60-
f.input :state
60+
f.input :state, as: :select
6161

6262
f.input :category_id, as: :search_select,
6363
url: proc { "/admin/categories" },

spec/dummy/app/models/invoice.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
require 'enumerize'
21
require 'aasm'
32

43
class Invoice < ActiveRecord::Base
5-
extend ::Enumerize
64
include AASM
75
include ImageUploader::Attachment(:picture)
6+
after_initialize :set_default_state, if: :new_record?
87

98
belongs_to :category
109
belongs_to :city
1110
has_and_belongs_to_many :items
1211
has_and_belongs_to_many :other_items, class_name: 'Item'
1312

14-
enumerize :state, in: [:pending, :rejected, :approved], default: :pending
13+
enum state: {
14+
pending: 'pending',
15+
rejected: 'rejected',
16+
approved: 'approved',
17+
}
1518

1619
enum status: { active: 0, archived: 1 }
1720

@@ -86,4 +89,8 @@ def self.colors
8689
"#B9BF00"
8790
]
8891
end
92+
93+
def set_default_state
94+
self.state ||= 'pending'
95+
end
8996
end

0 commit comments

Comments
 (0)