diff --git a/app/models/license.rb b/app/models/license.rb new file mode 100644 index 00000000..46345a16 --- /dev/null +++ b/app/models/license.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class License < ApplicationRecord + validates :code, presence: true + validates :label, presence: true +end diff --git a/db/migrate/20240208220722_create_licenses.rb b/db/migrate/20240208220722_create_licenses.rb new file mode 100644 index 00000000..a9293ba1 --- /dev/null +++ b/db/migrate/20240208220722_create_licenses.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class CreateLicenses < ActiveRecord::Migration[7.1] + def change + create_table :licenses do |t| + t.string :code, null: false + t.text :source, null: true + t.text :label, null: false + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a289ab51..9b3a6d8a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_01_10_214125) do +ActiveRecord::Schema[7.1].define(version: 2024_02_08_220722) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -93,6 +93,14 @@ t.index ["email"], name: "index_interests_on_email", unique: true end + create_table "licenses", force: :cascade do |t| + t.string "code", null: false + t.text "source" + t.text "label", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "password_reset_tokens", force: :cascade do |t| t.bigint "user_id", null: false t.index ["user_id"], name: "index_password_reset_tokens_on_user_id" diff --git a/db/seeds.rb b/db/seeds.rb index 8ba6c633..3d684c1d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,19 @@ # frozen_string_literal: true load(Rails.root.join('db/seeds/development.rb')) if Rails.env.development? + +License.create!([ + { code: 'all_rights_reserved', source: nil, label: 'All Rights Reserved' }, + { code: 'by', source: 'https://creativecommons.org/licenses/by/4.0/', label: 'Attribution' }, + { code: 'by_sa', source: 'https://creativecommons.org/licenses/by-sa/4.0/', + label: 'Attribution-ShareAlike 4.0 International' }, + { code: 'by_nc', source: 'https://creativecommons.org/licenses/by-nc/4.0/', + label: 'Attribution-NonCommercial' }, + { code: 'by_nc_sa', source: 'https://creativecommons.org/licenses/by-nc-sa/4.0/', + label: 'Attribution-NonCommercial-ShareAlike' }, + { code: 'by_nd', source: 'https://creativecommons.org/licenses/by-nd/4.0/', + label: 'Attribution-NoDerivs' }, + { code: 'by_nc_nd', source: 'https://creativecommons.org/licenses/by-nc-nd/4.0/', + label: 'Attribution-NonCommercial-NoDerivs' }, + { code: 'cc_0', source: 'https://creativecommons.org/publicdomain/zero/1.0/', label: 'No Copyright' } +]) diff --git a/test/factories/license.rb b/test/factories/license.rb new file mode 100644 index 00000000..a01cccbb --- /dev/null +++ b/test/factories/license.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :license do + code { 'by' } + label { 'Attribution' } + end +end diff --git a/test/models/license_test.rb b/test/models/license_test.rb new file mode 100644 index 00000000..d7e2f85c --- /dev/null +++ b/test/models/license_test.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'test_helper' + +class LicenseTest < ActiveSupport::TestCase + include ActiveJob::TestHelper + + test 'fixture is valid' do + assert build(:license).valid? + end + + test 'is not valid if requires attribuets are misising' do + license = License.new + + assert_not license.valid? + assert_includes license.errors[:code], "can't be blank" + assert_includes license.errors[:label], "can't be blank" + end +end