From 19b6740d370c732461668b9e9a4c9fdf05ad666a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 16:46:54 +0200 Subject: [PATCH 1/2] updates email from field --- app/mailers/application_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index c1f3e4bb6..8838f522f 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,5 +1,5 @@ class ApplicationMailer < ActionMailer::Base helper :settings - default from: "participacion@madrid.es" + default from: "Decide Madrid " layout 'mailer' end From 06596ac4d80a0e56a1e9cbbbb7245ef2b29dd9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 15 Jun 2016 17:01:50 +0200 Subject: [PATCH 2/2] adds author_of? helper method --- app/helpers/application_helper.rb | 5 +++++ spec/helpers/application_helper_spec.rb | 27 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c5f2e6aca..1f52f0eea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -35,4 +35,9 @@ module ApplicationHelper } Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe end + + def author_of?(authorable, user) + return false if authorable.blank? || user.blank? + authorable.author_id == user.id + end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..61137912d --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +describe ApplicationHelper do + + describe "#author_of?" do + it "should be true if user is the author" do + user = create(:user) + proposal = create(:proposal, author: user) + expect(author_of?(proposal, user)).to eq true + end + + it "should be false if user is not the author" do + user = create(:user) + proposal = create(:proposal) + expect(author_of?(proposal, user)).to eq false + end + + it "should be false if user or authorable is nil" do + user = create(:user) + proposal = create(:proposal) + + expect(author_of?(nil, user)).to eq false + expect(author_of?(proposal, nil)).to eq false + end + end + +end \ No newline at end of file