【发布时间】:2010-09-04 11:42:20
【问题描述】:
我在为我的视图和请求创建规范时遇到问题。 我的一些控制器使用 named_scope,如下所示:
#projects_controller.rb
@projects = Project.with_user( current_user)
## project.rb:
scope :with_user, lambda {|u| {:joins => :client, :conditions => {:clients => {:user_id => u.id} } }}
但以下规范给出了错误:
规格:
describe "GET /projects" do
it "works! (now write some real specs)" do
get projects_path
end
错误:
6) Projects GET /projects works! (now write some real specs)
Failure/Error: get projects_path
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
# ./app/models/project.rb:9:in `block in <class:Project>'
# /home/mping/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.0.rc/lib/active_record/named_scope.rb:95:in `call'
# /home/mping/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.0.rc/lib/active_record/named_scope.rb:95:in `block in scope'
# ./app/controllers/projects_controller.rb:4:in `index'
我的视图规范中有类似的错误:
4) projects/show.haml renders attributes in <p>
Failure/Error: render
undefined method `name' for nil:NilClass
# /home/mping/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0.rc/lib/active_support/whiny_nil.rb:48:in `method_missing'
# ./app/views/projects/show.haml:4:in `_app_views_projects_show_haml___1706343108022772066_34134280__4548622860215298334'
在我看来,我需要对 authlogic 定义的 current_user 方法进行存根,以便能够前进。我如何指定视图和请求?谢谢
【问题讨论】:
-
切换到设计...
标签: ruby-on-rails ruby-on-rails-3 rspec authlogic bdd