From 0614629d35da2dc5e83223c79d34192dc09ebc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 9 Nov 2015 13:12:44 +0100 Subject: [PATCH 1/7] adds info about deleted items on comments activity --- app/helpers/users_helper.rb | 27 +++++++++++++++++++++++++++ app/views/users/_comments.html.erb | 2 +- config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/helpers/users_helper.rb diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..77464e00b --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,27 @@ +module UsersHelper + + def comment_commentable_title(comment) + commentable = comment.commentable + if commentable.nil? + deleted_commentable_text(comment) + elsif commentable.hidden? + "".html_safe + + commentable.title + + "".html_safe + else + link_to(commentable.title, commentable) + end + end + + def deleted_commentable_text(comment) + case comment.commentable_type + when "Proposal" + t("users.show.deleted_proposal") + when "Debate" + t("users.show.deleted_debate") + else + t("users.show.deleted") + end + end + +end \ No newline at end of file diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb index 2a8c9d66b..4a2ca5da7 100644 --- a/app/views/users/_comments.html.erb +++ b/app/views/users/_comments.html.erb @@ -2,7 +2,7 @@ <% @comments.each do |comment| %> - <%= comment.commentable.hidden? ? comment.commentable.title : link_to(comment.commentable.title, comment.commentable) %> + <%= comment_commentable_title(comment) %>
<%= comment.body %> diff --git a/config/locales/en.yml b/config/locales/en.yml index cb22de6fd..0089fded9 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -340,6 +340,9 @@ en: other: "%{count} Comments" no_activity: "User has no public activity" private_activity: "This user decided to keep the activity list private" + deleted: "Deleted" + deleted_debate: "This debate has been deleted" + deleted_proposal: "This proposal has been deleted" unauthorized: default: "You do not have permission to access this page." manage: diff --git a/config/locales/es.yml b/config/locales/es.yml index eda14968c..9bc0fe644 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -340,6 +340,9 @@ es: other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" private_activity: "Este usuario ha decidido mantener en privado su lista de actividades" + deleted: "Eliminado" + deleted_debate: "Este debate ha sido eliminado" + deleted_proposal: "Este propuesta ha sido eliminada" unauthorized: default: "No tienes permiso para acceder a esta página." manage: From 7259ac06e8068755e8a59eb57ae535e7a40f0553 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 9 Nov 2015 13:28:02 +0100 Subject: [PATCH 2/7] renames user_helper --- app/helpers/user_helper.rb | 12 ------------ app/helpers/users_helper.rb | 11 +++++++++++ .../{user_helper_spec.rb => users_helper_spec.rb} | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 app/helpers/user_helper.rb rename spec/helpers/{user_helper_spec.rb => users_helper_spec.rb} (92%) diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb deleted file mode 100644 index 9fe2a801d..000000000 --- a/app/helpers/user_helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -module UserHelper - def humanize_document_type(document_type) - case document_type - when "1" - t "verification.residence.new.document_type.spanish_id" - when "2" - t "verification.residence.new.document_type.passport" - when "3" - t "verification.residence.new.document_type.residence_card" - end - end -end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 77464e00b..cbd635a28 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,5 +1,16 @@ module UsersHelper + def humanize_document_type(document_type) + case document_type + when "1" + t "verification.residence.new.document_type.spanish_id" + when "2" + t "verification.residence.new.document_type.passport" + when "3" + t "verification.residence.new.document_type.residence_card" + end + end + def comment_commentable_title(comment) commentable = comment.commentable if commentable.nil? diff --git a/spec/helpers/user_helper_spec.rb b/spec/helpers/users_helper_spec.rb similarity index 92% rename from spec/helpers/user_helper_spec.rb rename to spec/helpers/users_helper_spec.rb index a30b2eecf..34ca626fe 100644 --- a/spec/helpers/user_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe UserHelper do +describe UsersHelper do describe '#humanize_document_type' do it "should return a humanized document type" do From ceb157b53b66300f42a7f9d7e7578da5349b3929 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 9 Nov 2015 13:46:29 +0100 Subject: [PATCH 3/7] removes unused code --- app/helpers/users_helper.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index cbd635a28..90d494f8d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -13,9 +13,7 @@ module UsersHelper def comment_commentable_title(comment) commentable = comment.commentable - if commentable.nil? - deleted_commentable_text(comment) - elsif commentable.hidden? + if commentable.hidden? "".html_safe + commentable.title + "".html_safe @@ -30,8 +28,6 @@ module UsersHelper t("users.show.deleted_proposal") when "Debate" t("users.show.deleted_debate") - else - t("users.show.deleted") end end From f4cee3b1c12c930315706cb982fb0ece07af59f1 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 9 Nov 2015 13:46:37 +0100 Subject: [PATCH 4/7] adds helper specs --- spec/helpers/users_helper_spec.rb | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 34ca626fe..822764292 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -10,4 +10,37 @@ describe UsersHelper do end end + describe '#deleted_commentable_text' do + it "should return the appropriate message for deleted debates" do + debate = create(:debate) + comment = create(:comment, commentable: debate) + + debate.hide + + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title}" + end + + it "should return the appropriate message for deleted proposals" do + proposal = create(:proposal) + comment = create(:comment, commentable: proposal) + + proposal.hide + + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title}" + end + end + + describe '#comment_commentable_title' do + it "should return a link to the commentable" do + comment = create(:comment) + expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment.commentable + end + + it "should return a hint if the commentable has been deleted", :focus do + comment = create(:comment) + comment.commentable.hide + expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title}" + end + end + end From 08c499d4f6b878f83be18c42ffb4f6e05bbae8d4 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 9 Nov 2015 13:49:21 +0100 Subject: [PATCH 5/7] removes spec focus --- spec/helpers/users_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 822764292..2094cea04 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -36,7 +36,7 @@ describe UsersHelper do expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment.commentable end - it "should return a hint if the commentable has been deleted", :focus do + it "should return a hint if the commentable has been deleted" do comment = create(:comment) comment.commentable.hide expect(comment_commentable_title(comment)).to eq "#{comment.commentable.title}" From ef2e7ca4f946a10dba86d02eb6d7880cc150c6e0 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 9 Nov 2015 14:27:56 +0100 Subject: [PATCH 6/7] fixes specs --- app/mailers/mailer.rb | 2 +- config/locales/en.yml | 1 - config/locales/es.yml | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index bf646019a..33b52d170 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -1,7 +1,7 @@ class Mailer < ApplicationMailer helper :text_with_links helper :mailer - helper :user + helper :users def comment(comment) @comment = comment diff --git a/config/locales/en.yml b/config/locales/en.yml index 0089fded9..c47a27703 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -340,7 +340,6 @@ en: other: "%{count} Comments" no_activity: "User has no public activity" private_activity: "This user decided to keep the activity list private" - deleted: "Deleted" deleted_debate: "This debate has been deleted" deleted_proposal: "This proposal has been deleted" unauthorized: diff --git a/config/locales/es.yml b/config/locales/es.yml index 9bc0fe644..e6f76ec86 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -340,7 +340,6 @@ es: other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" private_activity: "Este usuario ha decidido mantener en privado su lista de actividades" - deleted: "Eliminado" deleted_debate: "Este debate ha sido eliminado" deleted_proposal: "Este propuesta ha sido eliminada" unauthorized: From 56e752e8293f0ac752f643f7e3e503488463a6ba Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 9 Nov 2015 15:12:12 +0100 Subject: [PATCH 7/7] brings back extra security checks --- app/helpers/users_helper.rb | 6 +++++- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 90d494f8d..cbd635a28 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -13,7 +13,9 @@ module UsersHelper def comment_commentable_title(comment) commentable = comment.commentable - if commentable.hidden? + if commentable.nil? + deleted_commentable_text(comment) + elsif commentable.hidden? "".html_safe + commentable.title + "".html_safe @@ -28,6 +30,8 @@ module UsersHelper t("users.show.deleted_proposal") when "Debate" t("users.show.deleted_debate") + else + t("users.show.deleted") end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c47a27703..0089fded9 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -340,6 +340,7 @@ en: other: "%{count} Comments" no_activity: "User has no public activity" private_activity: "This user decided to keep the activity list private" + deleted: "Deleted" deleted_debate: "This debate has been deleted" deleted_proposal: "This proposal has been deleted" unauthorized: diff --git a/config/locales/es.yml b/config/locales/es.yml index e6f76ec86..9bc0fe644 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -340,6 +340,7 @@ es: other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" private_activity: "Este usuario ha decidido mantener en privado su lista de actividades" + deleted: "Eliminado" deleted_debate: "Este debate ha sido eliminado" deleted_proposal: "Este propuesta ha sido eliminada" unauthorized: