這裏是我的控制器測試( 「投機/控制器/ API/tasks_controller_spec.rb」)Rspec的控制器測試掛
require 'spec_helper'
describe Api::TasksController do
before :each do
@quadros = create :cat
@task = Task.new(:content => "Example task for #api")
@quadros.add_task(@task)
end
describe "GET index" do
it "returns a list of all user's tasks" do
get :index, :format => 'json'
expect(response).to eq(User.first.all_tasks)
end
end
end
這裏是我的API :: BaseController
class Api::BaseController < ApplicationController
respond_to :json
skip_before_filter :authenticate_user!
end
和API :: TasksController
class Api::TasksController < Api::BaseController
def index
@tasks = User.first.all_tasks
respond_with @tasks.to_json
end
end
我的其他測試運行良好。
當我運行的API測試,它執行塊之前,發出請求爲JSON,然後掛在該查詢:
Processing by Api::TasksController#index as JSON
User Load (0.3ms) SELECT `users`.* FROM `users` LIMIT 1
Tag Load (0.3ms) SELECT `tags`.* FROM `tags` WHERE (user_id = 418 AND parent_tag_id IS NOT NULL)
Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`id` IN (NULL)
Tag Load (0.3ms) SELECT `tags`.* FROM `tags` WHERE (user_id = 418 AND parent_tag_id IS NULL)
Task Load (0.7ms) SELECT tasks.* FROM `tasks` JOIN tag_tasks on tasks.id = tag_tasks.task_id WHERE (tag_tasks.tag_id IN (301) OR creator_id = 418) GROUP BY tasks.id ORDER BY tasks.created_at DESC
Completed 200 OK in 99ms (Views: 0.1ms | ActiveRecord: 0.0ms)
User Load (0.3ms) SELECT `users`.* FROM `users` LIMIT 1
Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE (user_id = 418 AND parent_tag_id IS NOT NULL)
Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE `tags`.`id` IN (NULL)
Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE (user_id = 418 AND parent_tag_id IS NULL)
Task Load (0.7ms) SELECT tasks.* FROM `tasks` JOIN tag_tasks on tasks.id = tag_tasks.task_id WHERE (tag_tasks.tag_id IN (301) OR creator_id = 418) GROUP BY tasks.id ORDER BY tasks.created_at DESC
凡只會永遠地坐着。
任何想法,爲什麼這可能發生?