Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to setting mailchimp subscription option #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def generate_vpn_credentials
end

def add_to_newsletter
return unless Settings.mailchimp.subscription == 'true'

AddUserToNewsletterWorker.perform_async(email, :all)
end
end
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ servers:
sample_config_path: 'config/sample.server.ovpn.erb'

mailchimp:
subscription: 'true'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to manage mailchimp through env variables.
For example we can just check that api key exists.
So, basically we can check just return unless Settings.mailchimp.api_key

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reabiliti ping

api_key: <%= ENV['MAILCHIMP_API_KEY'] %>
all_clients_list_id: <%= ENV['MAILCHIMP_ALL_CLIENTS_LIST_ID'] %>

Expand Down
21 changes: 17 additions & 4 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,23 @@
end

describe 'newsletter subscription' do
it 'adds to newsletter' do
expect do
create(:user)
end.to change(AddUserToNewsletterWorker.jobs, :size).by(1)
let(:settings) { double('Settings.mailchimp') }
before { allow(Settings).to receive(:mailchimp).and_return(settings) }

context 'subscription set as true' do
before { expect(settings).to receive(:subscription).and_return('true') }

it 'adds to newsletter' do
expect { create(:user) }.to change(AddUserToNewsletterWorker.jobs, :size).by(1)
end
end

context 'subscription set as false' do
before { expect(settings).to receive(:subscription).and_return('false') }

it 'adds to newsletter' do
expect { create(:user) }.not_to change(AddUserToNewsletterWorker.jobs, :size)
end
end
end
end
Expand Down