Commit 4e5f310b authored by gwendal's avatar gwendal
Browse files

fix notify_expiration thomasvo bug :) (close #177)

parent bc8e7b6e
......@@ -182,7 +182,7 @@ class ServicesController < WebController
end
def notify_expiration
@service = @services.first
post_load
@service.notify_expiration
redirect_to(@service, notice: I18n.t(
:expiration_notified, scope: [:services, :notify_expiration]
......
......@@ -72,7 +72,7 @@
</p>
<% if can? :notify_expiration, @service %>
<%= button_to t('services.notify_expiration.link'), service_notify_expiration_path(@service), class: "btn btn-warning" %>
<%= button_to t('services.notify_expiration.link'), [:notify_expiration, @service], class: "btn btn-warning" %>
<% if @service.expiration_notified_on %>
<p class="service_expiration_notified_on">
<b><%= Service.human_attribute_name('expiration_notified_on') %> :</b>
......
......@@ -7,12 +7,14 @@ Ambre::Application.routes.draw do
root :to => 'dashboard#index'
resources :services, only: [:index, :destroy] do
post :notify_expiration
end
resources :services, only: [:index, :destroy]
get '/dsl_services/update_form_prices' => 'dsl_services#update_form_prices'
get '/member_payments/update_form_recipient' => 'member_payments#update_form_recipient'
resources :blo_services, :dsl_services, :radio_services, :vpn_services
resources :blo_services, :dsl_services, :radio_services, :vpn_services do
member do
post :notify_expiration
end
end
resources :service_sale_templates, only: [:new, :create, :update, :show, :edit, :destroy]
resources :service_macs, only: [:new, :create, :destroy]
......
......@@ -346,6 +346,30 @@ module AllServicesControllerSpec
end # end board member
end # end edit add deposit
describe "#notify_expiration" do
let(:member) { FactoryBot.create :member }
let(:member_service) { FactoryBot.create SERVICE_BY_TYPE[service_type], member: member }
context "when logged as board member" do
before(:each) do
@board_member = FactoryBot.create(:board_member)
sign_in @board_member
end
it 'should send a notification that the service has expired' do
params = {id: member_service.id}
expect { post :notify_expiration, params }.to change(MemberMailer.deliveries, :count).by 1
end
it 'should change the expiration_notified_on date' do
params = {id: member_service.id}
post :notify_expiration, params
member_service.reload
expect(member_service.expiration_notified_on).to eq(Date.current)
end
end
end
end # end service controller
end # end service loop
......
......@@ -11,8 +11,6 @@ FactoryBot.define do
expired_at do
if expired
Date.new(2013, 1, 15)
else
Date.today.next_month
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment