Skip to content

Commit

Permalink
Merge pull request #338 from howtohireme/196-stack-model
Browse files Browse the repository at this point in the history
(#196) add stack model and data migration
  • Loading branch information
Mehonoshin committed Jul 23, 2018
2 parents dc9ced4 + d8313c5 commit cf97a6b
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/models/skill.rb
Expand Up @@ -7,6 +7,8 @@ class Skill < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
has_many :developer_test_tasks, class_name: 'Developer::TestTask'
has_many :stack_skills
has_many :stacks, through: :stack_skills

include AASM

Expand Down
10 changes: 10 additions & 0 deletions app/models/stack.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

# It group of skills, that are required for project staffing.
class Stack < ApplicationRecord
has_many :stack_skills
has_many :skills, through: :stack_skills

validates :name, presence: true
validates :identifier, presence: true, uniqueness: true
end
7 changes: 7 additions & 0 deletions app/models/stack_skill.rb
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# This model is designed to stroe links between skill and stack
class StackSkill < ApplicationRecord
belongs_to :skill
belongs_to :stack
end
2 changes: 1 addition & 1 deletion app/models/user_skill.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# This model is designed to store links between user and skilll
# This model is designed to store links between user and skill
class UserSkill < ApplicationRecord
belongs_to :skill
belongs_to :user
Expand Down
4 changes: 2 additions & 2 deletions data/skills.yml
Expand Up @@ -2,9 +2,9 @@
- Ruby
- Java
- Clojure
- JavaScript
- Front-end
- Python
- ".Net"
- '.Net'
- Design
- Project Management
- Quality Assurance
8 changes: 8 additions & 0 deletions db/data/20180723180541_add_stack_to_production.rb
@@ -0,0 +1,8 @@
class AddStackToProduction < ActiveRecord::Migration[5.2]
def change
stack = Stack.create!(name: 'Rails monolith', identifier: 'rails_monolith')
Skill.where(title: %w[Ruby Front-end]).each do |skill|
stack.skills << skill
end
end
end
2 changes: 1 addition & 1 deletion db/data_schema.rb
@@ -1,2 +1,2 @@

DataMigrate::Data.define(version: 20180707131445)
DataMigrate::Data.define(version: 20180723180541)
12 changes: 12 additions & 0 deletions db/migrate/20180723172036_create_stacks.rb
@@ -0,0 +1,12 @@
class CreateStacks < ActiveRecord::Migration[5.2]
def change
create_table :stacks do |t|
t.string :name, null: false
t.string :identifier, null: false

t.timestamps
end

add_index :stacks, :identifier
end
end
10 changes: 10 additions & 0 deletions db/migrate/20180723173209_create_stack_skills.rb
@@ -0,0 +1,10 @@
class CreateStackSkills < ActiveRecord::Migration[5.2]
def change
create_table :stack_skills do |t|
t.references :stack, foreign_key: true
t.references :skill, foreign_key: true

t.timestamps
end
end
end
31 changes: 30 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_07_21_092152) do
ActiveRecord::Schema.define(version: 2018_07_23_173209) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -107,13 +107,40 @@
t.index ["slug"], name: "index_projects_on_slug"
end

create_table "roles", force: :cascade do |t|
t.string "name"
t.string "resource_type"
t.bigint "resource_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource_type_and_resource_id"
end

create_table "skills", force: :cascade do |t|
t.string "title", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "state"
end

create_table "stack_skills", force: :cascade do |t|
t.bigint "stack_id"
t.bigint "skill_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["skill_id"], name: "index_stack_skills_on_skill_id"
t.index ["stack_id"], name: "index_stack_skills_on_stack_id"
end

create_table "stacks", force: :cascade do |t|
t.string "name", null: false
t.string "identifier", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["identifier"], name: "index_stacks_on_identifier"
end

create_table "user_skills", force: :cascade do |t|
t.boolean "primary", default: false
t.bigint "skill_id"
Expand Down Expand Up @@ -159,6 +186,8 @@
t.index ["user_id"], name: "index_votes_on_user_id"
end

add_foreign_key "stack_skills", "skills"
add_foreign_key "stack_skills", "stacks"
add_foreign_key "user_skills", "skills"
add_foreign_key "user_skills", "users"
end
5 changes: 5 additions & 0 deletions db/seeds.rb
Expand Up @@ -35,3 +35,8 @@
user.add_role Developer::Wizard::ProfileForm::ROLES.sample
UserSkill.create!(user: user, skill: Skill.all.sample, primary: true)
end

stack = Stack.create!(name: 'Rails monolith', identifier: 'rails_monolith')
Skill.where(title: %w[Ruby Front-end]).each do |skill|
stack.skills << skill
end
8 changes: 8 additions & 0 deletions spec/factories/stack_skills.rb
@@ -0,0 +1,8 @@
# frozen_string_literal: true

FactoryBot.define do
factory :stack_skill do
skill { create(:skill) }
stack { create(:stack) }
end
end
8 changes: 8 additions & 0 deletions spec/factories/stacks.rb
@@ -0,0 +1,8 @@
# frozen_string_literal: true

FactoryBot.define do
factory :stack do
name { Faker::App.author }
identifier { Faker::App.name }
end
end
10 changes: 10 additions & 0 deletions spec/models/stack_skill_spec.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe StackSkill, type: :model do
describe 'relations' do
it { is_expected.to belong_to :skill }
it { is_expected.to belong_to :stack }
end
end
18 changes: 18 additions & 0 deletions spec/models/stack_spec.rb
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Stack, type: :model do
subject(:stack) { create(:stack) }

describe 'validations' do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :identifier }
it { is_expected.to validate_uniqueness_of :identifier }
end

describe 'relations' do
it { is_expected.to have_many :skills }
it { is_expected.to have_many :stack_skills }
end
end

0 comments on commit cf97a6b

Please sign in to comment.