Skip to content

Instantly share code, notes, and snippets.

@ohammersmith
Created February 2, 2009 18:20
Show Gist options
  • Select an option

  • Save ohammersmith/57022 to your computer and use it in GitHub Desktop.

Select an option

Save ohammersmith/57022 to your computer and use it in GitHub Desktop.
{:country=>"United States", :state=>"Delaware", :keyword_filters_attributes=>{"new_1"=>{:any=>true, :keywords=>"Lorem ipsum dolor sit amet,", :must_have=>false, :weight=>4}, "new_2"=>{:any=>true, :keywords=>"Lorem ipsum dolor sit amet,", :must_have=>false, :weight=>8}}, :city=>"Rotorua", :range=>nil, :postal_code=>"03887"}
# normalized_nested_attributes branch tests, these will fail when I switch rails off to another branch
it "should let me create a new Criterion with Filters already in the attributes hash" do
@criterion_count = Criterion.count
@filter_count = Filter.count
@keyword_filter_count = KeywordFilter.count
@criterion_attrs = Factory.attributes_for(:criterion)
@criterion_attrs[:keyword_filters_attributes] = {}
# note the keys new_1, new_2 do actually matter. Presumably that's how it knows which ones are new vs existing.
@criterion_attrs[:keyword_filters_attributes]["new_1"] = Factory.attributes_for(:keyword_filter)
@criterion_attrs[:keyword_filters_attributes]["new_2"] = Factory.attributes_for(:keyword_filter)
@criterion = Criterion.create(@criterion_attrs)
Criterion.count.should == @criterion_count + 1
Filter.count.should == @filter_count + 2
KeywordFilter.count.should == @keyword_filter_count + 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment