运行RSpec时出现此错误,我不知道它对我有什么要求?我不知道为什么说permit
未定义?这1:string
事发生了什么?如果有人有想法,我很乐意知道。为清楚起见,这是我的错误和代码。
CONTROLLER:
class SubscribersController < ApplicationController
def index
@subscriber = Subscriber.all
end
def new
@subscriber = Subscriber.new
end
def create
@subscriber = Subscriber.create(subscriber_params)
if @subscriber.save
flash[:notice] = "Subscriber Has Been Successfully Created"
redirect_to new_subscriber_path(:subscriber)
else
render "new"
end
end
def search
@subscriber = Subscriber.new
end
def visit
@subscriber = Subscriber.find_by_phone_number(params[:phone_number])
if @subscriber
@subscriber.visit += 1
@subscriber.save
flash[:notice] = "thanks"
redirect_to subscribers_search_path(:subscriber)
else
render "search"
end
end
private
def subscriber_params
params.require(:subscriber).permit(:first_name, :last_name, :email, :phone_number)
end
end
TEST:
require "rails_helper"
describe SubscribersController do
include Devise::TestHelpers
let(:user) { FactoryGirl.create(:user)}
it "creates a new subscriber" do
sign_in(user)
subscriber = FactoryGirl.create(:subscriber)
expect { post :create, :subscriber => subscriber }.to change(Subscriber, :count).by(1)
end
end
SUBSCIRBER OBJECT
答案 0 :(得分:2)
我认为这里的问题是,当您在规范中提交请求时,您提供的是ruby对象而不是值的哈希值。请尝试使用以下内容:
subscriber = FactoryGirl.attributes_for(:subscriber)
expect { post :create, :subscriber => subscriber }.to ...