Skip to content

Commit

Permalink
Changed validation of name to filename (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
brand-it authored Oct 9, 2024
1 parent bc5c6c9 commit 744ad3e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 15 deletions.
6 changes: 4 additions & 2 deletions app/models/disk_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# angle :integer
# description :string
# duration :integer
# filename :string
# name :string not null
# filename :string not null
# name :string
# ripped_at :datetime
# size :integer default(0), not null
# created_at :datetime not null
Expand Down Expand Up @@ -41,6 +41,8 @@ class DiskTitle < ApplicationRecord
scope :not_ripped, -> { where(ripped_at: nil) }
scope :ripped, -> { where.not(ripped_at: nil) }

validates :filename, presence: true

def duration
super&.seconds
end
Expand Down
1 change: 1 addition & 0 deletions app/services/create_disks_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def disk_info(disk)
def find_or_build_disk_title(disk, title)
disk.disk_titles.find do |disk_title|
disk_title.title_id == title.id &&
title.name == disk_title.name &&
title.filename == disk_title.filename &&
title.bytes == disk_title.size &&
title.duration_seconds == disk_title.duration &&
Expand Down
2 changes: 1 addition & 1 deletion app/services/create_mkv_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def call
private

def rename_file
File.rename(tmp_dir.join(disk_title.name), video_blob.tmp_plex_path)
File.rename(tmp_dir.join(disk_title.filename), video_blob.tmp_plex_path)
end

def byte_size
Expand Down
4 changes: 2 additions & 2 deletions app/services/movie_disk_title_selector_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def featured_file_disk_title
end

def ripped?(disk_title)
movie.ripped_disk_titles.any? { _1.name == disk_title.name }
movie.ripped_disk_titles.any? { _1.filename == disk_title.filename }
end

def uploaded?(disk_title)
movie.ripped_disk_titles.find { _1.name == disk_title.name }&.video_blob&.uploaded? || false
movie.ripped_disk_titles.find { _1.filename == disk_title.filename }&.video_blob&.uploaded? || false
end

def within_range?(disk_title)
Expand Down
2 changes: 1 addition & 1 deletion app/views/disk_titles/_disk_title.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<tr>
<th scope="row" class="<%= text_class %>"><%= disk_title.id %></th>
<td class="<%= text_class %>"><%= disk_title.name %></td>
<td class="<%= text_class %>"><%= disk_title.filename %></td>
<td class="<%= text_class %>"><%= distance_of_time_in_words(disk_title.duration.seconds) %></td>
<td class="<%= disk_title.size >= free_disk_space ? 'text-danger' : text_class %>">
<%= number_to_human_size(disk_title.size, precision: 3) %>
Expand Down
2 changes: 1 addition & 1 deletion current_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5.3.0
v5.3.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class RemoveNameValidationOnDiskTitle < ActiveRecord::Migration[7.2]
def change
DiskTitle.destroy_all

change_column_null :disk_titles, :name, true
change_column_null :disk_titles, :filename, false
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.2].define(version: 2024_10_08_200453) do
ActiveRecord::Schema[7.2].define(version: 2024_10_09_012227) do
create_table "configs", force: :cascade do |t|
t.string "type", default: "Config", null: false
t.text "settings"
Expand All @@ -19,7 +19,7 @@
end

create_table "disk_titles", force: :cascade do |t|
t.string "name", null: false
t.string "name"
t.integer "duration"
t.integer "title_id", null: false
t.integer "size", default: 0, null: false
Expand All @@ -32,7 +32,7 @@
t.datetime "ripped_at"
t.integer "video_blob_id"
t.integer "angle"
t.string "filename"
t.string "filename", null: false
t.string "description"
t.index ["disk_id"], name: "index_disk_titles_on_disk_id"
t.index ["episode_id"], name: "index_disk_titles_on_episode_id"
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/disk_titles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# angle :integer
# description :string
# duration :integer
# filename :string
# name :string not null
# filename :string not null
# name :string
# ripped_at :datetime
# size :integer default(0), not null
# created_at :datetime not null
Expand All @@ -31,7 +31,7 @@
#
FactoryBot.define do
factory :disk_title do
name { 'title_mk1.mkv' } # don't rename required for spec/bin/makemkvcon_test
filename { 'title_mk1.mkv' } # don't rename required for spec/bin/makemkvcon_test
title_id { Faker::Types.rb_integer }
disk
video
Expand Down
8 changes: 6 additions & 2 deletions spec/models/disk_title_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# angle :integer
# description :string
# duration :integer
# filename :string
# name :string not null
# filename :string not null
# name :string
# ripped_at :datetime
# size :integer default(0), not null
# created_at :datetime not null
Expand Down Expand Up @@ -44,6 +44,10 @@
it { is_expected.to have_scope(:ripped).where.not(ripped_at: nil) }
end

describe 'validations' do
it { is_expected.to validate_presence_of(:filename) }
end

describe '#to_label' do
let(:disk_title) { create(:disk_title, title_id: 1, name: 'Sample Title', duration: 3600) }

Expand Down

0 comments on commit 744ad3e

Please sign in to comment.