Commit 62d31ead by Alex Chaffee

Merge pull request #86 from kuroda/without_primary_key

expect a model without primary key
parents bef0c494 be82e0c0
...@@ -82,7 +82,7 @@ module AnnotateModels ...@@ -82,7 +82,7 @@ module AnnotateModels
attrs = [] attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil? attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null attrs << "not null" unless col.null
attrs << "primary key" if col.name.to_sym == klass.primary_key.to_sym attrs << "primary key" if klass.primary_key && col.name.to_sym == klass.primary_key.to_sym
col_type = (col.type || col.sql_type).to_s col_type = (col.type || col.sql_type).to_s
if col_type == "decimal" if col_type == "decimal"
......
...@@ -8,7 +8,7 @@ describe AnnotateModels do ...@@ -8,7 +8,7 @@ describe AnnotateModels do
options = { options = {
:connection => mock("Conn", :indexes => []), :connection => mock("Conn", :indexes => []),
:table_name => table_name, :table_name => table_name,
:primary_key => primary_key.to_s, :primary_key => primary_key && primary_key.to_s,
:column_names => columns.map { |col| col.name.to_s }, :column_names => columns.map { |col| col.name.to_s },
:columns => columns :columns => columns
} }
...@@ -55,6 +55,24 @@ describe AnnotateModels do ...@@ -55,6 +55,24 @@ describe AnnotateModels do
EOS EOS
end end
it "should get schema info even if the primary key is not set" do
klass = mock_class(:users, nil, [
mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50)
])
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
# Schema Info
#
# Table name: users
#
# id :integer not null
# name :string(50) not null
#
EOS
end
it "should get schema info as RDoc" do it "should get schema info as RDoc" do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment