logo
Tags down

shadow

RSpec sessions controllers - user with invalid params without devise


By : Satu Mare
Date : October 18 2020, 08:10 PM
I hope this helps . I've got a simple message app to learn RSpec where one user can create message to another user (only logged users can write messages). I didn't used devise or FactoryBot, this app is as simple as possible just for rspec learning. , In your test you expect redirect response:
code :
expect(response).to redirect_to(action: 'new')
render 'new'
expect(response).to render_template(:new)


Share : facebook icon twitter icon

Testing controllers in Rails 3 with Devise and RSpec


By : user2466519
Date : March 29 2020, 07:55 AM
With these it helps EDIT (totally wrong first attempt removed)
Calling as_null_object essentially tells the mock to accept all messages that aren't stubbed and just return self. So when you call
code :
  def mock_users(stubs={})
    @user = User.create(stubs)
  end

Rails 4 + Rails-API + RSpec + Devise - Trouble testing controllers with custom devise routes


By : NonymusEntity
Date : March 29 2020, 07:55 AM
this will help I think I may have solved the issue. It seems I had to add in a devise_for outside the api namespace blocks:
code :
MyApplication::Application.routes.draw do

  devise_for :users, skip: [:sessions, :passwords, :registrations]

  namespace :api, defaults: { format: :json } do
    namespace :v1 do
      devise_scope :user do
        post 'sessions' => 'sessions#create', :as => 'login'
      end
    end
  end
end

Writing rspec for controllers with params?


By : user3522096
Date : March 29 2020, 07:55 AM
this one helps. If I understand your question correctly, you can try approach like this:
code :
RSpec.describe <controllername>, :type => :controller do
  describe "GET my_method" do
    context "param 'c' is provided"
      get :my_method, { "c" => "sample value" }
      expect(response).to have_http_status(:success)
    end

    context "param 'e' is provided"
      get :my_method, { "e" => "sample value" }
      expect(response).to have_http_status(:success)
    end
  end
end

Rails 4 with Devise, testing Controllers with Rspec


By : user3605399
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The resource you have in your spec is already loaded and doesn't change when the row is deleted from the DB. You can do a couple things:
Test that the resource is gone from the DB
code :
expect(Resource.find_by(id: resource.id)).to be_nil
expect { delete :destroy, id: resource.id }.to change(Resource, :count).by(-1)

How to test Devise Sessions Controller with RSpec


By : kroberso
Date : March 29 2020, 07:55 AM
wish helps you You know that Devise offers RSpec test helpers for controller specs. However, in request specs, they will not work.
Here is a solution for request specs, adapted from the Devise wiki. We will simply use Warden's test helpers – you probably already load them for your Cucumber tests.
shadow
Privacy Policy - Terms - Contact Us © voile276.org