Permalink
Browse files

Change Etymology#rejectable to match what's really checked for. (not …

…DRY)


Closes #114.
  • Loading branch information...
kohath committed Jun 28, 2011
1 parent ef3d6d6 commit 0f7919ed1054cb530d5e5d59180331a5a39319da
Showing with 41 additions and 1 deletion.
  1. +3 −1 app/models/etymology.rb
  2. +38 −0 test/unit/etymology_test.rb
View
@@ -35,8 +35,10 @@ def primary_gloss
gloss.present? ? gloss : Gloss.attesting(self, "Etymology").first.try(:gloss)
end
+ # Determine whether the given attribute hash would create an invalid etymology.
def self.rejectable?(attrs)
- !new(attrs.delete_if{|key, value| ["_destroy", "parses_attributes"].include? key}).valid?
+ next_etymon_rejectable = (attrs["next_etymology_attributes"] ? Etymology.rejectable?(attrs["next_etymology_attributes"]) : nil)
+ [next_etymon_rejectable, attrs["etymon"], attrs["original_language"], attrs["gloss"], attrs["notes"]].all?(&:blank?)
end
protected
@@ -27,4 +27,42 @@ class EtymologyTest < ActiveSupport::TestCase
test "ancestor_map with next_etymon" do
assert_equal [{etymologies(:with_same_language_next) => {}}, {etymologies(:with_same_language_next_b) => {}}], etymologies(:with_same_language_next).ancestor_map
end
+
+ # Issue #114.
+ test "rejectable?" do
+ assert !Etymology.rejectable?(
+ {"_destroy"=>"0",
+ "original_language_id"=>"",
+ "etymon"=>"[[novem]]",
+ "gloss"=>"",
+ "parses_attributes"=>
+ {"0"=>
+ {"_destroy"=>"false",
+ "parsed_form"=>""}
+ },
+ "next_etymon_attributes"=>
+ {"_destroy"=>"0",
+ "original_language_id"=>"14",
+ "etymon"=>"''*mens-ri-''",
+ "gloss"=>"",
+ "parses_attributes"=>
+ {"0"=>
+ {"_destroy"=>"false",
+ "parsed_form"=>""}
+ },
+ "next_etymon_attributes"=>
+ {"_destroy"=>"false",
+ "original_language_id"=>"",
+ "etymon"=>"",
+ "gloss"=>"",
+ "parses_attributes"=>
+ {"0"=>
+ {"_destroy"=>"false",
+ "parsed_form"=>""}
+ }
+ },
+ "id"=>"738"},
+ "id"=>"737"})
+ end
end
+

0 comments on commit 0f7919e

Please sign in to comment.