Compare commits

...

3 Commits

Author SHA1 Message Date
Angel Aviel Domaoan e16c3b4308 Remove document in doctrines 4 years ago
Angel Aviel Domaoan aeac325b2b Remove test directory 4 years ago
Angel Aviel Domaoan 5704d93544 Implement DoctrineJurisprudence 4 years ago
  1. 40
      app/controllers/api/jurisprudence/doctrines_controller.rb
  2. 2
      app/controllers/doctrines_controller.rb
  3. 52
      app/controllers/jurisprudence/doctrines_controller.rb
  4. 3
      app/models/cdao/jurisprudence.rb
  5. 3
      app/models/doctrine.rb
  6. 6
      app/models/doctrine_jurisprudence.rb
  7. 8
      config/routes.rb
  8. 15
      db/migrate/20220215021520_create_doctrine_jurisprudences.rb
  9. 6
      db/migrate/20220215025319_remove_document_type_and_document_id_in_doctrines.rb
  10. 7
      db/seeds.rb
  11. 5
      test/application_system_test_case.rb
  12. 11
      test/channels/application_cable/connection_test.rb
  13. 0
      test/controllers/.keep
  14. 0
      test/fixtures/files/.keep
  15. 0
      test/helpers/.keep
  16. 0
      test/integration/.keep
  17. 0
      test/mailers/.keep
  18. 0
      test/models/.keep
  19. 0
      test/system/.keep
  20. 13
      test/test_helper.rb

40
app/controllers/api/jurisprudence/doctrines_controller.rb

@ -11,46 +11,6 @@ module Api
def show def show
respond_with @doctrine respond_with @doctrine
end end
def create
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
subject_ids = attrs.delete(:subject_ids)
@doctrine = @jurisprudence.doctrines.new(attrs)
if @doctrine.save
@doctrine.subject_ids = subject_ids if subject_ids.present?
respond_with @doctrine
else
render errors: @doctrine.errors, status: 422
end
end
def update
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
subject_ids = attrs.delete(:subject_ids)
if @doctrine.update(attrs)
@doctrine.subject_ids = subject_ids if subject_ids.present?
respond_with @doctrine
else
render errors: @doctrine.errors, status: 422
end
end
def destroy
@doctrine.destroy
respond_with @doctrine
end
private
def resource_params
params.permit(:content, subject_ids: [])
end
end end
end end
end end

2
app/controllers/doctrines_controller.rb

@ -26,6 +26,6 @@ class DoctrinesController < ApplicationController
private private
def search_params def search_params
params.permit(subject_ids: []) params.permit(jurisprudence_ids: [], subject_ids: [])
end end
end end

52
app/controllers/jurisprudence/doctrines_controller.rb

@ -1,52 +0,0 @@
class Jurisprudence::DoctrinesController < ApplicationController
load_and_authorize_resource :jurisprudence, class: "Cdao::Jurisprudence"
load_and_authorize_resource :doctrine, class: "Doctrine", through: :jurisprudence
def create
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
subject_ids = attrs.delete(:subject_ids)
@doctrine = @jurisprudence.doctrines.new(attrs)
respond_to do |format|
if @doctrine.save
@doctrine.subject_ids = subject_ids if subject_ids.present?
format.html { redirect_to document_doctrine_path(@jurisprudence, @doctrine), notice: "Doctrine was successfully created." }
else
format.html { redirect_to document_doctrine_path(@jurisprudence) }
end
end
end
def update
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
subject_ids = attrs.delete(:subject_ids)
respond_to do |format|
if @doctrine.update(attrs)
@doctrine.subject_ids = subject_ids if subject_ids.present?
format.html { redirect_to document_doctrine_path(@jurisprudence, @doctrine), notice: "Doctrine was successfully updated." }
else
format.html { redirect_to document_doctrine_path(@jurisprudence) }
end
end
end
def destroy
respond_to do |format|
if @doctrine.destroy
format.html { redirect_to document_path(@jurisprudence), notice: "Doctrine was successfully destroyed." }
else
format.html { redirect_to document_path(@jurisprudence), alert: @doctrine.errors.full_messages }
end
end
end
private
def resource_params
params.permit(:content, subject_ids: [])
end
end

3
app/models/cdao/jurisprudence.rb

@ -3,7 +3,8 @@ class Cdao::Jurisprudence < Cdao::Base
has_many :annotations, as: :document, dependent: :restrict_with_error has_many :annotations, as: :document, dependent: :restrict_with_error
has_many :doctrines, as: :document, dependent: :restrict_with_error has_many :doctrine_jurisprudences, dependent: :destroy
has_many :doctrines, through: :doctrine_jurisprudences
has_many :annotation_documents, as: :document, dependent: :restrict_with_error has_many :annotation_documents, as: :document, dependent: :restrict_with_error
has_many :annotations_as_cited, through: :annotation_documents, source: :annotation has_many :annotations_as_cited, through: :annotation_documents, source: :annotation

3
app/models/doctrine.rb

@ -1,5 +1,6 @@
class Doctrine < ApplicationRecord class Doctrine < ApplicationRecord
belongs_to :document, polymorphic: true, optional: false has_many :doctrine_jurisprudences, dependent: :destroy
has_many :jurisprudences, through: :doctrine_jurisprudences
has_many :doctrine_subjects, dependent: :destroy has_many :doctrine_subjects, dependent: :destroy
has_many :subjects, through: :doctrine_subjects has_many :subjects, through: :doctrine_subjects

6
app/models/doctrine_jurisprudence.rb

@ -0,0 +1,6 @@
class DoctrineJurisprudence < ApplicationRecord
acts_as_list column: :rank, scope: %i[doctrine_id]
belongs_to :doctrine, optional: false
belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false
end

8
config/routes.rb

@ -10,12 +10,6 @@ Rails.application.routes.draw do
end end
end end
resources :jurisprudences, only: [] do
scope module: :jurisprudence do
resources :doctrines, only: %i[create update destroy]
end
end
resources :documents, only: %i[index show] do resources :documents, only: %i[index show] do
get :search, on: :collection get :search, on: :collection
@ -48,7 +42,7 @@ Rails.application.routes.draw do
scope module: :jurisprudence do scope module: :jurisprudence do
resources :cited_ins, only: %i[index show] resources :cited_ins, only: %i[index show]
resources :cross_references, only: %i[index show] resources :cross_references, only: %i[index show]
resources :doctrines resources :doctrines, only: %i[index show]
end end
end end
end end

15
db/migrate/20220215021520_create_doctrine_jurisprudences.rb

@ -0,0 +1,15 @@
class CreateDoctrineJurisprudences < ActiveRecord::Migration[6.1]
def change
create_table :doctrine_jurisprudences do |t|
t.references :doctrine, null: false
t.references :jurisprudence, null: false
t.integer :rank, null: false, default: 1
t.timestamps
end
add_index :doctrine_jurisprudences, %i[doctrine_id jurisprudence_id],
name: "index_doctrine_jurisprudences_uniqueness",
unique: true
end
end

6
db/migrate/20220215025319_remove_document_type_and_document_id_in_doctrines.rb

@ -0,0 +1,6 @@
class RemoveDocumentTypeAndDocumentIdInDoctrines < ActiveRecord::Migration[6.1]
def up
remove_column :doctrines, :document_type, :string
remove_column :doctrines, :document_id, :integer
end
end

7
db/seeds.rb

@ -54,3 +54,10 @@ Cdao::Subject.find_each.with_index do |subject, index|
annotation_document.document = Cdao::Jurisprudence.last(index + 101).first annotation_document.document = Cdao::Jurisprudence.last(index + 101).first
annotation_document.save annotation_document.save
end end
Doctrine.find_each do |doctrine|
doc = doctrine.document
ids = doc.doctrine_ids
ids << doctrine.id
doc.doctrine_ids = ids.uniq
end

5
test/application_system_test_case.rb

@ -1,5 +0,0 @@
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end

11
test/channels/application_cable/connection_test.rb

@ -1,11 +0,0 @@
require "test_helper"
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
# test "connects with cookies" do
# cookies.signed[:user_id] = 42
#
# connect
#
# assert_equal connection.user_id, "42"
# end
end

0
test/controllers/.keep

0
test/fixtures/files/.keep vendored

0
test/helpers/.keep

0
test/integration/.keep

0
test/mailers/.keep

0
test/models/.keep

0
test/system/.keep

13
test/test_helper.rb

@ -1,13 +0,0 @@
ENV['RAILS_ENV'] ||= 'test'
require_relative "../config/environment"
require "rails/test_help"
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
Loading…
Cancel
Save