Skip to content

Commit

Permalink
Merge pull request #754 from mcclaskc/master
Browse files Browse the repository at this point in the history
Allow one-time skipping of activation-related emails for new users.
  • Loading branch information
arnvald committed Jun 2, 2016
2 parents a7d9786 + 12f712a commit c2ccad5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sorcery/model/submodules/user_activation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def activate!
sorcery_adapter.save(:validate => false, :raise_on_failure => true)
end

attr_accessor :skip_activation_needed_email, :skip_activation_success_email

protected

# called automatically after user initial creation.
Expand All @@ -127,14 +129,14 @@ def send_activation_success_email?
!external? && (
!(sorcery_config.activation_success_email_method_name.nil? ||
sorcery_config.activation_mailer_disabled == true)
)
) && !skip_activation_success_email
end

def send_activation_needed_email?
!external? && (
!(sorcery_config.activation_needed_email_method_name.nil? ||
sorcery_config.activation_mailer_disabled == true)
)
) && !skip_activation_needed_email
end

def prevent_non_active_login
Expand Down
43 changes: 43 additions & 0 deletions spec/shared_examples/user_activation_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,48 @@

expect(ActionMailer::Base.deliveries.size).to eq old_size
end

context "activation_needed_email is skipped" do
before(:each) do
@user = build_new_user
@user.skip_activation_needed_email = true
end

it "does not send the user an activation email" do
old_size = ActionMailer::Base.deliveries.size

@user.sorcery_adapter.save(:raise_on_failure => true)

expect(ActionMailer::Base.deliveries.size).to eq old_size
end

it "does not call send_activation_needed_email! method of user" do
expect(@user).to receive(:send_activation_needed_email!).never

@user.sorcery_adapter.save(:raise_on_failure => true)
end

it "calls send_activation_success_email! method of user on activation" do
expect(@user).to receive(:send_activation_success_email!).never

@user.activate!
end
end

context "activation_success_email is skipped" do
before(:each) do
@user = build_new_user
@user.skip_activation_success_email = true
end

it "does not send the user an activation success email on successful activation" do
old_size = ActionMailer::Base.deliveries.size

@user.activate!

expect(ActionMailer::Base.deliveries.size).to eq old_size
end
end
end

context "mailer has been disabled" do
Expand All @@ -149,6 +191,7 @@

it "does not send the user an activation email" do
old_size = ActionMailer::Base.deliveries.size
create_new_user

expect(ActionMailer::Base.deliveries.size).to eq old_size
end
Expand Down

0 comments on commit c2ccad5

Please sign in to comment.