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 2 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
5 changes: 5 additions & 0 deletions Gemfile.lock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated during test run? Are y'all ok to check these in?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so - but ideally as a separate commit. I guess it's because you're using an intel mac?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh yeah.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -363,6 +367,7 @@ GEM

PLATFORMS
arm64-darwin-22
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
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.

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