Add Board model

parent fa576d38
class Board < ActiveRecord::Base
belongs_to :project
has_many :lists, dependent: :destroy
validates :project, presence: true
end
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 ...@@ -62,6 +62,8 @@ class Project < ActiveRecord::Base
belongs_to :group, -> { where(type: Group) }, foreign_key: 'namespace_id' belongs_to :group, -> { where(type: Group) }, foreign_key: 'namespace_id'
belongs_to :namespace belongs_to :namespace
has_one :board, dependent: :destroy
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id' has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id'
# Project services # Project services
......
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
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
...@@ -117,6 +117,14 @@ ActiveRecord::Schema.define(version: 20160810142633) do ...@@ -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"], 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 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| create_table "broadcast_messages", force: :cascade do |t|
t.text "message", null: false t.text "message", null: false
t.datetime "starts_at" t.datetime "starts_at"
...@@ -533,6 +541,18 @@ ActiveRecord::Schema.define(version: 20160810142633) do ...@@ -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 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| create_table "members", force: :cascade do |t|
t.integer "access_level", null: false t.integer "access_level", null: false
t.integer "source_id", null: false t.integer "source_id", null: false
...@@ -1116,6 +1136,9 @@ ActiveRecord::Schema.define(version: 20160810142633) do ...@@ -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_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 "personal_access_tokens", "users"
add_foreign_key "protected_branch_merge_access_levels", "protected_branches" add_foreign_key "protected_branch_merge_access_levels", "protected_branches"
add_foreign_key "protected_branch_push_access_levels", "protected_branches" add_foreign_key "protected_branch_push_access_levels", "protected_branches"
......
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
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 ...@@ -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(:slack_service).dependent(:destroy) }
it { is_expected.to have_one(:pushover_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(: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(:commit_statuses) }
it { is_expected.to have_many(:pipelines) } it { is_expected.to have_many(:pipelines) }
it { is_expected.to have_many(:builds) } it { is_expected.to have_many(:builds) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment