Je ne peux pas sembler obtenir ma tête sur la façon de faire des demandes de poste pour tester une URL dans les tests de spécifications de demande, voici le code de testrails demande spec après syntaxe
RSpec.describe "Certifications", type: :request do
describe "denies public access" do
it "for new certification form" do
get new_certification_path
expect(response).to redirect_to new_user_session_path
end
it "for creating certification" do
certification_attributes = FactoryGirl.attributes_for :certification
expect {
post "/certifications", { certification: certification_attributes }
}.to_not change(Certification, :count)
expect(response).to redirect_to new_user_session_path
end
end
end
Ce qui donne l'erreur
1) Certifications denies public access for creating certification
Failure/Error: post "/certifications", { certification: certification_attributes }
ArgumentError:
unknown keyword: certification
J'ai essayé le :certifications => certification_attributes
, fondamentalement je ne peux pas obtenir la tête sur comment passer des params.
Le contrôleur à l'essai est, en ajoutant seulement des méthodes pertinentes à ce poste.
class CertificationsController < ApplicationController
skip_before_action :authenticate_user!, if: :skip_user_authentication
before_action :set_certification, only: [:show, :edit, :update, :destroy]
# GET /certifications
# GET /certifications.json
def index
@certifications = Certification.all
end
# GET /certifications/1
# GET /certifications/1.json
def show
end
# GET /certifications/new
def new
@certification = Certification.new
end
# POST /certifications
# POST /certifications.json
def create
@certification = Certification.new(certification_params)
respond_to do |format|
if @certification.save
format.html { redirect_to @certification, notice: 'Certification was successfully created.' }
format.json { render :show, status: :created, location: @certification }
else
format.html { render :new }
format.json { render json: @certification.errors, status: :unprocessable_entity }
end
end
end
protected
def skip_user_authentication
request.format.json? && (action_name.eql?('show') || (action_name.eql?('index')))
end
end
Je suis en train d'affirmer le comportement de permettre à toutes les méthodes sauf certifications.json
ou certifications/1.json
pour ne pas exiger l'authentification, il existe d'autres tests qui accèdent à ces URL et ils passent. La partie de s'assurer qu'il ne permet aucune autre demande est où je suis coincé. J'utilise Devise avec Omnitauth Google OAuth2 pour l'authentification dans cette application.
certification_attributes
{
:name=>"Foundation Certification",
:description=>"Foundation Certification",
:terms=>"Foundation Certification",
:seo_meta_keywords=>["laaa", "lalala certifications"],
:seo_meta_description=>"Foundation Certifications"
}
Quelle ligne est à l'origine de l'erreur? –
De plus, à quoi ressemble 'certification_params'? –
@MattGibson ajouté détails de l'erreur –