Permalink
Browse files

- ActiveResource test_belongs_to_accessor_should_return_the_associate…

…d_project
  • Loading branch information...
1 parent 8a7f3d9 commit 55156b130fe63ad2f6482b2a63c4ef209f5e4c75 @gramos committed Sep 29, 2010
@@ -5,9 +5,8 @@ def hash_options(association, resource)
h = { :klass => klass_for(association, resource) }
h[:host_klass] = self
case association
- when :has_many
- h[:association_col] = "#{h[:host_klass].to_s.downcase}_id".to_sym
-
+ when :belongs_to
+ h[:association_col] = "#{h[:klass].to_s.underscore}_id".to_sym
when :has_one
h[:association_col] = "#{h[:host_klass].to_s.underscore}_id".to_sym
end
@@ -62,7 +61,7 @@ def belongs_to(resource, opts = {})
define_method(klass_name) do
if !instance_variable_defined?("@#{resource}") ||
instance_variable_get("@#{resource}").nil?
- instance_variable_set("@#{resource}", h[:klass].find(h[:association_col]))
+ instance_variable_set("@#{resource}", h[:klass].find(send h[:association_col]))
end
return instance_variable_get("@#{resource}")
end
@@ -44,15 +44,15 @@ def test_has_one_should_add_a_resource_accessor
assert @project.respond_to? :project_manager
end
- def test_accessor_should_return_the_associated_project_manager
+ def test_has_one_accessor_should_return_the_associated_project_manager
assert_equal @project_manager, @project.project_manager
end
- def test_accessor_should_return_nil_when_the_does_not_has_an_associated_resource
+ def test_has_one_accessor_should_return_nil_when_the_does_not_has_an_associated_resource
assert_nil @other_project.project_manager
end
- def test_should_assign_a_new_project_manager
+ def test_has_one_should_assign_a_new_project_manager
@other_project.project_manager = @other_project_manager
assert_equal @other_project.id, @other_project_manager.project_id
end
@@ -61,8 +61,13 @@ def test_should_assign_a_new_project_manager
# belogns_to association
#----------------------------------------------------------------------
- def test_belogns_to_should_add_a_resource_accessor
+ def test_belongs_to_should_add_a_resource_accessor
assert @project_manager.respond_to? :project
end
+
+ def test_belongs_to_accessor_should_return_the_associated_project
+ assert_equal @project, @project_manager.project
+ end
+
end

0 comments on commit 55156b1

Please sign in to comment.