Skip to content

Commit

Permalink
Merge pull request #2170 from MushroomObserver/jdc-update-preferred-l…
Browse files Browse the repository at this point in the history
…icenses

Update Licenses defaults
  • Loading branch information
JoeCohen committed Jun 11, 2024
2 parents 310c503 + 2ac23b2 commit bd4e528
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/models/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class License < AbstractModel
before_destroy :prevent_destruction_of_license_in_use

# Use this license if all else equal.
# It is currently hard-coded in the schema as Licenses default `license_id`
# It is hard-coded in the schema as Users default `license_id`
def self.preferred
License.find(Image.column_defaults["license_id"])
License.find(User.column_defaults["license_id"])
end

def preferred?
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240608213317_update_preferred_licenses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class UpdatePreferredLicenses < ActiveRecord::Migration[7.1]
def change
change_column_default(:images, :license_id, from: 1, to: 10)
change_column_default(:users, :license_id, from: 3, to: 10)
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_06_04_193245) do
ActiveRecord::Schema[7.1].define(version: 2024_06_08_213317) do
create_table "api_keys", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.datetime "created_at", precision: nil
t.datetime "last_used", precision: nil
Expand Down Expand Up @@ -178,7 +178,7 @@
t.date "when"
t.text "notes"
t.string "copyright_holder", limit: 100
t.integer "license_id", default: 1, null: false
t.integer "license_id", default: 10, null: false
t.integer "num_views", default: 0, null: false
t.datetime "last_view", precision: nil
t.integer "width"
Expand Down Expand Up @@ -821,7 +821,7 @@
t.datetime "created_at", precision: nil
t.datetime "last_login", precision: nil
t.datetime "verified", precision: nil
t.integer "license_id", default: 3, null: false
t.integer "license_id", default: 10, null: false
t.integer "contribution", default: 0
t.integer "location_id"
t.integer "image_id"
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
# See http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

ccnc25:
# Do not autogenerate id
# This is the default license for images.
# That id is defined and hard-coded in the schema, in the image table.
# So unless it's also hand-coded as a license fixture id, images are
# instantiated with the incorrect license.id.
id: 1
display_name: Creative Commons Non-commercial v2.5
url: https://creativecommons.org/licenses/by-nc-sa/2.5/
deprecated: true
Expand All @@ -21,6 +15,12 @@ ccnc30:
deprecated: false

ccwiki30:
# Do not autogenerate id
# This is the stand-in for the default license for Users and for Images.
# The id is defined and hard-coded in the schema, in the users table.
# So unless it's also hand-coded as a license fixture id, Users amd Images are
# instantiated with the wrong preferred license.id.
id: <%= User.column_defaults["license_id"] %>
display_name: Creative Commons Wikipedia Compatible v3.0
url: https://creativecommons.org/licenses/by-sa/3.0/
deprecated: false
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ DEFAULTS: &DEFAULTS
rolf:
<<: *DEFAULTS
name: Rolf Singer
license: ccwiki30
# The default license for Users.
# It is hard-coded in the schema, and in licenses.yml.
# So `license: ccwiki30` will not work here.
license_id: <%= User.column_defaults["license_id"] %>
image: rolf_profile_image
image_size: <%= User.image_sizes[:medium] %>
view_owner_id: true
Expand Down
8 changes: 4 additions & 4 deletions test/models/license_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def test_license_badge_url
end

def test_preferred
license = licenses(:ccnc25)
assert(license.preferred?)
preferred_license = License.preferred
assert(preferred_license.preferred?)

License.where.not(id: license.id).find_each do |lic|
assert_not(lic.preferred?)
License.where.not(id: preferred_license.id).find_each do |lic|
assert_not(lic.preferred?, "There should be only one preferred license.")
end
end

Expand Down

0 comments on commit bd4e528

Please sign in to comment.