Add followable specific notices to follows controller actions and render notice on AJAX JS response.
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
App.Followable =
|
||||
|
||||
update: (followable_id, button) ->
|
||||
update: (followable_id, button, notice) ->
|
||||
$("#" + followable_id + " .js-follow").html(button)
|
||||
if ($('[data-alert]').length > 0)
|
||||
$('[data-alert]').replaceWith(notice)
|
||||
else
|
||||
$("body").append(notice)
|
||||
|
||||
@@ -5,12 +5,14 @@ class FollowsController < ApplicationController
|
||||
def create
|
||||
followable = find_followable
|
||||
@follow = Follow.create(user: current_user, followable: followable)
|
||||
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice_html")
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
def destroy
|
||||
@follow = Follow.find(params[:id])
|
||||
@follow.destroy
|
||||
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice_html")
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
@@ -20,4 +22,8 @@ class FollowsController < ApplicationController
|
||||
params[:followable_type].constantize.find(params[:followable_id])
|
||||
end
|
||||
|
||||
def followable_translation_key(followable)
|
||||
followable.class.name.parameterize.gsub("-", "_")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
App.Followable.update("<%= dom_id(@follow.followable) %>",
|
||||
"<%= j render('follow_button', follow: @follow) %>")
|
||||
"<%= j render('follow_button', follow: @follow) %>",
|
||||
"<%= j render('layouts/flash') %>")
|
||||
|
||||
@@ -504,7 +504,17 @@ en:
|
||||
flag: Flag as inappropriate
|
||||
follow: "Follow"
|
||||
follow_entity: "Follow %{entity}"
|
||||
followable_title: "Follow %{entity}: You can participate and receive notifications of any related events."
|
||||
followable:
|
||||
budget_investment:
|
||||
create:
|
||||
notice_html: "You are now following this investment project! </br> We will notify you of changes as they occur so that you are up-to-date."
|
||||
destroy:
|
||||
notice_html: "You have stopped following this investment project! </br> You will no longer receive notifications related to this project."
|
||||
proposal:
|
||||
create:
|
||||
notice_html: "Now you are following this citizen proposal! </br> We will notify you of changes as they occur so that you are up-to-date."
|
||||
destroy:
|
||||
notice_html: "You have stopped following this citizen proposal! </br> You will no longer receive notifications related to this proposal."
|
||||
hide: Hide
|
||||
print:
|
||||
print_button: Print this info
|
||||
|
||||
@@ -504,7 +504,17 @@ es:
|
||||
flag: Denunciar como inapropiado
|
||||
follow: "Seguir"
|
||||
follow_entity: "Seguir %{entity}"
|
||||
followable_title: "Seguir %{entity}: Podrás participar y recibir notificaciones de cualquier suceso relacionado."
|
||||
followable:
|
||||
budget_investment:
|
||||
create:
|
||||
notice_html: "¡Ahora estás siguiendo este proyecto de inversión! </br> Te notificaremos los cambios a medida que se produzcan para que estés al día."
|
||||
destroy:
|
||||
notice_html: "¡Has dejado de seguir este proyecto de inverisión! </br> Ya no recibirás más notificaciones relacionadas con este proyecto."
|
||||
proposal:
|
||||
create:
|
||||
notice_html: "¡Ahora estás siguiendo esta propuesta ciudadana! </br> Te notificaremos los cambios a medida que se produzcan para que estés al día."
|
||||
destroy:
|
||||
notice_html: "¡Has dejado de seguir esta propuesta ciudadana! </br> Ya no recibirás más notificaciones relacionadas con esta propuesta."
|
||||
hide: Ocultar
|
||||
print:
|
||||
print_button: Imprimir esta información
|
||||
|
||||
@@ -49,10 +49,23 @@ shared_examples "followable" do |followable_class_name, followable_path, followa
|
||||
within "##{dom_id(followable)}" do
|
||||
click_link "Follow"
|
||||
|
||||
expect(page).not_to have_link "Follow"
|
||||
expect(page).to have_link "Unfollow"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Should display new follower notice after user clicks on follow button", :js do
|
||||
user = create(:user)
|
||||
login_as(user)
|
||||
|
||||
visit send(followable_path, arguments)
|
||||
within "##{dom_id(followable)}" do
|
||||
click_link "Follow"
|
||||
end
|
||||
|
||||
expect(page).to have_content strip_tags(t("shared.followable.#{followable_class_name}.create.notice_html"))
|
||||
end
|
||||
|
||||
scenario "Display unfollow button when user already following" do
|
||||
user = create(:user)
|
||||
follow = create(:follow, user: user, followable: followable)
|
||||
@@ -63,7 +76,7 @@ shared_examples "followable" do |followable_class_name, followable_path, followa
|
||||
expect(page).to have_link("Unfollow")
|
||||
end
|
||||
|
||||
scenario "Should display follow button after user clicks on unfollow button", :js do
|
||||
scenario "Should update follow button and show destroy notice after user clicks on unfollow button", :js do
|
||||
user = create(:user)
|
||||
follow = create(:follow, user: user, followable: followable)
|
||||
login_as(user)
|
||||
@@ -72,10 +85,24 @@ shared_examples "followable" do |followable_class_name, followable_path, followa
|
||||
within "##{dom_id(followable)}" do
|
||||
click_link "Unfollow"
|
||||
|
||||
expect(page).not_to have_link "Unfollow"
|
||||
expect(page).to have_link "Follow"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Should display destroy follower notice after user clicks on unfollow button", :js do
|
||||
user = create(:user)
|
||||
follow = create(:follow, user: user, followable: followable)
|
||||
login_as(user)
|
||||
|
||||
visit send(followable_path, arguments)
|
||||
within "##{dom_id(followable)}" do
|
||||
click_link "Unfollow"
|
||||
end
|
||||
|
||||
expect(page).to have_content strip_tags(t("shared.followable.#{followable_class_name}.destroy.notice_html"))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user