Skip to content

Commit

Permalink
Add the Collection model
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 10, 2020
1 parent 715db4f commit 898c34a
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
@@ -1,11 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-09-24 04:28:12 UTC using RuboCop version 0.90.0.
# on 2020-10-09 20:36:14 UTC using RuboCop version 0.92.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 19
# Offense count: 20
Style/Documentation:
Enabled: false
2 changes: 1 addition & 1 deletion app/components/work_form_component.html.erb
@@ -1,7 +1,7 @@
<div id="editor">
<h1 class="row">Deposit your work</h1>

<%= form_with model: @work, data: { controller: 'progress' },
<%= form_with model: work, url: [work.collection, work], data: { controller: 'progress' },
html: { class: 'needs-validation row', novalidate: true, multipart: true } do |f| %>
<%= render DepositProgressComponent.new %>
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/works_controller.rb
Expand Up @@ -5,11 +5,13 @@ class WorksController < ApplicationController
layout 'editor'

def new
@work = Work.new(work_type: 'text')
@collection = Collection.find(params[:collection_id])
@work = Work.new(work_type: 'text', collection: @collection)
end

def create
@work = Work.new(work_params)
@collection = Collection.find(params[:collection_id])
@work = Work.new(work_params.merge(collection: @collection))
if @work.save
DepositJob.perform_later(@work) if params[:commit] == 'Deposit'
redirect_to @work
Expand Down
6 changes: 6 additions & 0 deletions app/models/collection.rb
@@ -0,0 +1,6 @@
# typed: false
# frozen_string_literal: true

# Models a collection in the database
class Collection < ApplicationRecord
end
2 changes: 2 additions & 0 deletions app/models/work.rb
Expand Up @@ -2,6 +2,8 @@
# frozen_string_literal: true

class Work < ApplicationRecord
belongs_to :collection

has_many :contributors, dependent: :destroy
has_many :related_links, dependent: :destroy
has_many :related_works, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/show.html.erb
Expand Up @@ -29,7 +29,7 @@
</p>

<div class="d-flex flex-column flex-md-row">
<%= link_to 'Start here', new_work_path, class: 'btn btn-primary btn-lg mb-3 mr-md-3' %>
<%= link_to 'Start here', new_collection_work_path(Collection.all.first), class: 'btn btn-primary btn-lg mb-3 mr-md-3' %>
</div>
<p class="text-muted mb-0">
Not ready to deposit? Learn more about the process. It's a few simple steps and often takes less than 10 minutes
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Expand Up @@ -8,7 +8,9 @@
root to: 'welcome#show'
resource 'welcome', only: 'show'

resources :works, only: %i[new create show]
resources :collections, only: [] do
resources :works, shallow: true, only: %i[new create show]
end

mount Sidekiq::Web => '/queues'
end
21 changes: 21 additions & 0 deletions db/migrate/20201009194116_create_collections.rb
@@ -0,0 +1,21 @@
class CreateCollections < ActiveRecord::Migration[6.0]
def change
create_table :collections do |t|
t.string :name, null: false
t.string :description, null: false
t.string :contact_email, null: false
t.string :release_option
t.string :release_duration
t.date :release_date
t.string :visibility, null: false
t.string :required_license
t.string :default_license
t.boolean :email_when_participants_changed
t.string :managers, null: false
t.string :depositors
t.string :reviewers

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20201009194443_add_collection_ref_to_works.rb
@@ -0,0 +1,5 @@
class AddCollectionRefToWorks < ActiveRecord::Migration[6.0]
def change
add_reference :works, :collection, null: false, foreign_key: true
end
end
23 changes: 22 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_10_09_042617) do
ActiveRecord::Schema.define(version: 2020_10_09_194443) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -37,6 +37,24 @@
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "collections", force: :cascade do |t|
t.string "name", null: false
t.string "description", null: false
t.string "contact_email", null: false
t.string "release_option"
t.string "release_duration"
t.date "release_date"
t.string "visibility", null: false
t.string "required_license"
t.string "default_license"
t.boolean "email_when_participants_changed"
t.string "managers", null: false
t.string "depositors"
t.string "reviewers"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "contributors", force: :cascade do |t|
t.bigint "work_id", null: false
t.string "first_name", null: false
Expand Down Expand Up @@ -88,6 +106,8 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "state", null: false
t.bigint "collection_id", null: false
t.index ["collection_id"], name: "index_works_on_collection_id"
t.index ["druid", "version"], name: "index_works_on_druid_and_version", unique: true
t.index ["state"], name: "index_works_on_state"
end
Expand All @@ -97,4 +117,5 @@
add_foreign_key "contributors", "works"
add_foreign_key "related_links", "works"
add_foreign_key "related_works", "works"
add_foreign_key "works", "collections"
end
3 changes: 3 additions & 0 deletions db/seeds.rb
Expand Up @@ -10,3 +10,6 @@
# Character.create(name: 'Luke', movie: movies.first)

RoleTerm.create([{ label: 'Author' }, { label: 'Contributor' }])

# Don't load this in production:
FactoryBot.create(:collection)
20 changes: 20 additions & 0 deletions spec/factories/collections.rb
@@ -0,0 +1,20 @@
# typed: false
# frozen_string_literal: true

FactoryBot.define do
factory :collection do
name { 'MyString' }
description { 'MyString' }
contact_email { 'MyString' }
release_option { 'MyString' }
release_duration { 'MyString' }
release_date { '2020-10-09' }
visibility { 'MyString' }
required_license { 'MyString' }
default_license { 'MyString' }
email_when_participants_changed { false }
managers { 'maya.aguirre, jcairns' }
reviewers { 'MyString' }
depositors { 'MyString' }
end
end
1 change: 1 addition & 0 deletions spec/factories/works.rb
Expand Up @@ -12,5 +12,6 @@
citation { 'test citation' }
access { 'stanford' }
license { 'cc-0' }
collection
end
end
10 changes: 10 additions & 0 deletions spec/models/collection_spec.rb
@@ -0,0 +1,10 @@
# typed: false
# frozen_string_literal: true

require 'rails_helper'

# rubocop:disable RSpec/EmptyExampleGroup
RSpec.describe Collection, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
# rubocop:enable RSpec/EmptyExampleGroup

0 comments on commit 898c34a

Please sign in to comment.