Hello, when I try to run my tests with capybara, I get that error, I do not understand why, what am I doing wrong?
this is the error:
Failures:
1) Users editar usuario edicion exitosa
Failure/Error: click_button 'Grabar'
Capybara::InfiniteRedirectError:
redirected more than 100 times, check for infinite redirects.
This is my test tees
require 'rails_helper'
RSpec.feature "Users", type: :feature do
context "crear nuevo usuario" do
scenario "creacion exitosa" do
user= FactoryBot.create(:user, :super_usuario)
login_as(user, :scope => :user)
visit new_user_path
within('#frm_user') do
fill_in('user_user', with: 'elusuario')
fill_in('user_name', with: 'Jhon Smith')
fill_in('user_email', with: '[email protected]')
select('Cliente', from: 'user[roles]')
fill_in('user_password', with: '123456')
end
click_button 'Grabar'
expect(page).to have_content('Jhon Smith')
end
end
context "editar usuario" do
scenario "edicion exitosa" do
user= FactoryBot.create(:user, :super_usuario)
login_as(user, :scope => :user)
visit edit_user_path(user)
within('#frm_user') do
fill_in('user_user', with: 'marco')
fill_in('user_name', with: 'Marco Smith')
fill_in('user_email', with: '[email protected]')
select('Cliente', from: 'user[roles]')
end
click_button 'Grabar'
expect(page).to have_content('Marco Smith')
end
scenario "fallo al actualizar" do
end
end
context "eliminar usuario" do
end
end
This is my controller
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy], :except => :change_password
add_breadcrumb "users", :users_path
# GET /users
# GET /users.json
def index
add_breadcrumb "", users_path
@users = User.all
authorize @users
end
# GET /users/1
# GET /users/1.json
def show
add_breadcrumb @user.id, user_path(@user)
end
# GET /users/new
def new
add_breadcrumb "New", new_user_path
@flag_nuevo_usuario=true
@user = User.new
authorize @user
end
# GET /users/1/edit
def edit
add_breadcrumb @user.id, edit_user_path(@user)
end
# POST /users
# POST /users.json
def create
@flag_nuevo_usuario=true
@user = User.new(user_params)
authorize @user
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'Usuario creado satisfactoriamente.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params_update)
format.html { redirect_to @user, notice: 'Usuario fue actualizado.' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'Usuario ha sido eliminado.' }
format.json { head :no_content }
end
end
def show_modal_change_password
set_user
end
def change_password
set_user
respond_to do |format|
if @user.update(change_password_params)
format.js
else
mensaje="Error: Ocurrio un error al actualizar el password"
format.js{render :js => "alert('#{mensaje}');"}
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
authorize @user
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:user,:name,:roles, :email, :password)
end
def user_params_update
params.require(:user).permit(:user,:name,:roles, :email)
end
def change_password_params
params.permit(:password)
end
end
This is my use_policy class
class UserPolicy < AdminPolicy
def show_modal_change_password?
es_super_usuario?
end
def change_password?
es_super_usuario?
end
end
Which inherits from AdminPolicy
class AdminPolicy < ApplicationPolicy
def index?
es_super_usuario? || es_gerente_general?
end
def show?
#scope.where(:id => record.id).exists?
es_super_usuario?
end
def create?
es_super_usuario?
end
def new?
create?
end
def update?
es_super_usuario?
end
def edit?
update?
end
def destroy?
es_super_usuario?
end
end
This is my error trace:
Failures:
1) Users editar usuario edicion exitosa
Failure/Error: click_button 'Grabar'
Capybara::InfiniteRedirectError:
redirected more than 5 times, check for infinite redirects.
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/rack_test/browser.rb:46:in 'process_and_follow_redirects'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/rack_test/browser.rb:32:in 'submit'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/rack_test/form.rb:80:in 'submit'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/rack_test/node.rb:64:in 'click'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/node/element.rb:143:in 'block in click'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/node/base.rb:85:in 'synchronize'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/node/element.rb:143:in 'click'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/node/actions.rb:61:in 'click_button'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/session.rb:808:in 'block (2 levels) in <class:Session>'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/capybara-2.18.0/lib/capybara/dsl.rb:50:in 'block (2 levels) in <module:DSL>'
# ./spec/features/users_spec.rb:33:in 'block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:97:in 'block (3 levels) in <top (required)>'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/database_cleaner-1.6.1/lib/database_cleaner/generic/base.rb:16:in 'cleaning'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/database_cleaner-1.6.1/lib/database_cleaner/base.rb:98:in 'cleaning'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/database_cleaner-1.6.1/lib/database_cleaner/configuration.rb:86:in 'block (2 levels) in cleaning'
# /home/jarvis/.rvm/gems/ruby-2.3.1@rails_5_gemset/gems/database_cleaner-1.6.1/lib/database_cleaner/configuration.rb:87:in 'cleaning'
# ./spec/rails_helper.rb:96:in 'block (2 levels) in <top (required)>'