Merge pull request #2416 from wairbut-m2c/show_error_message_when_relating_content_to_itself
Show error message when relating content to itself
This commit is contained in:
@@ -5,13 +5,18 @@ class RelatedContentsController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
if relationable_object && related_object
|
if relationable_object && related_object
|
||||||
RelatedContent.create(parent_relationable: @relationable, child_relationable: @related, author: current_user)
|
|
||||||
|
|
||||||
flash[:success] = t('related_content.success')
|
if relationable_object.url != related_object.url
|
||||||
|
RelatedContent.create(parent_relationable: @relationable, child_relationable: @related, author: current_user)
|
||||||
|
|
||||||
|
flash[:success] = t('related_content.success')
|
||||||
|
else
|
||||||
|
flash[:error] = t('related_content.error_itself')
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
flash[:error] = t('related_content.error', url: Setting['url'])
|
flash[:error] = t('related_content.error', url: Setting['url'])
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to @relationable.url
|
redirect_to @relationable.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -821,6 +821,7 @@ en:
|
|||||||
help: "You can add links of %{models} inside of %{org}."
|
help: "You can add links of %{models} inside of %{org}."
|
||||||
submit: "Add"
|
submit: "Add"
|
||||||
error: "Link not valid. Remember to start with %{url}."
|
error: "Link not valid. Remember to start with %{url}."
|
||||||
|
error_itself: "Link not valid. You cannot relate a content to itself."
|
||||||
success: "You added a new related content"
|
success: "You added a new related content"
|
||||||
is_related: "¿Is it related content?"
|
is_related: "¿Is it related content?"
|
||||||
score_positive: "Yes"
|
score_positive: "Yes"
|
||||||
|
|||||||
@@ -820,6 +820,7 @@ es:
|
|||||||
help: "Puedes introducir cualquier enlace de %{models} que esté dentro de %{org}."
|
help: "Puedes introducir cualquier enlace de %{models} que esté dentro de %{org}."
|
||||||
submit: "Añadir"
|
submit: "Añadir"
|
||||||
error: "Enlace no válido. Recuerda que debe empezar por %{url}."
|
error: "Enlace no válido. Recuerda que debe empezar por %{url}."
|
||||||
|
error_itself: "Enlace no válido. No se puede relacionar un contenido consigo mismo."
|
||||||
success: "Has añadido un nuevo contenido relacionado"
|
success: "Has añadido un nuevo contenido relacionado"
|
||||||
is_related: "¿Es contenido relacionado?"
|
is_related: "¿Es contenido relacionado?"
|
||||||
score_positive: "Sí"
|
score_positive: "Sí"
|
||||||
|
|||||||
@@ -819,6 +819,7 @@ val:
|
|||||||
help: "Pots afegir enllaços de %{models} en %{org}."
|
help: "Pots afegir enllaços de %{models} en %{org}."
|
||||||
submit: "Afegir"
|
submit: "Afegir"
|
||||||
error: "Enllaç no vàlid. Recorda iniciar amb %{url}."
|
error: "Enllaç no vàlid. Recorda iniciar amb %{url}."
|
||||||
|
error_itself: "Enllaç no vàlid. No es pot relacionar un contingut aconseguisc mateix"
|
||||||
success: "Has afegit nou contingut relacionat"
|
success: "Has afegit nou contingut relacionat"
|
||||||
is_related: "Es contingut relacionat?"
|
is_related: "Es contingut relacionat?"
|
||||||
score_positive: "Sí"
|
score_positive: "Sí"
|
||||||
|
|||||||
@@ -71,6 +71,20 @@ shared_examples "relationable" do |relationable_model_name|
|
|||||||
expect(page).to have_content("Link not valid. Remember to start with #{Setting[:url]}.")
|
expect(page).to have_content("Link not valid. Remember to start with #{Setting[:url]}.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'returns error when relating content URL to itself' do
|
||||||
|
login_as(user)
|
||||||
|
visit relationable.url
|
||||||
|
|
||||||
|
click_on("Add related content")
|
||||||
|
|
||||||
|
within("#related_content") do
|
||||||
|
fill_in 'url', with: Setting[:url] + relationable.url.to_s
|
||||||
|
click_button "Add"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content("Link not valid. You cannot relate a content to itself")
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'related content can be scored positively', :js do
|
scenario 'related content can be scored positively', :js do
|
||||||
related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user