#275: spec test for controller method. Other small fixes.

This commit is contained in:
Paul Mackay
2015-04-11 18:28:31 +01:00
parent 99709b53ed
commit 9103e83ce2
4 changed files with 29 additions and 4 deletions

View File

@@ -74,8 +74,7 @@ module Admin
@order_cycle = OrderCycle.find params[:id]
Delayed::Job.enqueue OrderCycleNotificationJob.new(@order_cycle)
flash[:notice] = 'Emails to be sent to producers have been queued for sending.'
format.html { redirect_to admin_order_cycles_path }
redirect_to main_app.admin_order_cycles_path, :notice => 'Emails to be sent to producers have been queued for sending.'
end

View File

@@ -43,7 +43,7 @@ Openfoodnetwork::Application.routes.draw do
post :bulk_update, on: :collection, as: :bulk_update
get :clone, on: :member
post 'notifications', on: :member
post 'notify_producers', on: :member
end
resources :enterprises do

View File

@@ -0,0 +1,27 @@
require 'spec_helper'
module Admin
describe OrderCyclesController do
include AuthenticationWorkflow
let(:user) { create_enterprise_user }
let(:admin_user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
user
end
let(:order_cycle) { create(:simple_order_cycle) }
context 'order cycle has closed' do
it 'can notify producers' do
controller.stub spree_current_user: admin_user
expect(Delayed::Job).to receive(:enqueue).once
spree_post :notify_producers, {id: order_cycle.id}
# TODO: is there a better variable to use?
expect(response).to redirect_to spree.admin_path + '/order_cycles'
flash[:notice].should == 'Emails to be sent to producers have been queued for sending.'
end
end
end
end

View File

@@ -6,7 +6,6 @@ describe OrderCycleNotificationJob do
it 'sends a mail to each supplier' do
mail = double()
allow(mail).to receive(:deliver)
mailer = double('ProducerMailer')
expect(ProducerMailer).to receive(:order_cycle_report).twice.and_return(mail)
job = OrderCycleNotificationJob.new(order_cycle)
job.perform