Permalink
Browse files

moved the method_name to class name stuff into it's own method, mostl…

…y so i can test for it easily, and then tested it ;)
  • Loading branch information...
1 parent baff20e commit e76ead48010bee5c7939c2b0b43b1ab19c0909c8 @justinfrench committed Dec 31, 2008
Showing with 13 additions and 1 deletion.
  1. +7 −1 lib/active_time.rb
  2. +6 −0 test/active_time_test.rb
View
8 lib/active_time.rb
@@ -65,7 +65,7 @@ def method_missing(method_name, *args)
if method_name.to_s =~ COLLECTION_METHOD_NAMES_PATTERN
args[0] ||= :created_at
begin
- klass_name = method_name.to_s.singularize.classify
+ klass_name = class_name_for_method_name(method_name)
klass = klass_name.constantize
return klass.in_date_range(starting, ending, args[0]) # Post.in_date_range(start_time, end_time, :created_at)
rescue NoMethodError
@@ -104,4 +104,10 @@ def description
end
end
+ protected
+
+ def self.class_name_for_method_name(method_name)
+ method_name.to_s.singularize.classify
+ end
+
end
View
6 test/active_time_test.rb
@@ -215,6 +215,12 @@ def ending
assert @object.respond_to?(:summaries)
end
+ should "infer a class name from the missing method name" do
+ assert_equal "Post", ActiveTime.send(:class_name_for_method_name, "posts")
+ assert_equal "ActivityEvent", ActiveTime.send(:class_name_for_method_name, "activity_events")
+ assert_equal "User", ActiveTime.send(:class_name_for_method_name, "users")
+ assert_equal "Summary", ActiveTime.send(:class_name_for_method_name, "summaries")
+ end
end
end

0 comments on commit e76ead4

Please sign in to comment.