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
# Now try creating a diary entry using get
session_for(create(:user))
assert_difference "DiaryEntry.count", 0 do
- get new_diary_entry_path(:commit => "save",
- :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
+ get new_diary_entry_path(:diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
:longitude => "2.2", :language_code => "en" })
end
assert_response :success
user = create(:user)
session_for(user)
assert_no_difference "DiaryEntry.count" do
- post diary_entries_path(:commit => "save",
- :diary_entry => { :title => "New Title", :body => "", :latitude => "1.1",
+ post diary_entries_path(:diary_entry => { :title => "New Title", :body => "", :latitude => "1.1",
:longitude => "2.2", :language_code => "en" })
end
assert_response :success
user = create(:user)
session_for(user)
assert_difference "DiaryEntry.count", 1 do
- post diary_entries_path(:commit => "save",
- :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
+ post diary_entries_path(:diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
: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_redirected_to diary_entry_path(user, entry)
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
# Now try creating a diary entry in a different language
assert_difference "DiaryEntry.count", 1 do
- post diary_entries_path(:commit => "save",
- :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
+ post diary_entries_path(:diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
: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_redirected_to diary_entry_path(user, entry)
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
# Try creating a spammy diary entry
assert_difference "DiaryEntry.count", 1 do
- post diary_entries_path(:commit => "save",
- :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" })
+ post diary_entries_path(: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_redirected_to diary_entry_path(user, entry)
assert_equal user.id, entry.user_id
assert_equal spammy_title, entry.title
assert_equal spammy_body, entry.body
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
new_latitude = "1.1"
new_longitude = "2.2"
new_language_code = "en"
- put diary_entry_path(entry.user, entry, :commit => "save",
- :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
+ put diary_entry_path(entry.user, entry, :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
:longitude => new_longitude, :language_code => new_language_code })
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
def test_index_friends
user = create(:user)
other_user = create(:user)
- friendship = create(:friendship, :befriender => user)
- diary_entry = create(:diary_entry, :user => friendship.befriendee)
+ follow = create(:follow, :follower => user)
+ diary_entry = create(:diary_entry, :user => follow.following)
_other_entry = create(:diary_entry, :user => other_user)
# Try a list of diary entries for your friends when not logged in
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")
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
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
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
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
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
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 => "<img src='https://example.com/no_alt.gif'>")
+
+ 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