Created
January 30, 2015 17:01
-
-
Save mamantoha/3311a4287e383a8f6efe to your computer and use it in GitHub Desktop.
CSN Notifier test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/mailers/action_notifier.rb | |
public | |
def generate_csn_notifications_and_deliver(users, template) | |
if @email_notification # maybe instead for @csn_email and @csn_online we pass an argument instead | |
users.each do |user| | |
m = mail(:to => user.email) do |format| | |
format.html { render :text => template } | |
end | |
# if user.notification_preferences.deliver_by_email == true # -- what this? | |
mail.deliver | |
# end | |
end | |
end | |
if @online_notification | |
# no need to check notification preferences here. | |
csn_api_helper.deliver(json) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/mailers/csn_notifier.rb | |
class CsnNotifier < ActionNotifier | |
def approved(invoice) | |
supplier = invoice.supplier | |
# TODO add needed values for email template | |
@title = "TITLE" | |
if supplier.linked_to_connect? | |
users = supplier.supplier_users.active | |
@email_notification = render "email_template" | |
pp @email_notification | |
#@online_notification = invoice.get_csn_json # uncomment this later | |
generate_csn_notifications_and_deliver(users, @email_notification) | |
else | |
# do the thing that we currently do fo approved logic in notifier.rb | |
# maybe just call InvoiceNotify.approve | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/mailers/csn_test_spec.rb | |
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe "Test CSN invoice_approved notifications" do | |
before do | |
User.current_user = CoupaLib::Factory.create_user | |
end | |
describe "notifiers" do | |
describe CsnNotifier do | |
it "an invoice state changes " do | |
expect { | |
supplier = FactoryGirl.create(:supplier, :status => 'active', :coupa_connect_status => 'Linked') | |
supplier_user1 = FactoryGirl.create(:supplier_user, :email => 'test1@example.com', :supplier => supplier) | |
supplier_user2 = FactoryGirl.create(:supplier_user, :email => 'test2@example.com', :supplier => supplier) | |
invoice = CoupaLib::Factory.create_invoice_header(:supplier => supplier) | |
# call from a model when an invoice state changes we do | |
CsnNotifier.approved(invoice) | |
}.to change { ActionMailer::Base.deliveries.size }.by(2) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<%= @title%> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment