Permalink
Browse files

Generate belongs_to associations automatically for 'references' types [

…#640 state:resolved]
  • Loading branch information...
tarmo committed Aug 23, 2008
1 parent a652c30 commit 9223a919111867e6b47b2627c30d8eb21e8ac7d9
@@ -1,2 +1,5 @@
class <%= class_name %> < ActiveRecord::Base
+<% attributes.select { |a| a.type.to_s == 'references' }.each do |attribute| -%>
+ belongs_to :<%= attribute.name %>
+<% end -%>
end
@@ -29,4 +29,12 @@ def test_model_with_attributes_generates_resources_with_attributes
assert_generated_column t, :created_at, :timestamp
end
end
+
+ def test_model_with_reference_attributes_generates_belongs_to_associations
+ run_generator('model', %w(Product name:string supplier:references))
+
+ assert_generated_model_for :product do |body|
+ assert body =~ /^\s+belongs_to :supplier/, "#{body.inspect} should contain 'belongs_to :supplier'"
+ end
+ end
end

0 comments on commit 9223a91

Please sign in to comment.