mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Add order and show_in_roadmap fields to PostStatus
This commit is contained in:
@@ -11,6 +11,8 @@ class PostStatusDashboard < Administrate::BaseDashboard
|
||||
id: Field::Number,
|
||||
name: Field::String,
|
||||
color: ColorField,
|
||||
order: Field::Number,
|
||||
show_in_roadmap: Field::Boolean,
|
||||
created_at: Field::DateTime,
|
||||
updated_at: Field::DateTime,
|
||||
}.freeze
|
||||
@@ -23,6 +25,8 @@ class PostStatusDashboard < Administrate::BaseDashboard
|
||||
COLLECTION_ATTRIBUTES = %i[
|
||||
name
|
||||
color
|
||||
order
|
||||
show_in_roadmap
|
||||
].freeze
|
||||
|
||||
# SHOW_PAGE_ATTRIBUTES
|
||||
@@ -31,6 +35,8 @@ class PostStatusDashboard < Administrate::BaseDashboard
|
||||
id
|
||||
name
|
||||
color
|
||||
order
|
||||
show_in_roadmap
|
||||
created_at
|
||||
updated_at
|
||||
].freeze
|
||||
@@ -41,6 +47,8 @@ class PostStatusDashboard < Administrate::BaseDashboard
|
||||
FORM_ATTRIBUTES = %i[
|
||||
name
|
||||
color
|
||||
order
|
||||
show_in_roadmap
|
||||
].freeze
|
||||
|
||||
# COLLECTION_FILTERS
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class PostStatus < ApplicationRecord
|
||||
validates :name, presence: true, uniqueness: true
|
||||
validates :color, format: { with: /\A#(?:[0-9a-fA-F]{3}){1,2}\z/ }
|
||||
validates :order, numericality: { only_integer: true, greater_than: 0 }
|
||||
end
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddOrderAndShowInRoadmapToPostStatuses < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :post_statuses, :order, :integer, null: false, default: 999
|
||||
add_column :post_statuses, :show_in_roadmap, :boolean, null: false, default: false
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_08_25_093234) do
|
||||
ActiveRecord::Schema.define(version: 2019_08_26_154118) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -28,6 +28,8 @@ ActiveRecord::Schema.define(version: 2019_08_25_093234) do
|
||||
t.string "color", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "order", default: 999, null: false
|
||||
t.boolean "show_in_roadmap", default: false, null: false
|
||||
t.index ["name"], name: "index_post_statuses_on_name", unique: true
|
||||
end
|
||||
|
||||
|
||||
@@ -2,5 +2,7 @@ FactoryBot.define do
|
||||
factory :post_status do
|
||||
sequence(:name) { |n| "Post Status #{n}" }
|
||||
color { '#ffffff' }
|
||||
sequence(:order) { |n| n }
|
||||
show_in_roadmap { true }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,4 +36,18 @@ RSpec.describe PostStatus, type: :model do
|
||||
expect(valid_color).to be_valid
|
||||
expect(valid_color2).to be_valid
|
||||
end
|
||||
|
||||
it 'must have a order of type integer and positive' do
|
||||
nil_order = FactoryBot.build(:post_status, order: nil)
|
||||
empty_order = FactoryBot.build(:post_status, order: '')
|
||||
decimal_order = FactoryBot.build(:post_status, order: 1.1)
|
||||
negative_order = FactoryBot.build(:post_status, order: -1)
|
||||
zero_order = FactoryBot.build(:post_status, order: 0)
|
||||
|
||||
expect(nil_order).to be_invalid
|
||||
expect(empty_order).to be_invalid
|
||||
expect(decimal_order).to be_invalid
|
||||
expect(negative_order).to be_invalid
|
||||
expect(zero_order).to be_invalid
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user