Factory-girl create that bypasses my model validation

后端 未结 9 2155
既然无缘
既然无缘 2021-01-30 06:31

I am using Factory Girl to create two instances in my model/unit test for a Group. I am testing the model to check that a call to .current returns only the \'current\' groups ac

9条回答
  •  温柔的废话
    2021-01-30 06:43

    This isn't very specific to FactoryGirl, but you can always bypass validations when saving models via save(:validate => false):

    describe ".current" do
      let!(:current_group) { FactoryGirl.create(:group) }
      let!(:old_group) {
        g = FactoryGirl.build(:group, :expiry => Time.now - 3.days)
        g.save(:validate => false)
        g
      }
    
      specify { Group.current.should == [current_group] }
    end
    

提交回复
热议问题