相关疑难解决方法(0)

我怎样才能对我的默认范围进行rspec测试

我的模型有default_scope(:order =>'created_at')我的测试(rspec,factory girl,shoulda等)是:

require 'spec/spec_helper.rb'

describe CatMembership do
  context "is valid" do
    subject { Factory.build(:cat_membership) }
    it { should be_valid }
    it { should belong_to :cat}
    it { should belong_to :cat_group}
    it { should have_db_column(:start_date)}
    it { should have_db_column(:end_date)}
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby testing scope rspec default-scope

18
推荐指数
1
解决办法
8293
查看次数

测试Rails 3 Scopes有意义吗?

我有点不知所措.Rails 3中的Scopes的单元测试是否有意义?

一方面,我正在编写代码,我应该测试该代码.

但是,另一方面,基本上我的所有范围都是微不足道的.检查传递参数的一个变量几乎是我迄今为止最复杂的范围.

scope :author, proc { |author| where(:author_user_id => author }

该代码是微不足道的,并且或多或少地覆盖了实际使用范围的函数.

测试或不测试范围的最佳实践是什么?

unit-testing named-scope ruby-on-rails ruby-on-rails-3

15
推荐指数
2
解决办法
5572
查看次数