Skip to content

Commit

Permalink
exclude current when checking for later actions
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Jul 5, 2017
1 parent 3f7295e commit b079b73
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/downgrade_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ def assert_delete_is_last
end

def later_actions
DowngradeAction.where(archive_format_id: archive_format_id)
.where('months > ?', months)
scope = DowngradeAction.where(archive_format_id: archive_format_id)
.where('months > ?', months)
scope = scope.where('id <> ?', id) if persisted?
scope
end

end
26 changes: 26 additions & 0 deletions test/models/downgrade_action_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,30 @@ class DowngradeActionTest < ActiveSupport::TestCase
assert_not_valid action, :channels
end

test 'bitrate and channels must not be zero' do
af = archive_formats(:unimportant_mp3)
af.downgrade_actions.destroy_all
action = af.downgrade_actions.build(months: 24, bitrate: 0, channels: 2)
assert_not_valid action, :bitrate
action.bitrate = 160 # equal
action.channels = 0
assert_not_valid action, :channels
action.bitrate = nil
action.channels = nil
assert_valid action
end

test 'delete must be last' do
af = archive_formats(:important_mp3)
action = af.downgrade_actions.build(months: 6, bitrate: nil, channels: nil) # delete before others
assert_not_valid action, :base
action.months = 24
assert_valid action
action.save!
action.months = 18
assert_valid action
action.months = 8
assert_not_valid action, :base
end

end

0 comments on commit b079b73

Please sign in to comment.