From: Anton Khorev Date: Fri, 5 Jan 2024 09:34:27 +0000 (+0300) Subject: Add :closed trait to note factory X-Git-Tag: live~785^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/6272b041c6dd9c39cc7a23d6163651e74509da2b?hp=b154cefbf0a18d512c3768bf7de1505acab77341 Add :closed trait to note factory --- diff --git a/test/controllers/api/notes_controller_test.rb b/test/controllers/api/notes_controller_test.rb index 874ac3ccd..303bcea91 100644 --- a/test/controllers/api/notes_controller_test.rb +++ b/test/controllers/api/notes_controller_test.rb @@ -345,7 +345,7 @@ module Api end assert_response :gone - closed_note_with_comment = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) + closed_note_with_comment = create(:note_with_comments, :closed) assert_no_difference "NoteComment.count" do post comment_api_note_path(:id => closed_note_with_comment, :text => "This is an additional comment"), :headers => auth_header @@ -406,14 +406,14 @@ module Api post close_api_note_path(:id => hidden_note_with_comment), :headers => auth_header assert_response :gone - closed_note_with_comment = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) + closed_note_with_comment = create(:note_with_comments, :closed) post close_api_note_path(:id => closed_note_with_comment), :headers => auth_header assert_response :conflict end def test_reopen_success - closed_note_with_comment = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) + closed_note_with_comment = create(:note_with_comments, :closed) user = create(:user) post reopen_api_note_path(:id => closed_note_with_comment, :text => "This is a reopen comment", :format => "json") @@ -428,7 +428,7 @@ module Api assert_equal "Feature", js["type"] assert_equal closed_note_with_comment.id, js["properties"]["id"] assert_equal "open", js["properties"]["status"] - assert_equal 2, js["properties"]["comments"].count + assert_equal 3, js["properties"]["comments"].count assert_equal "reopened", js["properties"]["comments"].last["action"] assert_equal "This is a reopen comment", js["properties"]["comments"].last["text"] assert_equal user.display_name, js["properties"]["comments"].last["user"] @@ -440,7 +440,7 @@ module Api assert_equal "Feature", js["type"] assert_equal closed_note_with_comment.id, js["properties"]["id"] assert_equal "open", js["properties"]["status"] - assert_equal 2, js["properties"]["comments"].count + assert_equal 3, js["properties"]["comments"].count assert_equal "reopened", js["properties"]["comments"].last["action"] assert_equal "This is a reopen comment", js["properties"]["comments"].last["text"] assert_equal user.display_name, js["properties"]["comments"].last["user"] @@ -752,8 +752,8 @@ module Api end def test_index_closed - create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc - 5.days) - create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc - 100.days) + create(:note_with_comments, :closed, :closed_at => Time.now.utc - 5.days) + create(:note_with_comments, :closed, :closed_at => Time.now.utc - 100.days) create(:note_with_comments, :status => "hidden") create(:note_with_comments) diff --git a/test/factories/notes.rb b/test/factories/notes.rb index 77b4245aa..63dcd7804 100644 --- a/test/factories/notes.rb +++ b/test/factories/notes.rb @@ -4,6 +4,15 @@ FactoryBot.define do longitude { 1 * GeoRecord::SCALE } # tile { QuadTile.tile_for_point(1,1) } + trait :closed do + status { "closed" } + closed_at { Time.now.utc } + + after(:create) do |note| + create(:note_comment, :body => "Closing comment", :event => "closed", :note => note) + end + end + factory :note_with_comments do transient do comments_count { 1 } diff --git a/test/models/note_test.rb b/test/models/note_test.rb index 8d5a557cd..34b16c19d 100644 --- a/test/models/note_test.rb +++ b/test/models/note_test.rb @@ -14,7 +14,7 @@ class NoteTest < ActiveSupport::TestCase bad.each do |status| note = create(:note) note.status = status - assert_not note.valid?, "#{status} is valid when it shouldn't be" + assert_not_predicate note, :valid?, "#{status} is valid when it shouldn't be" end end @@ -28,7 +28,7 @@ class NoteTest < ActiveSupport::TestCase end def test_reopen - note = create(:note, :status => "closed", :closed_at => Time.now.utc) + note = create(:note, :closed) assert_equal "closed", note.status assert_not_nil note.closed_at note.reopen @@ -38,13 +38,13 @@ class NoteTest < ActiveSupport::TestCase def test_visible? assert_predicate create(:note, :status => "open"), :visible? - assert_predicate create(:note, :status => "closed"), :visible? - assert_not create(:note, :status => "hidden").visible? + assert_predicate create(:note, :closed), :visible? + assert_not_predicate create(:note, :status => "hidden"), :visible? end def test_closed? - assert_predicate create(:note, :status => "closed", :closed_at => Time.now.utc), :closed? - assert_not create(:note, :status => "open", :closed_at => nil).closed? + assert_predicate create(:note, :closed), :closed? + assert_not_predicate create(:note, :status => "open", :closed_at => nil), :closed? end def test_author diff --git a/test/system/note_comments_test.rb b/test/system/note_comments_test.rb index 2ad64ccc8..aa548059f 100644 --- a/test/system/note_comments_test.rb +++ b/test/system/note_comments_test.rb @@ -11,7 +11,7 @@ class NoteCommentsTest < ApplicationSystemTestCase end test "closed note has no login notice" do - note = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) + note = create(:note_with_comments, :closed) visit note_path(note) assert_no_button "Reactivate"