|
11 | 11 | require 'test_helper'
|
12 | 12 |
|
13 | 13 | class ContentLengthTest < ActiveSupport::TestCase
|
14 |
| - def setup |
15 |
| - # ContentLengths are automatically created when we create an AudioFile and CodecConversion. Manually creating one would result in an error due to uniqueness contraints. |
16 |
| - io = StringIO.new Rails.root.join('test/files/base.flac').read |
17 |
| - AudioFile.any_instance.stubs(:convert).returns(io) |
18 |
| - @audio_file = create(:audio_file) |
19 |
| - @codec_conversion = create(:codec_conversion) |
20 |
| - end |
21 |
| - |
22 |
| - test 'should not create new ContentLength if audio is longer than config and track is older than config' do |
23 |
| - @track = create(:track, audio_file: @audio_file) |
24 |
| - |
25 |
| - # rubocop:disable Rails/SkipsModelValidations |
26 |
| - # We want to avoid our own before_save callbacks to manually set audio_file length and track age |
27 |
| - @audio_file.update_column(:length, 1) |
28 |
| - @audio_file.track.update_column(:created_at, 1.year.ago) |
29 |
| - # rubocop:enable Rails/SkipsModelValidations |
30 |
| - |
31 |
| - assert_difference('ContentLength.count', -1) do |
32 |
| - ContentLength.destroy_all_and_recalculate |
33 |
| - end |
34 |
| - end |
35 |
| - |
36 |
| - test 'should create new ContentLength if audio is longer than config' do |
37 |
| - io = StringIO.new Rails.root.join('test/files/base.flac').read |
38 |
| - AudioFile.any_instance.stubs(:convert).returns(io) |
39 |
| - @track = create(:track, audio_file: @audio_file) |
40 |
| - |
41 |
| - # rubocop:disable Rails/SkipsModelValidations |
42 |
| - # We want to avoid our own before_save callbacks to manually set the audio_file length and track age |
43 |
| - @audio_file.update_column(:length, 1000) |
44 |
| - @audio_file.track.update_column(:created_at, 1.year.ago) |
45 |
| - # rubocop:enable Rails/SkipsModelValidations |
46 |
| - |
47 |
| - assert_difference('ContentLength.count', 0) do |
48 |
| - ContentLength.destroy_all_and_recalculate |
49 |
| - end |
50 |
| - end |
51 |
| - |
52 |
| - test 'should create new ContentLength if track is newer than config' do |
53 |
| - io = StringIO.new Rails.root.join('test/files/base.flac').read |
54 |
| - AudioFile.any_instance.stubs(:convert).returns(io) |
55 |
| - @track = create(:track, audio_file: @audio_file) |
56 |
| - |
57 |
| - # rubocop:disable Rails/SkipsModelValidations |
58 |
| - # We want to avoid our own before_save callbacks to manually set the audio_file length and track age |
59 |
| - @audio_file.update_column(:length, 1) |
60 |
| - @audio_file.track.update_column(:created_at, 1.day.ago) |
61 |
| - # rubocop:enable Rails/SkipsModelValidations |
62 |
| - |
63 |
| - assert_difference('ContentLength.count', 0) do |
64 |
| - ContentLength.destroy_all_and_recalculate |
65 |
| - end |
66 |
| - |
67 |
| - @audio_file.reload |
68 |
| - |
69 |
| - assert_equal 1, @audio_file.content_lengths.length |
70 |
| - end |
71 | 14 | end
|
0 commit comments