]> git.openstreetmap.org Git - rails.git/blob - test/models/redaction_test.rb
Merge remote-tracking branch 'upstream/pull/4753'
[rails.git] / test / models / redaction_test.rb
1 require "test_helper"
2
3 class RedactionTest < ActiveSupport::TestCase
4   def test_cannot_redact_current
5     n = create(:node)
6     r = create(:redaction)
7     assert_not_predicate(n, :redacted?, "Expected node to not be redacted already.")
8     assert_raise(OSM::APICannotRedactError) do
9       n.redact!(r)
10     end
11   end
12
13   def test_cannot_redact_current_via_old
14     node = create(:node, :with_history)
15     node_v1 = node.old_nodes.find_by(:version => 1)
16     r = create(:redaction)
17     assert_not_predicate(node_v1, :redacted?, "Expected node to not be redacted already.")
18     assert_raise(OSM::APICannotRedactError) do
19       node_v1.redact!(r)
20     end
21   end
22
23   def test_can_redact_old
24     node = create(:node, :with_history, :version => 2)
25     node_v1 = node.old_nodes.find_by(:version => 1)
26     node_v2 = node.old_nodes.find_by(:version => 2)
27     r = create(:redaction)
28
29     assert_not_predicate(node_v1, :redacted?, "Expected node to not be redacted already.")
30     assert_nothing_raised do
31       node_v1.redact!(r)
32     end
33     assert_predicate(node_v1, :redacted?, "Expected node version 1 to be redacted after redact! call.")
34     assert_not_predicate(node_v2, :redacted?, "Expected node version 2 to not be redacted after redact! call.")
35   end
36
37   def test_invalid_with_empty_title
38     redaction = build(:redaction, :title => "")
39     assert_not redaction.valid?
40     assert_includes redaction.errors.messages[:title], "can't be blank"
41   end
42
43   def test_invalid_with_empty_description
44     redaction = build(:redaction, :description => "")
45     assert_not redaction.valid?
46     assert_includes redaction.errors.messages[:description], "can't be blank"
47   end
48 end