Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #338 from howtohireme/196-stack-model
(#196) add stack model and data migration
- Loading branch information
Showing
15 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
DataMigrate::Data.define(version: 20180707131445) | ||
DataMigrate::Data.define(version: 20180723180541) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :stack_skill do | ||
skill { create(:skill) } | ||
stack { create(:stack) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :stack do | ||
name { Faker::App.author } | ||
identifier { Faker::App.name } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |