Skip to content

Commit

Permalink
Merge pull request #726 from maco/approved_crops
Browse files Browse the repository at this point in the history
Crop accept/reject notification improvements
  • Loading branch information
Skud committed Mar 18, 2015
2 parents 6505254 + bd0da36 commit d7ef598
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
8 changes: 8 additions & 0 deletions app/models/crop.rb
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/views/crops/_approval_status_message.html.haml
Expand Up @@ -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}.
%b This crop was rejected for the following reason: #{crop.rejection_explanation}
2 changes: 1 addition & 1 deletion app/views/notifier/crop_request_approved.html.haml
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions app/views/notifier/crop_request_rejected.html.haml
Expand Up @@ -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'
= render :partial => 'signature'
3 changes: 2 additions & 1 deletion app/views/notifier/new_crop_request.html.haml
Expand Up @@ -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)}.
Expand All @@ -18,4 +19,4 @@
%p
Thanks for your help!

= render :partial => 'signature'
= render :partial => 'signature'
15 changes: 15 additions & 0 deletions spec/models/crop_spec.rb
Expand Up @@ -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

0 comments on commit d7ef598

Please sign in to comment.