add Axis, Category and Subject
This commit is contained in:
18
spec/factories/axes.rb
Normal file
18
spec/factories/axes.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: axes
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_axes_on_name (name) UNIQUE
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :axis do
|
||||
name { Faker::Superhero.name }
|
||||
end
|
||||
end
|
||||
18
spec/factories/categories.rb
Normal file
18
spec/factories/categories.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: categories
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_categories_on_name (name) UNIQUE
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :category do
|
||||
name { Faker::Superhero.name }
|
||||
end
|
||||
end
|
||||
29
spec/factories/subjects.rb
Normal file
29
spec/factories/subjects.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: subjects
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# axis_id :bigint not null
|
||||
# category_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_subjects_on_axis_id (axis_id)
|
||||
# index_subjects_on_category_id (category_id)
|
||||
# index_subjects_on_name (name) UNIQUE
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (axis_id => axes.id)
|
||||
# fk_rails_... (category_id => categories.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :subject do
|
||||
name { Faker::Superhero.name }
|
||||
axis
|
||||
category
|
||||
end
|
||||
end
|
||||
27
spec/models/axis_spec.rb
Normal file
27
spec/models/axis_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: axes
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_axes_on_name (name) UNIQUE
|
||||
#
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe(Axis, type: :model) do
|
||||
describe "associations" do
|
||||
it { is_expected.to(have_many(:subjects)) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
subject { create :axis }
|
||||
|
||||
it { is_expected.to(validate_presence_of(:name)) }
|
||||
it { is_expected.to(validate_uniqueness_of(:name)) }
|
||||
end
|
||||
end
|
||||
25
spec/models/category_spec.rb
Normal file
25
spec/models/category_spec.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: categories
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_categories_on_name (name) UNIQUE
|
||||
#
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe(Category, type: :model) do
|
||||
describe "associations" do
|
||||
it { is_expected.to(have_many(:subjects)) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it { is_expected.to(validate_presence_of(:name)) }
|
||||
it { is_expected.to(validate_uniqueness_of(:name)) }
|
||||
end
|
||||
end
|
||||
38
spec/models/subject_spec.rb
Normal file
38
spec/models/subject_spec.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: subjects
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# axis_id :bigint not null
|
||||
# category_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_subjects_on_axis_id (axis_id)
|
||||
# index_subjects_on_category_id (category_id)
|
||||
# index_subjects_on_name (name) UNIQUE
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (axis_id => axes.id)
|
||||
# fk_rails_... (category_id => categories.id)
|
||||
#
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe(Subject, type: :model) do
|
||||
describe "associations" do
|
||||
it { is_expected.to(belong_to(:axis)) }
|
||||
it { is_expected.to(belong_to(:category)) }
|
||||
# it { is_expected.to(have_many(:questions)) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
subject { create :subject }
|
||||
|
||||
it { is_expected.to(validate_presence_of(:name)) }
|
||||
it { is_expected.to(validate_uniqueness_of(:name)) }
|
||||
end
|
||||
end
|
||||
@@ -39,26 +39,14 @@ RSpec.configure do |config|
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
# You can uncomment this line to turn off ActiveRecord support entirely.
|
||||
# config.use_active_record = false
|
||||
|
||||
# RSpec Rails can automatically mix in different behaviours to your tests
|
||||
# based on their file location, for example enabling you to call `get` and
|
||||
# `post` in specs under `spec/controllers`.
|
||||
#
|
||||
# You can disable this behaviour by removing the line below, and instead
|
||||
# explicitly tag your specs with their type, e.g.:
|
||||
#
|
||||
# RSpec.describe UsersController, type: :controller do
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
# The different available types are documented in the features, such as in
|
||||
# https://relishapp.com/rspec/rspec-rails/docs
|
||||
config.infer_spec_type_from_file_location!
|
||||
|
||||
# Filter lines from Rails gems in backtraces.
|
||||
config.filter_rails_from_backtrace!
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
config.include(FactoryBot::Syntax::Methods)
|
||||
end
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
config.integrate do |with|
|
||||
with.test_framework(:rspec)
|
||||
with.library(:rails)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user