I have a user model
class User < ActiveRecord::Base has_many :languages, :dependent => :destroy accepts_nested_attributes_for :languages, :reject_if => lambda { |l| l[:name].blank? } end
I want to check the reject_if part with RSpec 2.0.0. I currently have two simple test cases for this.
it "should not save language without name by accepts_nested_attributes" do lambda { @user.update_attributes!("languages_attributes"=>{"0"=>{}}) }.should_not change(Language, :count) end it "should save language with name by accepts_nested_attributes" do lambda { @user.update_attributes!("languages_attributes"=>{"0"=>{"name"=>"lang_name"}}) }.should change(Language, :count).by(1) end
However, I'm pretty new to testing, and it looks really weird. Interestingly, is this the correct way to check reject_if? And is there a better way to do this?
ruby-on-rails rspec
Tadas tamosauskas
source share