From 42024fc2434a31fd1300971612c61295e8cc84ec Mon Sep 17 00:00:00 2001 From: Ross Chapman Date: Thu, 8 Feb 2024 14:24:58 -0800 Subject: [PATCH 1/4] Adds license model --- app/models/license.rb | 6 ++++++ db/migrate/20240208220722_create_licenses.rb | 12 ++++++++++++ db/schema.rb | 10 +++++++++- test/factories/license.rb | 8 ++++++++ test/models/license_test.rb | 18 ++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/models/license.rb create mode 100644 db/migrate/20240208220722_create_licenses.rb create mode 100644 test/factories/license.rb create mode 100644 test/models/license_test.rb 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/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..acf9ab85 --- /dev/null +++ b/test/models/license_test.rb @@ -0,0 +1,18 @@ +# 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 code is not present' do + license = License.new + + assert_not license.valid? + assert_includes license.errors[:code], 'file cannot be missing' + end +end From c34bc718fc16fb1a902141af24a20750977fe185 Mon Sep 17 00:00:00 2001 From: Ross Chapman Date: Thu, 8 Feb 2024 14:37:05 -0800 Subject: [PATCH 2/4] Updates spec --- Gemfile.lock | 5 +++++ test/models/license_test.rb | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4750060e..5d02ad0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -209,6 +209,8 @@ GEM nio4r (2.7.0) nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) + nokogiri (1.16.0-x86_64-darwin) + racc (~> 1.4) nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) parallel (1.24.0) @@ -340,6 +342,8 @@ GEM stripe (10.5.0) tailwindcss-rails (2.0.32-arm64-darwin) railties (>= 6.0.0) + tailwindcss-rails (2.0.32-x86_64-darwin) + railties (>= 6.0.0) tailwindcss-rails (2.0.32-x86_64-linux) railties (>= 6.0.0) thor (1.3.0) @@ -363,6 +367,7 @@ GEM PLATFORMS arm64-darwin-22 + x86_64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/test/models/license_test.rb b/test/models/license_test.rb index acf9ab85..d7e2f85c 100644 --- a/test/models/license_test.rb +++ b/test/models/license_test.rb @@ -9,10 +9,11 @@ class LicenseTest < ActiveSupport::TestCase assert build(:license).valid? end - test 'is not valid if code is not present' do + test 'is not valid if requires attribuets are misising' do license = License.new assert_not license.valid? - assert_includes license.errors[:code], 'file cannot be missing' + assert_includes license.errors[:code], "can't be blank" + assert_includes license.errors[:label], "can't be blank" end end From abf50440c18f9f488d5aa701e4e1b73d2b31a0d4 Mon Sep 17 00:00:00 2001 From: Ross Chapman Date: Fri, 16 Feb 2024 19:26:56 -0800 Subject: [PATCH 3/4] Adds new data to seed --- db/seeds.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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' } +]) From d4ad208397df1f08a105a6b5e3e517bc84d45004 Mon Sep 17 00:00:00 2001 From: Ross Chapman Date: Fri, 16 Feb 2024 19:30:31 -0800 Subject: [PATCH 4/4] Resets gemfile lock --- Gemfile.lock | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5d02ad0f..4750060e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -209,8 +209,6 @@ GEM nio4r (2.7.0) nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.0-x86_64-darwin) - racc (~> 1.4) nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) parallel (1.24.0) @@ -342,8 +340,6 @@ GEM stripe (10.5.0) tailwindcss-rails (2.0.32-arm64-darwin) railties (>= 6.0.0) - tailwindcss-rails (2.0.32-x86_64-darwin) - railties (>= 6.0.0) tailwindcss-rails (2.0.32-x86_64-linux) railties (>= 6.0.0) thor (1.3.0) @@ -367,7 +363,6 @@ GEM PLATFORMS arm64-darwin-22 - x86_64-darwin-22 x86_64-linux DEPENDENCIES