forked from brendon/positioning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_timestamps_item.rb
More file actions
31 lines (24 loc) · 1.1 KB
/
test_timestamps_item.rb
File metadata and controls
31 lines (24 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require "test_helper"
class TestTimestampsItem < Minitest::Test
include Minitest::Hooks
def around
ActiveRecord::Base.transaction do
super
raise ActiveRecord::Rollback
end
end
def test_updated_at_is_touched_when_other_items_are_repositioned
list = List.create name: "List"
first_item = list.timestamps_items.create name: "First Item"
second_item = list.timestamps_items.create name: "Second Item"
third_item = list.timestamps_items.create name: "Third Item"
before_updated_ats = list.timestamps_items.order(:id).pluck(:id, :updated_at).to_h
third_item.update! position: 1
after_updated_ats = list.timestamps_items.order(:id).pluck(:id, :updated_at).to_h
assert_equal [third_item.id, first_item.id, second_item.id],
list.timestamps_items.order(:position).pluck(:id)
assert_operator after_updated_ats[first_item.id], :>, before_updated_ats[first_item.id]
assert_operator after_updated_ats[second_item.id], :>, before_updated_ats[second_item.id]
assert_operator after_updated_ats[third_item.id], :>, before_updated_ats[third_item.id]
end
end