Permalink
Browse files

Cleaned up the code a bit

  • Loading branch information...
1 parent c709a73 commit 25717917c5eca9aabddfedb486aae1e2b9f9a072 @estei estei committed Oct 21, 2011
Showing with 11 additions and 19 deletions.
  1. +9 −12 lib/couchrest/model/properties.rb
  2. +2 −7 spec/unit/base_spec.rb
@@ -120,7 +120,7 @@ def directly_set_attributes(hash, mass_assign = false)
end
end
- assign_multiparameter_attributes(multi_parameter_attributes, hash) unless multi_parameter_attributes.length == 0
+ assign_multiparameter_attributes(multi_parameter_attributes, hash) unless multi_parameter_attributes.empty?
end
def directly_set_read_only_attributes(hash)
@@ -133,25 +133,22 @@ def directly_set_read_only_attributes(hash)
end
end
- def assign_multiparameter_attributes(pairs, attrib_hash)
+ def assign_multiparameter_attributes(pairs, hash)
execute_callstack_for_multiparameter_attributes(
- extract_callstack_for_multiparameter_attributes(pairs),
- attrib_hash
- )
+ extract_callstack_for_multiparameter_attributes(pairs), hash
+ )
end
- def execute_callstack_for_multiparameter_attributes(callstack, attrib_hash)
+ def execute_callstack_for_multiparameter_attributes(callstack, hash)
callstack.each do |name, values_with_empty_parameters|
if self.respond_to?("#{name}=")
- s = send("#{name}=", values_with_empty_parameters)
- unless s.is_a?(Hash)
- attrib_hash.reject! do |key, value|
- key.include?(name.to_s)
- end
+ casted_attrib = send("#{name}=", values_with_empty_parameters)
+ unless casted_attrib.is_a?(Hash)
+ hash.reject { |key, value| key.include?(name.to_s)}
end
end
end
- attrib_hash
+ hash
end
def extract_callstack_for_multiparameter_attributes(pairs)
View
@@ -116,17 +116,12 @@ def set_name; self.name = "foobar"; end
it "should still create a model if there are invalid attributes" do
@obj = WithDateAndTime.new @invalid_date_params
@obj.should_not be_nil
+ @obj.should be_kind_of(WithDateAndTime)
end
it "should not crash because of an empty value" do
@invalid_date_params["exec_date(2i)"] = ""
@obj = WithDateAndTime.new @invalid_date_params
- @obj.exec_date.should_not be_nil
- @obj.exec_date.should_not be_kind_of(Date)
- @obj.should be_kind_of(WithDateAndTime)
- end
- it "should not crash because of an illegal value" do
- @obj = WithDateAndTime.new @invalid_date_params
- @obj.exec_date.should_not be_nil
+ @obj.should_not be_nil
@obj.exec_date.should_not be_kind_of(Date)
@obj.should be_kind_of(WithDateAndTime)
end

0 comments on commit 2571791

Please sign in to comment.