From 9e53105f430eb3748e83d23b07817d2fcf37e06d Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Wed, 4 Mar 2015 22:02:35 -0500 Subject: [PATCH 1/4] make language for crop accept/reject friendlier and if reason for rejection is 'other', give the rejection notes --- app/views/notifier/crop_request_approved.html.haml | 2 +- app/views/notifier/crop_request_rejected.html.haml | 9 ++++++--- app/views/notifier/new_crop_request.html.haml | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/views/notifier/crop_request_approved.html.haml b/app/views/notifier/crop_request_approved.html.haml index 5fea20246..871522b0b 100644 --- a/app/views/notifier/crop_request_approved.html.haml +++ b/app/views/notifier/crop_request_approved.html.haml @@ -2,7 +2,7 @@ %p Hello #{@member.login_name}, %p - Your request for the new crop: #{link_to @crop.name, crop_url(@crop)} has been approved! + Your request for the new crop: #{link_to @crop.name, crop_url(@crop)} has been approved! Thank you for helping us make our listing ever more complete! %ul %li diff --git a/app/views/notifier/crop_request_rejected.html.haml b/app/views/notifier/crop_request_rejected.html.haml index c58e2546b..29585d8af 100644 --- a/app/views/notifier/crop_request_rejected.html.haml +++ b/app/views/notifier/crop_request_rejected.html.haml @@ -2,8 +2,11 @@ %p Hello #{@member.login_name}, %p - Your request for the new crop: #{link_to @crop.name, crop_url(@crop)} has been rejected for the following reason. + We're sorry, but your request for the new crop: #{link_to @crop.name, crop_url(@crop)} has been rejected for the following reason: - = @crop.reason_for_rejection + - if @crop.reason_for_rejection != "other" + = @crop.reason_for_rejection + - else + = @crop.rejection_notes -= render :partial => 'signature' \ No newline at end of file += render :partial => 'signature' diff --git a/app/views/notifier/new_crop_request.html.haml b/app/views/notifier/new_crop_request.html.haml index 163c898f4..0e8c65ab7 100644 --- a/app/views/notifier/new_crop_request.html.haml +++ b/app/views/notifier/new_crop_request.html.haml @@ -8,6 +8,7 @@ %ul %li Name: #{@request.name} %li Wikipedia URL: #{@request.en_wikipedia_url.present? ? @request.en_wikipedia_url : "not specified"} + %li Notes: #{@request.request_notes} %p As a crop wrangler, you can #{link_to "approve or reject this request", edit_crop_url(@request)}. @@ -18,4 +19,4 @@ %p Thanks for your help! -= render :partial => 'signature' \ No newline at end of file += render :partial => 'signature' From 920ca2948bac5c42098178b9497e941c937c5224 Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Mon, 9 Mar 2015 00:50:34 -0400 Subject: [PATCH 2/4] add helper function for crop rejection explanation and use it on both notifier and status message --- app/models/crop.rb | 8 ++++++++ app/views/crops/_approval_status_message.html.haml | 2 +- app/views/notifier/crop_request_rejected.html.haml | 7 +------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 4d898c73c..e2d4c3fb0 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -299,6 +299,14 @@ class Crop < ActiveRecord::Base end end + def rejection_explanation + if reason_for_rejection != "other" + return reason_for_rejection + else + return rejection_notes + end + end + # Crop.search(string) def self.search(query) if ENV['GROWSTUFF_ELASTICSEARCH'] == "true" diff --git a/app/views/crops/_approval_status_message.html.haml b/app/views/crops/_approval_status_message.html.haml index fffb822f4..54ae162db 100644 --- a/app/views/crops/_approval_status_message.html.haml +++ b/app/views/crops/_approval_status_message.html.haml @@ -8,4 +8,4 @@ - if crop.rejected? .alert.alert-danger - %b This crop was rejected for the following reason: #{crop.reason_for_rejection == "other" ? crop.rejection_notes : crop.reason_for_rejection}. \ No newline at end of file + %b This crop was rejected for the following reason: #{crop.rejection_explanation} diff --git a/app/views/notifier/crop_request_rejected.html.haml b/app/views/notifier/crop_request_rejected.html.haml index 29585d8af..d1ab14868 100644 --- a/app/views/notifier/crop_request_rejected.html.haml +++ b/app/views/notifier/crop_request_rejected.html.haml @@ -2,11 +2,6 @@ %p Hello #{@member.login_name}, %p - We're sorry, but your request for the new crop: #{link_to @crop.name, crop_url(@crop)} has been rejected for the following reason: - - - if @crop.reason_for_rejection != "other" - = @crop.reason_for_rejection - - else - = @crop.rejection_notes + We're sorry, but your request for the new crop: #{link_to @crop.name, crop_url(@crop)} has been rejected for the following reason: #{@crop.rejection_explanation} = render :partial => 'signature' From 6dedf1b03090ce66169e6ec5bf1f9813fabcad76 Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Mon, 16 Mar 2015 23:07:17 -0400 Subject: [PATCH 3/4] add test for crop.rejection_explanation function --- spec/models/crop_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index d58c46ee3..bf894b921 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -554,4 +554,19 @@ describe Crop do end end end + + context "crop rejections" do + let!(:rejected_reason) { FactoryGirl.create(:crop, :name => 'tomato', :approval_status => 'rejected', :reason_for_rejection => 'not edible') } + let!(:rejected_other) { FactoryGirl.create(:crop, :name => 'tomato', :approval_status => 'rejected', :reason_for_rejection => 'other', :rejection_notes => 'blah blah blah') } + + describe "rejecting a crop" do + it "should give reason if a default option" do + expect(rejected_reason.rejection_explanation).to eq "not edible" + end + + it "should show rejection notes if reason was other" do + expect(rejected_other.rejection_explanation).to eq "blah blah blah" + end + end + end end From bd0da36d6362b58209354c878a76df954160a3fa Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Tue, 17 Mar 2015 21:23:54 -0400 Subject: [PATCH 4/4] reverse the rejection_explanation logic to not use != --- app/models/crop.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index e2d4c3fb0..6bf902c4c 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -300,10 +300,10 @@ class Crop < ActiveRecord::Base end def rejection_explanation - if reason_for_rejection != "other" - return reason_for_rejection - else + if reason_for_rejection == "other" return rejection_notes + else + return reason_for_rejection end end