Commit 91da93dd by Cuong Tran

Merge pull request #353 from kfarst/develop

Add unit tests for classified sort option
parents 15e699ed f89d86f4
...@@ -48,7 +48,7 @@ describe AnnotateModels do ...@@ -48,7 +48,7 @@ describe AnnotateModels do
stubs = default_options.dup stubs = default_options.dup
stubs.merge!(options) stubs.merge!(options)
stubs[:name] = name stubs[:name] = name
stubs[:type] = type stubs[:type] = type
double("Column", stubs) double("Column", stubs)
end end
...@@ -218,14 +218,20 @@ EOS ...@@ -218,14 +218,20 @@ EOS
describe "#get_schema_info with custom options" do describe "#get_schema_info with custom options" do
def self.when_called_with(options = {}) def self.when_called_with(options = {})
expected = options.delete(:returns) expected = options.delete(:returns)
default_columns = [
[:id, :integer, { :limit => 8 }],
[:active, :boolean, { :limit => 1 }],
[:name, :string, { :limit => 50 }],
[:notes, :text, { :limit => 55 }]
]
it "should work with options = #{options}" do it "should work with options = #{options}" do
klass = mock_class(:users, :id, [ with_columns = (options.delete(:with_columns) || default_columns).map do |column|
mock_column(:id, :integer, :limit => 8), mock_column(column[0], column[1], column[2])
mock_column(:active, :boolean, :limit => 1), end
mock_column(:name, :string, :limit => 50),
mock_column(:notes, :text, :limit => 55), klass = mock_class(:users, :id, with_columns)
])
schema_info = AnnotateModels.get_schema_info(klass, "Schema Info", options) schema_info = AnnotateModels.get_schema_info(klass, "Schema Info", options)
expect(schema_info).to eql(expected) expect(schema_info).to eql(expected)
end end
...@@ -268,6 +274,24 @@ EOS ...@@ -268,6 +274,24 @@ EOS
# notes :text not null # notes :text not null
# #
EOS EOS
mocked_columns_without_id = [
[:active, :boolean, { :limit => 1 }],
[:name, :string, { :limit => 50 }],
[:notes, :text, { :limit => 55 }]
]
when_called_with classified_sort: 'yes', with_columns: mocked_columns_without_id, returns:
<<-EOS.strip_heredoc
# Schema Info
#
# Table name: users
#
# active :boolean not null
# name :string(50) not null
# notes :text(55) not null
#
EOS
end end
describe "#get_model_class" do describe "#get_model_class" do
......
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