Add Board model
This commit is contained in:
parent
fa576d38bb
commit
611dab2e52
9 changed files with 108 additions and 0 deletions
7
app/models/board.rb
Normal file
7
app/models/board.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class Board < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
|
||||
has_many :lists, dependent: :destroy
|
||||
|
||||
validates :project, presence: true
|
||||
end
|
10
app/models/list.rb
Normal file
10
app/models/list.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class List < ActiveRecord::Base
|
||||
belongs_to :board
|
||||
belongs_to :label
|
||||
|
||||
enum list_type: { label: 0, backlog: 1, done: 2 }
|
||||
|
||||
validates :board, :list_type, :position, presence: true
|
||||
validates :label, presence: true, if: :label?
|
||||
validates :position, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
end
|
|
@ -62,6 +62,8 @@ class Project < ActiveRecord::Base
|
|||
belongs_to :group, -> { where(type: Group) }, foreign_key: 'namespace_id'
|
||||
belongs_to :namespace
|
||||
|
||||
has_one :board, dependent: :destroy
|
||||
|
||||
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id'
|
||||
|
||||
# Project services
|
||||
|
|
13
db/migrate/20160727191041_create_boards.rb
Normal file
13
db/migrate/20160727191041_create_boards.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class CreateBoards < ActiveRecord::Migration
|
||||
include Gitlab::Database::MigrationHelpers
|
||||
|
||||
DOWNTIME = false
|
||||
|
||||
def change
|
||||
create_table :boards do |t|
|
||||
t.references :project, index: true, foreign_key: true, null: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
12
db/migrate/20160727193336_create_lists.rb
Normal file
12
db/migrate/20160727193336_create_lists.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class CreateLists < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :lists do |t|
|
||||
t.references :board, index: true, foreign_key: true, null: false
|
||||
t.references :label, index: true, foreign_key: true
|
||||
t.integer :list_type, null: false, default: 0
|
||||
t.integer :position, null: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
23
db/schema.rb
23
db/schema.rb
|
@ -117,6 +117,14 @@ ActiveRecord::Schema.define(version: 20160810142633) do
|
|||
add_index "award_emoji", ["user_id", "name"], name: "index_award_emoji_on_user_id_and_name", using: :btree
|
||||
add_index "award_emoji", ["user_id"], name: "index_award_emoji_on_user_id", using: :btree
|
||||
|
||||
create_table "boards", force: :cascade do |t|
|
||||
t.integer "project_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "boards", ["project_id"], name: "index_boards_on_project_id", using: :btree
|
||||
|
||||
create_table "broadcast_messages", force: :cascade do |t|
|
||||
t.text "message", null: false
|
||||
t.datetime "starts_at"
|
||||
|
@ -533,6 +541,18 @@ ActiveRecord::Schema.define(version: 20160810142633) do
|
|||
|
||||
add_index "lfs_objects_projects", ["project_id"], name: "index_lfs_objects_projects_on_project_id", using: :btree
|
||||
|
||||
create_table "lists", force: :cascade do |t|
|
||||
t.integer "board_id", null: false
|
||||
t.integer "label_id"
|
||||
t.integer "list_type", default: 0, null: false
|
||||
t.integer "position", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "lists", ["board_id"], name: "index_lists_on_board_id", using: :btree
|
||||
add_index "lists", ["label_id"], name: "index_lists_on_label_id", using: :btree
|
||||
|
||||
create_table "members", force: :cascade do |t|
|
||||
t.integer "access_level", null: false
|
||||
t.integer "source_id", null: false
|
||||
|
@ -1116,6 +1136,9 @@ ActiveRecord::Schema.define(version: 20160810142633) do
|
|||
|
||||
add_index "web_hooks", ["project_id"], name: "index_web_hooks_on_project_id", using: :btree
|
||||
|
||||
add_foreign_key "boards", "projects"
|
||||
add_foreign_key "lists", "boards"
|
||||
add_foreign_key "lists", "labels"
|
||||
add_foreign_key "personal_access_tokens", "users"
|
||||
add_foreign_key "protected_branch_merge_access_levels", "protected_branches"
|
||||
add_foreign_key "protected_branch_push_access_levels", "protected_branches"
|
||||
|
|
12
spec/models/board_spec.rb
Normal file
12
spec/models/board_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Board do
|
||||
describe 'relationships' do
|
||||
it { is_expected.to belong_to(:project) }
|
||||
it { is_expected.to have_many(:lists).dependent(:destroy) }
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it { is_expected.to validate_presence_of(:project) }
|
||||
end
|
||||
end
|
28
spec/models/list_spec.rb
Normal file
28
spec/models/list_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe List do
|
||||
describe 'relationships' do
|
||||
it { is_expected.to belong_to(:board) }
|
||||
it { is_expected.to belong_to(:label) }
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it { is_expected.to validate_presence_of(:board) }
|
||||
it { is_expected.to validate_presence_of(:label) }
|
||||
it { is_expected.to validate_presence_of(:list_type) }
|
||||
it { is_expected.to validate_presence_of(:position) }
|
||||
it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than_or_equal_to(0) }
|
||||
|
||||
it 'does not require label to be set when list_type is set to backlog' do
|
||||
subject.list_type = :backlog
|
||||
|
||||
expect(subject).not_to validate_presence_of(:label)
|
||||
end
|
||||
|
||||
it 'does not require label to be set when list_type is set to done' do
|
||||
subject.list_type = :done
|
||||
|
||||
expect(subject).not_to validate_presence_of(:label)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -23,6 +23,7 @@ describe Project, models: true do
|
|||
it { is_expected.to have_one(:slack_service).dependent(:destroy) }
|
||||
it { is_expected.to have_one(:pushover_service).dependent(:destroy) }
|
||||
it { is_expected.to have_one(:asana_service).dependent(:destroy) }
|
||||
it { is_expected.to have_one(:board).dependent(:destroy) }
|
||||
it { is_expected.to have_many(:commit_statuses) }
|
||||
it { is_expected.to have_many(:pipelines) }
|
||||
it { is_expected.to have_many(:builds) }
|
||||
|
|
Loading…
Reference in a new issue