Skip to content

Commit

Permalink
correcing spec to reject blank radio responses. fixing response set spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Yoon committed Jan 31, 2011
1 parent a4df8eb commit 2270fc7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/surveyor/models/response_set_methods.rb
Expand Up @@ -35,7 +35,7 @@ def reject_or_destroy_blanks(hash_of_hashes)
result
end
def has_blank_value?(hash)
hash.any?{|k,v| v.is_a?(Array) ? v.all?{|x| x.to_s.blank?} : v.to_s.blank?}
hash["answer_id"].blank? or hash.any?{|k,v| v.is_a?(Array) ? v.all?{|x| x.to_s.blank?} : v.to_s.blank?}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/response_set_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe ResponseSet do
before(:each) do
@response_set = Factory(:response_set)
@radio_response_attributes = HashWithIndifferentAccess.new({"1"=>{"question_id"=>"1", "answer_id"=>"1", "string_value"=>"XXL"}, "2"=>{"question_id"=>"2", "answer_id"=>"6"}, "3"=>{"question_id"=>"3", "answer_id"=>""}})
@radio_response_attributes = HashWithIndifferentAccess.new({"1"=>{"question_id"=>"1", "answer_id"=>"1", "string_value"=>"XXL"}, "2"=>{"question_id"=>"2", "answer_id"=>"6"}, "3"=>{"question_id"=>"3"}})
@checkbox_response_attributes = HashWithIndifferentAccess.new({"1"=>{"question_id"=>"9", "answer_id"=>"11"}, "2"=>{"question_id"=>"9", "answer_id"=>"12"}})
@other_response_attributes = HashWithIndifferentAccess.new({"6"=>{"question_id"=>"6", "answer_id" => "3", "string_value"=>""}, "7"=>{"question_id"=>"7", "answer_id" => "4", "text_value"=>"Brian is tired"}, "5"=>{"question_id"=>"5", "answer_id" => "5", "string_value"=>""}})
end
Expand Down Expand Up @@ -105,7 +105,7 @@
@response_set.should have(1).responses
ResponseSet.reject_or_destroy_blanks({"2"=>{"question_id"=>"1", "id"=> r.id, "answer_id"=>[""]}}).should == {"2"=>{"question_id"=>"1", "id"=> r.id, "_destroy"=> "true", "answer_id"=>[""]}}
@response_set.update_attributes(:responses_attributes => {"2"=>{"question_id"=>"1", "id"=> r.id, "_destroy"=> "true", "answer_id"=>[""]}}).should be_true
@response_set.reload.should have(1).responses
@response_set.reload.should have(0).responses
end
end

Expand Down

0 comments on commit 2270fc7

Please sign in to comment.