logo
down
shadow

Turn off email sends from Devise in test (Rspec)


Turn off email sends from Devise in test (Rspec)

By : Santhosh Damodaran
Date : November 22 2020, 02:59 PM
wish helps you When delivery_method is set to test, everything is still run the same, with the only difference being the message is not sent to SMTP.
So, in your case Redis is still required for test emails, as Resque is still going to process them, and depends on Redis to queue them.
code :


Share : facebook icon twitter icon
How to test Devise in a Controller RSpec, error: undefined method `assign' for #<RSpec::Core::ExampleGroup::Nested_1:

How to test Devise in a Controller RSpec, error: undefined method `assign' for #<RSpec::Core::ExampleGroup::Nested_1:


By : adlbeat
Date : March 29 2020, 07:55 AM
seems to work fine Rspec has changed a bit, it's now using assigns.
Doc here.
rail3/rspec/devise: rspec controller test fails unless I add a dummy=subject.current_user.inspect

rail3/rspec/devise: rspec controller test fails unless I add a dummy=subject.current_user.inspect


By : rebsp
Date : March 29 2020, 07:55 AM
hop of those help? What a struggle! Thank you Robin, I've been googling on this for hours and finally saw your post; now my controller tests are working :)
To add to your answer, I figured out how to get the devise session into the valid_session hash, which allows the controller tests to run properly as generated by rails.
code :
def valid_session
  {"warden.user.user.key" => session["warden.user.user.key"]}
end
Devise Rspec registration controller test failing on update as if it was trying to confirm email address

Devise Rspec registration controller test failing on update as if it was trying to confirm email address


By : Koe Varken
Date : March 29 2020, 07:55 AM
this one helps. This works. holtkampw for seeing what I wasn't! I put some extra code in there just to double check and everything is well!
code :
it "should change the user's display name" do
  subject.current_user.should_not be_nil
  @attr = { :email => @user.email, :display_name => "Test", :current_password => @user.password }
  puts "Old display name: " + subject.current_user.display_name
  put :update, :id => subject.current_user, :user => @attr
  subject.current_user.reload
  response.should redirect_to(root_path)
  subject.current_user.display_name == @attr[:display_name]
  puts "New display name: " + subject.current_user.display_name
end
Rails 4 + Devise: How to write a test for Devise Reset Password without RSpec?

Rails 4 + Devise: How to write a test for Devise Reset Password without RSpec?


By : Brad Olson
Date : March 29 2020, 07:55 AM
Does that help I figured out that you need to reload the user upon sending the password reset email and when putting the /user/password route. You also need to get the password token from the email as it is different from the one stored in the database.
code :
require 'test_helper'

class ResetPasswordTest < ActionDispatch::IntegrationTest
  setup do
    @user = users(:example)
  end

  test "reset user's password" do 
    # store old encrypted password
    old_password = @user.encrypted_password

    # check to ensure mailer sends reset password email
    assert_difference('ActionMailer::Base.deliveries.count', 1) do
      post user_password_path, user: {email: @user.email}
      assert_redirected_to new_user_session_path
    end

    # Get the email, and get the reset password token from it
    message = ActionMailer::Base.deliveries[0].to_s
    rpt_index = message.index("reset_password_token")+"reset_password_token".length+1
    reset_password_token = message[rpt_index...message.index("\"", rpt_index)]

    # reload the user and ensure user.reset_password_token is present
    # NOTE: user.reset_password_token and the token pulled from the email
    # are DIFFERENT
    @user.reload
    assert_not_nil @user.reset_password_token

    # Ensure that a bad token won't reset the password
    put "/users/password", user: {
      reset_password_token: "bad reset token", 
      password: "new-password", 
      password_confirmation: "new-password",
    }

    assert_match "error", response.body
    assert_equal @user.encrypted_password, old_password

    # Valid password update
    put "/users/password", user: {
      reset_password_token: reset_password_token, 
      password: "new-password", 
      password_confirmation: "new-password",
    }

    # After password update, signed in and redirected to root path
    assert_redirected_to root_path

    # Reload user and ensure that the password is updated.
    @user.reload
    assert_not_equal(@user.encrypted_password, old_password)
  end

end
How to test devise mail delivery with devise, rspec, capybara, and mailspec

How to test devise mail delivery with devise, rspec, capybara, and mailspec


By : felista wangui
Date : March 29 2020, 07:55 AM
hope this fix your issue Make sure you have this set in your you have this set in config/environments/test.rb:
Related Posts Related Posts :
  • Redirect User to Signup
  • Can I store IP addresses as integers?
  • How to parse a parameter in a URI for use in a controller?
  • RSpec, ActiveJob, Sidekiq: Avoid jobs from being fired when testing another job?
  • Ruby on Rails Titleize Underscore,Hyphenated and Single Quote Name
  • How do I assign a method to a variable?
  • Rails runs a different application to current path
  • rails form for model select box with 1-dimensional data
  • ActiveModel::MissingAttributeError in Rails4 Controller #create
  • Rails + Devise - Sending email to email + username in array
  • Paperclip, getting "undefined method error" :photo
  • How to completely delete a DB on Ruby on Rails?
  • Active Model Serializer - How do I include an attribute conditionally? Rails
  • Rails Fake-S3 on CircleCI Connection refused
  • Insert a variable for a label in Rails
  • Filter chain halted as :require_no_authentication rendered or redirected
  • Public Activity - Creating activities based on certain attribute changes
  • Attributes method explanation
  • Rails 4 Bootstrap DatePicker class today not working
  • Mongoid: Change(rename) foreign_key name without loosing data
  • Setting up controller and its actions for Admin login only, not for a Users?
  • How do I map an association through a model's parents if it can only belong to one of them?
  • How to use the HAML t() helper in RoR
  • How do I output a json dates array with RABL
  • Why does this FTP block read operation throw EOFError?
  • prawn rails download on open
  • Rails 4 deeply nested content tags and strings
  • Sending mail with Rails 4 in development environment
  • Mapping `has_many` in active admin
  • Rails - Use nested form to create new records
  • How to integrate elasticsearch with rails application specifically using "Elasticsearch" gem
  • Querying double has_many :through association
  • how to give whitespace in ruby slim
  • Mongoid, get distance from models in kilometers
  • can I get a data from file only one time in my gem similar to config/initializers in rails?
  • Calling a method from another controller in rails
  • Video content type is invalid in paperclip-ffmpeg
  • Website Speed With Heroku
  • adding Belongs to without "nil" in rails
  • Cloudfront returning 401 in response to requests
  • Should you use belongs_to if belonging to the object is optional?
  • Ordering a rails model with string outline notation
  • Ruby - Merge two arrays and remove values that have duplicate
  • Rails 4 - Using PUT instead of PATCH for updates
  • Rails last day of last week bug?
  • Mongodb querying for aggregation with count of multiple values
  • Bundler throws an error while creating rails new APP
  • Rails 4 - Devise: getting ActionController::UnknownFormat on signup
  • activeadmin: link_to in a helper does not appear in view
  • Virtual model attribute which links to a record from associated model
  • Travis CI cant resolve association in rails
  • How to add a custom route, controller, and action in Ruby on Rails?
  • Rails 4 session is not updated between requests
  • Input number multiplies as a string instead of number - Rails 4
  • Get enqueued_at inside scheduled Sidekiq job?
  • Update args of a scheduled job
  • Ruby on Rails, SQL Server order by and comparison
  • Devise Model unable to Work
  • Switching Heroku app to server in other region
  • Controller action for link shortening
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co