Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for classified sort option #353

Merged
merged 1 commit into from
Mar 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions spec/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def mock_column(name, type, options={})
stubs = default_options.dup
stubs.merge!(options)
stubs[:name] = name
stubs[:type] = type
stubs[:type] = type

double("Column", stubs)
end
Expand Down Expand Up @@ -218,14 +218,20 @@ def mock_column(name, type, options={})
describe "#get_schema_info with custom options" do
def self.when_called_with(options = {})
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
klass = mock_class(:users, :id, [
mock_column(:id, :integer, :limit => 8),
mock_column(:active, :boolean, :limit => 1),
mock_column(:name, :string, :limit => 50),
mock_column(:notes, :text, :limit => 55),
])
with_columns = (options.delete(:with_columns) || default_columns).map do |column|
mock_column(column[0], column[1], column[2])
end

klass = mock_class(:users, :id, with_columns)

schema_info = AnnotateModels.get_schema_info(klass, "Schema Info", options)
expect(schema_info).to eql(expected)
end
Expand Down Expand Up @@ -268,6 +274,24 @@ def self.when_called_with(options = {})
# notes :text not null
#
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

describe "#get_model_class" do
Expand Down