Permalink
Browse files

subscribe user to mailchimp after signup

  • Loading branch information...
hstove committed Dec 31, 2013
1 parent 0174f78 commit 4961da35b1e97906a08da0b55d467d1823582c7b
Showing with 28 additions and 0 deletions.
  1. +14 −0 app/models/user.rb
  2. +14 −0 spec/models/user_spec.rb
View
@@ -34,6 +34,8 @@ def enrolled_courses
if Rails.env.production? && !(how_to = Course.find_by_id(117)).blank?
Rails.configuration.queue << Afterparty::BasicJob.new(self, :enroll, how_to)
end
job = Afterparty::BasicJob.new(self, :subscribe_to_mailchimp)
Rails.configuration.queue << job
end
validates_presence_of :username, :email
@@ -167,4 +169,16 @@ def generate_token(column)
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
def subscribe_to_mailchimp testing=false
return true if (Rails.env.test? && !testing)
list_id = ENV['MAILCHIMP_ULUDUM_LIST_ID']
response = Rails.configuration.mailchimp.lists.subscribe({
id: list_id,
email: {email: email},
double_optin: false,
})
response
end
end
View
@@ -173,4 +173,18 @@ def new_user(attributes = {})
last_email.to.should include (user.email)
end
end
describe "#subscribe_to_mailchimp" do
let(:user) { create(:user) }
it "calls mailchimp correctly" do
opts = {
email: {email: user.email},
id: ENV['MAILCHIMP_ULUDUM_LIST_ID'],
double_optin: false,
}
clazz = Rails.configuration.mailchimp.lists.class
clazz.any_instance.should_receive(:subscribe).with(opts).once
user.send(:subscribe_to_mailchimp, true)
end
end
end

0 comments on commit 4961da3

Please sign in to comment.