requester receives a message when crop request is rejected

This commit is contained in:
Taylor Griffin committed 2015-02-01 17:32:49 +11:00
1 parent 776b5450f9
commit e86200b942
8 files changed
+62 -7

No files matched your search

+2 -1
View File
@@ -141,6 +141,7 @@ class CropsController < ApplicationController
requester = @crop.requester
new_status = @crop.approval_status
Notifier.crop_request_approved(requester, @crop).deliver! if new_status == "approved"
Notifier.crop_request_rejected(requester, @crop).deliver! if new_status == "rejected"
end
format.html { redirect_to @crop, notice: 'Crop was successfully updated.' }
format.json { head :no_content }
@@ -166,6 +167,6 @@ class CropsController < ApplicationController
private
def crop_params
params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :approval_status, :scientific_names_attributes => [:scientific_name])
params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :approval_status, :reason_for_rejection, :scientific_names_attributes => [:scientific_name])
end
end
+5
View File
@@ -32,4 +32,9 @@ class Notifier < ActionMailer::Base
mail(:to => @member.email, :subject => "#{crop.name.capitalize} has been approved")
end
def crop_request_rejected(member, crop)
@member, @crop = member, crop
mail(:to => @member.email, :subject => "#{crop.name.capitalize} has been rejected")
end
end
+5
View File
@@ -46,6 +46,11 @@
.col-md-8
= f.select(:approval_status, ['rejected', 'pending', 'approved'], {}, {:class => 'form-control'})
.form-group
= f.label :reason_for_rejection, 'Reason for rejection', :class => 'control-label col-md-2'
.col-md-8= f.text_area :reason_for_rejection, :rows => 6, :class => 'form-control'
.form-group
.form-actions.col-md-offset-2.col-md-8
= f.submit 'Save', :class => 'btn btn-primary'
@@ -0,0 +1,7 @@
- site_name = ENV['GROWSTUFF_SITE_NAME']
%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.
= @crop.reason_for_rejection
@@ -0,0 +1,5 @@
class AddReasonForRejectionToCrops < ActiveRecord::Migration
def change
add_column :crops, :reason_for_rejection, :text
end
end
+7 -6
View File
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150201053200) do
ActiveRecord::Schema.define(version: 20150201062506) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -62,16 +62,17 @@ ActiveRecord::Schema.define(version: 20150201053200) do
end
create_table "crops", force: true do |t|
t.string "name", null: false
t.string "name", null: false
t.string "en_wikipedia_url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.integer "parent_id"
t.integer "plantings_count", default: 0
t.integer "plantings_count", default: 0
t.integer "creator_id"
t.integer "requester_id"
t.string "approval_status", default: "approved"
t.string "approval_status", default: "approved"
t.text "reason_for_rejection"
end
add_index "crops", ["name"], name: "index_crops_on_name", using: :btree
+5
View File
@@ -59,6 +59,11 @@ FactoryGirl.define do
name "Ultra berry"
end
factory :rejected_crop do
name "Fail bean"
reason_for_rejection "Totally fake"
end
end
end
+26
View File
@@ -97,5 +97,31 @@ describe Notifier do
end
describe "crop rejected" do
let(:member) { FactoryGirl.create(:member) }
let(:crop) { FactoryGirl.create(:rejected_crop) }
let(:mail) { Notifier.crop_request_rejected(member, crop) }
it 'sets the subject correctly' do
expect(mail.subject).to eq "Fail bean has been rejected"
end
it 'comes from noreply@growstuff.org' do
expect(mail.from).to eq ['noreply@growstuff.org']
end
it 'sends the mail to the recipient of the notification' do
expect(mail.to).to eq [member.email]
end
it 'includes the rejected crop URL' do
expect(mail.body.encoded).to match crop_url(crop)
end
it 'includes the reason for rejection' do
expect(mail.body.encoded).to match "Totally fake"
end
end
end