Commit da7ad5f6 authored by hellekin's avatar hellekin

Update Taxonomy/Category/Section specs

Fix resource sections count

Add missing resource_section spec
parent 1b7079e0
......@@ -2,19 +2,17 @@
class Api::V0::CategoriesController < ApplicationController
def index
@categories = Category.all
@categories = policy_scope(Category)
render jsonapi: @categories,
fields: params[:fields],
include: include_from_params
rescue INCOMMON::API::UnknownRelationshipError => e
render_jsonapi_error_unknown_relationship(e.message, model_types)
end
def show
@category = Category.find(params[:id])
@category = policy_scope(Category).find(params[:id])
render jsonapi: @category,
fields: params[:fields],
include: include_from_params
rescue INCOMMON::API::UnknownRelationshipError => e
render_jsonapi_error_unknown_relationship(e.message, model_types)
end
private
......
......@@ -17,6 +17,12 @@ class Category < ApplicationRecord
presence: true,
uniqueness: { scope: :taxonomy_id },
length: 3..64
class << self
def policy_class
TaxonomyPolicy
end
end
end
# == Schema Information
......
......@@ -21,20 +21,26 @@ class Section < ApplicationRecord
validates :name,
uniqueness: { scope: :category_id },
length: 3..64
class << self
def policy_class
TaxonomyPolicy
end
end
end
# == Schema Information
#
# Table name: sections
#
# id :bigint(8) not null, primary key
# color :string(25)
# rank :integer
# resources_count :integer default(0)
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint(8)
# id :bigint(8) not null, primary key
# color :string(25)
# rank :integer
# resource_sections_count :integer default(0)
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint(8)
#
# Indexes
#
......
......@@ -12,8 +12,6 @@ class SerializableCategory < JSONAPI::Serializable::Resource
attribute :created_at
attribute :updated_at
meta locale: I18n.locale
belongs_to :taxonomy
has_many :sections do
meta count: @object.sections_count
......@@ -22,4 +20,8 @@ class SerializableCategory < JSONAPI::Serializable::Resource
link :self do
@url_helpers.api_category_url(@object)
end
meta do
meta_current
end
end
......@@ -11,8 +11,6 @@ class SerializableSection < JSONAPI::Serializable::Resource
attribute :created_at
attribute :updated_at
meta locale: I18n.locale
belongs_to :category
has_many :resources do
meta count: @object.resources_count
......@@ -21,4 +19,8 @@ class SerializableSection < JSONAPI::Serializable::Resource
link :self do
@url_helpers.api_section_url(@object)
end
meta do
meta_current
end
end
......@@ -22,4 +22,8 @@ class SerializableTaxonomy < JSONAPI::Serializable::Resource
link :self do
@url_helpers.api_taxonomy_url(@object)
end
meta do
meta_current
end
end
class FixResourcesCountOnSections < ActiveRecord::Migration[5.2]
def change
change_table :sections do |t|
t.rename :resources_count, :resource_sections_count
end
end
end
......@@ -643,7 +643,7 @@ CREATE TABLE public.sections (
updated_at timestamp without time zone NOT NULL,
rank integer,
translations json DEFAULT '{}'::json,
resources_count integer DEFAULT 0
resource_sections_count integer DEFAULT 0
);
......@@ -1521,6 +1521,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20181106094615'),
('20181106153013'),
('20181209023655'),
('20181209191924');
('20181209191924'),
('20181220123425');
......@@ -9,46 +9,46 @@ if Rails.env.development?
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults(
'routes' => 'false',
'position_in_routes' => 'after',
'position_in_class' => 'after',
'position_in_test' => 'after',
'position_in_fixture' => 'after',
'position_in_factory' => 'after',
'position_in_serializer' => 'after',
'show_foreign_keys' => 'true',
'routes' => 'false',
'position_in_routes' => 'after',
'position_in_class' => 'after',
'position_in_test' => 'after',
'position_in_fixture' => 'after',
'position_in_factory' => 'after',
'position_in_serializer' => 'after',
'show_foreign_keys' => 'true',
'show_complete_foreign_keys' => 'false',
'show_indexes' => 'true',
'simple_indexes' => 'false',
'model_dir' => 'app/models',
'root_dir' => '',
'include_version' => 'false',
'require' => '',
'exclude_tests' => 'false',
'exclude_fixtures' => 'false',
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'true',
'exclude_controllers' => 'true',
'exclude_helpers' => 'true',
'exclude_sti_subclasses' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_routes' => nil,
'ignore_unknown_models' => 'false',
'hide_limit_column_types' => 'integer,boolean',
'show_indexes' => 'true',
'simple_indexes' => 'false',
'model_dir' => 'app/models',
'root_dir' => '',
'include_version' => 'false',
'require' => '',
'exclude_tests' => 'false',
'exclude_fixtures' => 'false',
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'true',
'exclude_controllers' => 'true',
'exclude_helpers' => 'true',
'exclude_sti_subclasses' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_routes' => nil,
'ignore_unknown_models' => 'false',
'hide_limit_column_types' => 'integer,boolean',
'hide_default_column_types' => 'json,jsonb,hstore',
'skip_on_db_migrate' => 'true',
'format_bare' => 'true',
'format_rdoc' => 'false',
'format_markdown' => 'false',
'sort' => 'false',
'force' => 'false',
'classified_sort' => 'true',
'trace' => 'false',
'wrapper_open' => nil,
'wrapper_close' => nil,
'with_comment' => true
'skip_on_db_migrate' => 'true',
'format_bare' => 'true',
'format_rdoc' => 'false',
'format_markdown' => 'false',
'sort' => 'false',
'force' => 'false',
'classified_sort' => 'true',
'trace' => 'false',
'wrapper_open' => nil,
'wrapper_close' => nil,
'with_comment' => true
)
end
......
Fabricator(:resource_section) do
id 1
resource
section
end
# == Schema Information
#
# Table name: resource_sections
#
# id :bigint(8) not null, primary key
# resource_type :string
# resource_id :bigint(8)
# section_id :bigint(8)
#
# Indexes
#
# index_resource_sections_on_resource_type_and_resource_id (resource_type,resource_id)
# index_resource_sections_on_section_id (section_id)
#
# Foreign Keys
#
# fk_rails_... (section_id => sections.id)
#
......@@ -10,14 +10,14 @@ end
#
# Table name: sections
#
# id :bigint(8) not null, primary key
# color :string(25)
# rank :integer
# resources_count :integer default(0)
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint(8)
# id :bigint(8) not null, primary key
# color :string(25)
# rank :integer
# resource_sections_count :integer default(0)
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint(8)
#
# Indexes
#
......
require 'rails_helper'
RSpec.describe ResourceSection, type: :model do
let(:rsec) { Fabricate(:resource_section) }
describe 'factory' do
it 'exists and is valid' do
expect(rsec).to be_valid
end
end
end
# == Schema Information
#
# Table name: resource_sections
#
# id :bigint(8) not null, primary key
# resource_type :string
# resource_id :bigint(8)
# section_id :bigint(8)
#
# Indexes
#
# index_resource_sections_on_resource_type_and_resource_id (resource_type,resource_id)
# index_resource_sections_on_section_id (section_id)
#
# Foreign Keys
#
# fk_rails_... (section_id => sections.id)
#
......@@ -8,14 +8,14 @@ end
#
# Table name: sections
#
# id :bigint(8) not null, primary key
# color :string(25)
# rank :integer
# resources_count :integer default(0)
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint(8)
# id :bigint(8) not null, primary key
# color :string(25)
# rank :integer
# resource_sections_count :integer default(0)
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint(8)
#
# Indexes
#
......
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