【发布时间】:2014-11-26 20:07:03
【问题描述】:
我在使用序列化程序 (Rspec) 处理我的请求时遇到了 undefined method 'authenticate' for nil:NilClass。
api/users_controller_spec.rb
require 'rails_helper'
describe Api::V1::UsersController, type: :controller do
describe "GET #show" do
context "with valid credentials" do
let!(:application) { create(:doorkeeper_application) } # OAuth application
let!(:user) { create(:user) }
let!(:token) { create(:doorkeeper_access_token, application_id: application.id, resource_owner_id: user.id) }
before do
allow(controller).to receive(:doorkeeper_token) {token}
end
context 'and valid request' do
before(:each) do
get :show, format: :json
@json = JSON.parse(response.body)
end
it "returns the user with 'id'" do
expect(@json["id"]).to_not be_nil
end
end
end
end
end
serializers/user_serializer.rb
class UserSerializer < ActiveModel::Serializer
attributes :id, :uid, :name, :email
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 rspec devise active-model-serializers