Permalink
Browse files

- ActiveResource

  test_has_many_accessor_should_return_the_an_empty_array_when_it_does_not_has_milestones
  • Loading branch information...
1 parent 9b2d30b commit 25207f885f767b9a1cf574863877ff6aaeefc9e1 @gramos committed Sep 29, 2010
@@ -23,8 +23,10 @@ def options(association, resource)
o[:host_klass] = self
case association
+ when :has_many
+ o[:association_col] = "#{o[:host_klass].to_s.singularize.underscore}_id".to_sym
when :belongs_to
- o[:association_col] = "#{o[:klass].constantize.to_s.underscore}_id".to_sym
+ o[:association_col] = "#{o[:klass].underscore}_id".to_sym
when :has_one
o[:association_col] = "#{o[:host_klass].to_s.underscore}_id".to_sym
end
@@ -33,6 +33,8 @@ class Milestone < ActiveResource::Base
mock.get "/project_managers.xml?project_id=1", {}, @project_managers.to_xml
mock.get "/project_managers.xml?project_id=2", {}, [].to_xml
mock.get "/milestones.xml", {}, [@milestone].to_xml
+ mock.get "/milestones.xml?project_id=2", {}, [].to_xml
+ mock.get "/milestones.xml?project_id=1", {}, [@milestone].to_xml
mock.put "/project_managers/6.xml", {}, nil, 204
end
@@ -99,5 +101,9 @@ def test_has_many_should_add_a_resource_accessor
def test_has_many_accessor_should_return_the_an_array_with_the_associated_milestones
assert_equal [@milestone], @project.milestones
end
+
+ def test_has_many_accessor_should_return_the_an_empty_array_when_it_does_not_has_milestones
+ assert_equal [], @other_project.milestones
+ end
end

0 comments on commit 25207f8

Please sign in to comment.