X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/28726e5f11cb46add4e6b86eb9a958798b83c46a..f6141277d5a727fdec5c7bb26e35b17b1e6f495d:/test/controllers/diary_entries_controller_test.rb diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index 9acd72c67..7d543250b 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -119,9 +119,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 assert_select "input[name=commit][type=submit][value=Publish]", :count => 1 - assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 - assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 - assert_select "input", :count => 6 + assert_select "button[type=button]", :text => "Edit", :count => 1 + assert_select "button[type=button]", :text => "Preview", :count => 1 + assert_select "input", :count => 4 end end end @@ -163,7 +163,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest :longitude => "2.2", :language_code => "en" }) end assert_redirected_to :action => :index, :display_name => user.display_name - entry = DiaryEntry.order(:id).last + entry = DiaryEntry.last assert_equal user.id, entry.user_id assert_equal "New Title", entry.title assert_equal "This is a new body for the diary entry", entry.body @@ -189,7 +189,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest :longitude => "2.2", :language_code => "de" }) end assert_redirected_to :action => :index, :display_name => user.display_name - entry = DiaryEntry.order(:id).last + entry = DiaryEntry.last assert_equal user.id, entry.user_id assert_equal "New Title", entry.title assert_equal "This is a new body for the diary entry", entry.body @@ -217,7 +217,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" }) end assert_redirected_to :action => :index, :display_name => user.display_name - entry = DiaryEntry.order(:id).last + entry = DiaryEntry.last assert_equal user.id, entry.user_id assert_equal spammy_title, entry.title assert_equal spammy_body, entry.body @@ -272,9 +272,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 assert_select "input[name=commit][type=submit][value=Update]", :count => 1 - assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 - assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 - assert_select "input", :count => 7 + assert_select "button[type=button]", :text => "Edit", :count => 1 + assert_select "button[type=button]", :text => "Preview", :count => 1 + assert_select "input", :count => 5 end end @@ -336,6 +336,29 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry" end + def test_update + user = create(:user) + other_user = create(:user) + diary_entry = create(:diary_entry, :language_code => "en", :user => user, :title => "Original Title") + + put diary_entry_path(user, diary_entry, :diary_entry => { :title => "Updated Title" }) + assert_response :forbidden + diary_entry.reload + assert_equal "Original Title", diary_entry.title + + session_for(other_user) + put diary_entry_path(user, diary_entry, :diary_entry => { :title => "Updated Title" }) + assert_redirected_to diary_entry_path(user, diary_entry) + diary_entry.reload + assert_equal "Original Title", diary_entry.title + + session_for(user) + put diary_entry_path(user, diary_entry, :diary_entry => { :title => "Updated Title" }) + assert_redirected_to diary_entry_path(user, diary_entry) + diary_entry.reload + assert_equal "Updated Title", diary_entry.title + end + def test_index_all diary_entry = create(:diary_entry) geo_entry = create(:diary_entry, :latitude => 51.50763, :longitude => -0.10781) @@ -625,6 +648,17 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest end end + def test_show_og_title + user = create(:user) + diary_entry = create(:diary_entry, :user => user, :title => "The Important Blog Post") + + get diary_entry_path(user, diary_entry) + assert_response :success + assert_dom "head meta[property='og:title']" do + assert_dom "> @content", "The Important Blog Post" + end + end + def test_show_og_image_with_no_image user = create(:user) diary_entry = create(:diary_entry, :user => user, :body => "nothing") @@ -634,6 +668,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_dom "head meta[property='og:image']" do assert_dom "> @content", ActionController::Base.helpers.image_url("osm_logo_256.png", :host => root_url) end + assert_dom "head meta[property='og:image:alt']" do + assert_dom "> @content", "OpenStreetMap logo" + end end def test_show_og_image @@ -645,6 +682,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_dom "head meta[property='og:image']" do assert_dom "> @content", "https://example.com/picture.jpg" end + assert_dom "head meta[property='og:image:alt']" do + assert_dom "> @content", "some picture" + end end def test_show_og_image_with_relative_uri @@ -656,6 +696,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_dom "head meta[property='og:image']" do assert_dom "> @content", "#{root_url}picture.jpg" end + assert_dom "head meta[property='og:image:alt']" do + assert_dom "> @content", "some local picture" + end end def test_show_og_image_with_spaces @@ -667,6 +710,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_dom "head meta[property='og:image']" do assert_dom "> @content", "https://example.com/the%20picture.jpg" end + assert_dom "head meta[property='og:image:alt']" do + assert_dom "> @content", "some picture" + end end def test_show_og_image_with_relative_uri_and_spaces @@ -678,6 +724,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_dom "head meta[property='og:image']" do assert_dom "> @content", "#{root_url}the%20picture.jpg" end + assert_dom "head meta[property='og:image:alt']" do + assert_dom "> @content", "some local picture" + end end def test_show_og_image_with_invalid_uri @@ -689,6 +738,54 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_dom "head meta[property='og:image']" do assert_dom "> @content", ActionController::Base.helpers.image_url("osm_logo_256.png", :host => root_url) end + assert_dom "head meta[property='og:image:alt']" do + assert_dom "> @content", "OpenStreetMap logo" + end + end + + def test_show_og_image_without_alt + user = create(:user) + diary_entry = create(:diary_entry, :user => user, :body => "") + + get diary_entry_path(user, diary_entry) + assert_response :success + assert_dom "head meta[property='og:image']" do + assert_dom "> @content", "https://example.com/no_alt.gif" + end + assert_dom "head meta[property='og:image:alt']", :count => 0 + end + + def test_show_no_og_description + user = create(:user) + diary_entry = create(:diary_entry, :user => user, :body => "![nope](https://example.com/nope.jpg)") + + get diary_entry_path(user, diary_entry) + assert_response :success + assert_dom "head meta[property='og:description']" do + assert_dom "> @content", I18n.t("layouts.intro_text") + end + end + + def test_show_og_description + user = create(:user) + diary_entry = create(:diary_entry, :user => user, :body => "# Hello\n\n![hello](https://example.com/hello.jpg)\n\nFirst paragraph.\n\nSecond paragraph.") + + get diary_entry_path(user, diary_entry) + assert_response :success + assert_dom "head meta[property='og:description']" do + assert_dom "> @content", "First paragraph." + end + end + + def test_show_article_published_time + user = create(:user) + diary_entry = create(:diary_entry, :user => user, :created_at => "2020-03-04") + + get diary_entry_path(user, diary_entry) + assert_response :success + assert_dom "head meta[property='article:published_time']" do + assert_dom "> @content", "2020-03-04T00:00:00Z" + end end def test_hide