Sha256: 84ff04a0c2d8cd1c2389d472081ebfb9fd4cf91afdc3f4247b6bc8e9b2a52863

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

require "<%= @helper_file %>"
require "support/features/clearance_helpers"

RSpec.feature "Visitor resets password" do
  before { ActionMailer::Base.deliveries.clear }
<% if defined?(ActiveJob) -%>

  around do |example|
    original_adapter = ActiveJob::Base.queue_adapter
    ActiveJob::Base.queue_adapter = :inline
    example.run
    ActiveJob::Base.queue_adapter = original_adapter
  end
<% end -%>

  scenario "by navigating to the page" do
    visit sign_in_path

    click_link I18n.t("sessions.form.forgot_password")

    expect(current_path).to eq new_password_path
  end

  scenario "with valid email" do
    user = user_with_reset_password

    expect_page_to_display_change_password_message
    expect_reset_notification_to_be_sent_to user
  end

  scenario "with non-user account" do
    reset_password_for "unknown.email@example.com"

    expect_page_to_display_change_password_message
    expect_mailer_to_have_no_deliveries
  end

  private

  def expect_reset_notification_to_be_sent_to(user)
    expect(user.confirmation_token).not_to be_blank
    expect_mailer_to_have_delivery(
      user.email,
      "password",
      user.confirmation_token
    )
  end

  def expect_page_to_display_change_password_message
    expect(page).to have_content I18n.t("passwords.create.description")
  end

  def expect_mailer_to_have_delivery(recipient, subject, body)
    expect(ActionMailer::Base.deliveries).not_to be_empty

    message = ActionMailer::Base.deliveries.any? do |email|
      email.to == [recipient] &&
        email.subject =~ /#{subject}/i &&
        email.html_part.body =~ /#{body}/ &&
        email.text_part.body =~ /#{body}/
    end

    expect(message).to be
  end

  def expect_mailer_to_have_no_deliveries
    expect(ActionMailer::Base.deliveries).to be_empty
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
clearance-1.16.0 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
clearance-1.15.1 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
clearance-1.15.0 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
clearance-1.14.2 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
clearance-1.14.1 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
clearance-1.14.0 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt
clearance-1.13.0 lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt