Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a License model #167

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/license.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class License < ApplicationRecord
validates :code, presence: true
validates :label, presence: true
end
12 changes: 12 additions & 0 deletions db/migrate/20240208220722_create_licenses.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -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' }
])
8 changes: 8 additions & 0 deletions test/factories/license.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

FactoryBot.define do
factory :license do
code { 'by' }
label { 'Attribution' }
end
end
19 changes: 19 additions & 0 deletions test/models/license_test.rb
Original file line number Diff line number Diff line change
@@ -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