Reputation: 948
I'm using ruby v1.9.3 and factory_girl v2.2 and trying to setup traits. But am getting this error when I try to use my trait. Is it because of the ruby version I am using?
Failure/Error: let!(:notification) { create(:notification, :confirmable) }
NoMethodError:
undefined method `symbolize_keys' for :confirmable:Symbol
# ./spec/controllers/api/v1/sms_controller_spec.rb:13:in `block (3 levels) in <top (required)>
This is my factory:
FactoryGirl.define do
factory :notification do
smssid { Faker::Number.number(10) }
msg { Faker::Lorem.sentence(3) }
to { Faker::PhoneNumber.phone_number }
trait :confirmable do
confirmable "true"
end
end
end
spec:
require 'spec_helper'
describe Api::V1::SmsController do
let!(:user) { create(:user) }
describe "GET /api/v1/user/sms" do
let!(:notification) { FactoryGirl.create(:notification, :confirmable) }
context "a user replies to a confirmation with c" do
it "does something" do
get :incomming_message, :sid => notification.smssid,
:to => notification.to,
:from => user.phone_number,
:body => "c",
:status => "recieved",
:format => :json
notification.reload
notification.confirmed.should eq(true)
end
end
end
end
*** Edit, updated with my spec file
Upvotes: 3
Views: 735
Reputation: 1066
No, the version of Ruby you are using has nothing to do with symbolize_keys
because it is not part of the the Ruby core. Neither 1.9.3 nor 2.2.2 contain it. Rather, symbolize_keys
is an ActiveSupport extension to the Hash class. You must have Active support loaded to get this to work. See: Rails-4.2.5 : Object::HashWithIndifferentAccess < Hash.
Since this is a RoR question, which I missed (mea culpa), the problem evidently lies with the declaration of confirmable
as a symbol rather than a hash. However, the version of Ruby in use has nothing to do with the problem in either case.
Upvotes: -1