diff --git a/app/models/crop.rb b/app/models/crop.rb index 4d898c73c2..6bf902c4c5 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -299,6 +299,14 @@ def add_alternate_names_from_csv(alternate_names) end end + def rejection_explanation + if reason_for_rejection == "other" + return rejection_notes + else + return reason_for_rejection + 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 fffb822f43..54ae162db9 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_approved.html.haml b/app/views/notifier/crop_request_approved.html.haml index 5fea202463..871522b0b9 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 c58e2546b8..d1ab14868a 100644 --- a/app/views/notifier/crop_request_rejected.html.haml +++ b/app/views/notifier/crop_request_rejected.html.haml @@ -2,8 +2,6 @@ %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.rejection_explanation} - = @crop.reason_for_rejection - -= 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 163c898f4d..0e8c65ab78 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' diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index d58c46ee3a..bf894b9212 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -554,4 +554,19 @@ 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