3 class ChangesetsHelperTest < ActionView::TestCase
4 def test_changeset_user_link
5 changeset = create(:changeset)
6 changeset_user_link_dom = Rails::Dom::Testing.html_document_fragment.parse changeset_user_link(changeset)
7 assert_dom changeset_user_link_dom, "a:root", :text => changeset.user.display_name do
8 assert_dom "> @href", "/user/#{ERB::Util.u(changeset.user.display_name)}"
11 changeset = create(:changeset, :user => create(:user, :data_public => false))
12 assert_equal "anonymous", changeset_user_link(changeset)
14 changeset = create(:changeset, :user => create(:user, :deleted))
15 assert_equal "deleted", changeset_user_link(changeset)
18 def test_changeset_details
19 changeset = create(:changeset, :created_at => Time.utc(2007, 1, 1, 0, 0, 0), :user => create(:user, :data_public => false))
20 # We need to explicitly reset the closed_at to some point in the future, and avoid the before_save callback
21 changeset.update_column(:closed_at, Time.now.utc + 1.day) # rubocop:disable Rails/SkipsModelValidations
22 changeset_details_dom = Rails::Dom::Testing.html_document_fragment.parse "<div>#{changeset_details(changeset)}</div>"
23 assert_dom changeset_details_dom, ":root", :text => /^Created .* by anonymous$/ do
24 assert_dom "> time", :count => 1 do
25 assert_dom "> @title", "Mon, 01 Jan 2007 00:00:00 +0000"
26 assert_dom "> @datetime", "2007-01-01T00:00:00Z"
28 assert_dom "> a", :count => 0
31 changeset = create(:changeset, :created_at => Time.utc(2007, 1, 1, 0, 0, 0), :closed_at => Time.utc(2007, 1, 2, 0, 0, 0))
32 changeset_details_dom = Rails::Dom::Testing.html_document_fragment.parse "<div>#{changeset_details(changeset)}</div>"
33 assert_dom changeset_details_dom, ":root", :text => /^Closed .* by #{changeset.user.display_name}$/ do
34 assert_dom "> time", :count => 1 do
35 assert_dom "> @title", "Created: Mon, 01 Jan 2007 00:00:00 +0000\nClosed: Tue, 02 Jan 2007 00:00:00 +0000"
36 assert_dom "> @datetime", "2007-01-02T00:00:00Z"
38 assert_dom "> a", :count => 1, :text => changeset.user.display_name do
39 assert_dom "> @href", "/user/#{ERB::Util.u(changeset.user.display_name)}"