Created
November 16, 2012 00:13
-
-
Save cwsaylor/4082653 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/app/models/inbox/recruiter_message.rb b/app/models/inbox/recruiter_message.rb | |
index 2373ae2..c1b7eab 100644 | |
--- a/app/models/inbox/recruiter_message.rb | |
+++ b/app/models/inbox/recruiter_message.rb | |
@@ -20,6 +20,8 @@ class Inbox::RecruiterMessage < Inbox::Message | |
validate :available_credits, on: :create | |
validate :active_subscription, on: :create | |
+ after_create :doc_mail_debit | |
+ | |
# Internal: Adds an error if the sender does not have enough credits on | |
# creation. | |
def available_credits | |
@@ -53,6 +55,10 @@ class Inbox::RecruiterMessage < Inbox::Message | |
end | |
end | |
+ def doc_mail_debit | |
+ sender.user.recruiter_organization.doc_mail_debit conversation | |
+ end | |
+ | |
def oppurtunity | |
@oppurtunity ||= ActiveSupport::StringInquirer.new(read_attribute(:oppurtunity_type)) | |
end | |
diff --git a/spec/models/inbox/recruiter_message_spec.rb b/spec/models/inbox/recruiter_message_spec.rb | |
index d611e38..e74d960 100644 | |
--- a/spec/models/inbox/recruiter_message_spec.rb | |
+++ b/spec/models/inbox/recruiter_message_spec.rb | |
@@ -23,6 +23,13 @@ describe Inbox::RecruiterMessage do | |
receipt.notification.should be_valid | |
end | |
+ it 'performs a doc_mail_debit after save' do | |
+ create(:recruiter_credit, recruiter_organization: recruiter_subscription.recruiter_organization, amount: 3) | |
+ Recruiter::Subscription.any_instance.stub(:active?).and_return(true) | |
+ receipt.notification.deliver | |
+ Recruiter::Credit.last.amount.should eq(-1) | |
+ end | |
+ | |
describe "#available_credits" do | |
it "adds an error to base with no available credits" do | |
Recruiter::Credit.stub!(:balance).and_return(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment