Cameron Bass Cameron Bass - 5 months ago 25
Ruby Question

undefined method `permit' for "1":String - RSPEC

I fell a bit ridiculous but I really have no idea what this error is trying to tell me? I'm new to rspec and this is a new one for me. I'll post my code for clarity - ERROR: undefined method `permit' for "1":String|

CONTROLLER:

def subscriber_params
params.require(:subscriber).permit(:first_name, :last_name, :email, :phone_number)
end


SPEC:
require "rails_helper"

describe SubscribersController do
include Devise::TestHelpers

let(:user) { FactoryGirl.create(:user) }
let(:subscriber) { FactoryGirl.create(:subscriber) }

it "creates a new comment" do
sign_in(user)
comment = FactoryGirl.attributes_for(:comment)

expect { post :create, subscriber: subscriber, comment: comment }.to change(Comment, :count).by(1)
end
end


ERROR:

enter image description here

Answer

change:

let(:subscriber) { FactoryGirl.create(:subscriber) }

to:

let(:subscriber) { FactoryGirl.attributes_for(:subscriber) }

Because you want to add the subscriber's attributes to the request not an instance of subscriber.

Comments