2017-01-17 14 views
0

私のコントローラーのテストを書いていますが、私がrspec ./spec/controllersを実行しているときに以下のエラーが表示されています。RSPECのActionController :: UrlGenerationErrorに問題がある

1) VersionOne::UsersController GET #actives should return all actives 
Failure/Error: get :actives 

ActionController::UrlGenerationError: 
    No route matches {:action=>"actives", :controller=>"version_one/users"} 
# ./spec/controllers/version_one/users_controller_spec.rb:13:in `block (3 levels) in <top (required)>' 

2) VersionOne::UsersController GET #archived should return all archives 
Failure/Error: get :archives 

ActionController::UrlGenerationError: 
    No route matches {:action=>"archives", :controller=>"version_one/users"} 
# ./spec/controllers/version_one/users_controller_spec.rb:23:in `block (3 levels) in <top (required)>' 

3) VersionOne::UsersController POST #create should create a new collaborator with success 
Failure/Error: post :create, params: params 

これはこれはこれはこれは私の.rspec

である私のテスト

RSpec.describe VersionOne::UsersController, type: :controller do 
    before(:all) do 
    7.times { Collaborator.build(attributes_for(:user)) } 
    8.times { Admin.build(attributes_for(:user)) } 
    5.times { Collaborator.build(attributes_for(:user)).archived! } 
    end 

    describe "GET #actives" do 
    it "should return all actives" do 
    get :actives 
    body = JSON.parse(response.body) 
    expect(response).to have_http_status(:success) 
    expect(body["pagination"]["per_page"]).to eq(20) 
    expect(body["pagination"]["total_objects"]).to eq(15) 
    end 
end 

describe "GET #archived" do 
    it "should return all archives" do 
    get :archives 
    body = JSON.parse(response.body) 
    expect(response).to have_http_status(:success) 
    expect(body["pagination"]["per_page"]).to eq(20) 
    expect(body["pagination"]["total_objects"]).to eq(5) 
    end 
end 

describe "POST #create" do 
    it "should create a new collaborator with success" do 
    params = { kind: "Collaborator", user: { name: "User", email: "[email protected]", password: "123456", cpf: "36156291830" } } 
    post :create, params: params 
    body = JSON.parse(response.body) 
    expect(response).to have_http_status(:success) 
    expect(body).to include(
     "name" => "User", 
     "cpf" => "36156291830", 
     "email" => "[email protected]", 
    ) 
    end 
    end 
end 

ある

scope 'api' do 
    scope 'v1', module: 'version_one' do 
     resources 'users' do 
     collection do 
      get 'actives' 
      get 'archives' 
     end 

     member do 
      match 'active' 
      match 'archive' 
     end 
     end 
    end 
    end 

私のルートです

class UsersController < ApiControler 
    def actives 
    users = User.actives 
    render json: users 
    end 

    def archives 
    users = User.archiveds 
    render json: users 
end 

    def create 
    user = User.build(user_params) 
    render json: user 
    end 
end 

私のコントローラであり、

--color 
--format documentation 
--require rails_helper 

が、これは何かを忘れてam'i

ENV['RAILS_ENV'] ||= 'test' 

require File.expand_path('../../config/environment', __FILE__) 

abort("The Rails environment is running in production mode!") if Rails.env.production? 

require 'spec_helper' 
require 'rspec/rails' 
require 'shoulda-matchers' 
require 'rack/test' 
require 'faker' 
require 'rake' 

ActiveRecord::Migration.maintain_test_schema! 

RSpec.configure do |config| 
    config.include FactoryGirl::Syntax::Methods 
    config.include Shoulda::Matchers::ActiveModel, type: :model 
    config.include Shoulda::Matchers::ActiveRecord, type: :model 
    config.fixture_path = "#{::Rails.root}/spec/factories" 
    config.before(:suite) do 
    DatabaseCleaner.strategy = :truncation 
    DatabaseCleaner.clean_with(:truncation) 
    end 

    config.use_transactional_fixtures = false 
    config.infer_spec_type_from_file_location! 
    config.filter_rails_from_backtrace! 

end 

私rails_helperのですか? 「 `スコープ:

答えて

1

あなたはUsersController 試してみるための名前空間がありません:あなたはまた、それが助けたApiController

+0

Api::VersionOne::ApiControllerに変更する必要があります

module Api module VersionOne class UsersController < ApiController # your code end end end 

を、しかし、私はに私のルートを変更する必要がありますapi '、module:' api '、':api''そして、それが存在しないうちに、私のコントローラをフォルダapiの中に入れてください。 – Shirow

関連する問題