Skip to content

Commit 67b3fb5

Browse files
committed
Refactor RSpec for AnnotateModels - with Globalize gem
1 parent f3db77f commit 67b3fb5

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,49 @@ def mock_column(name, type, options = {})
761761
end
762762
end
763763
end
764+
765+
context 'with Globalize gem' do
766+
let :translation_klass do
767+
double('Post::Translation',
768+
to_s: 'Post::Translation',
769+
columns: [
770+
mock_column(:id, :integer, limit: 8),
771+
mock_column(:post_id, :integer, limit: 8),
772+
mock_column(:locale, :string, limit: 50),
773+
mock_column(:title, :string, limit: 50),
774+
])
775+
end
776+
777+
let :klass do
778+
mock_class(:posts, primary_key, columns, indexes, foreign_keys).tap do |mock_klass|
779+
allow(mock_klass).to receive(:translation_class).and_return(translation_klass)
780+
end
781+
end
782+
783+
let :columns do
784+
[
785+
mock_column(:id, :integer, limit: 8),
786+
mock_column(:author_name, :string, limit: 50),
787+
]
788+
end
789+
790+
let :expected_result do
791+
<<~EOS
792+
# Schema Info
793+
#
794+
# Table name: posts
795+
#
796+
# id :integer not null, primary key
797+
# author_name :string(50) not null
798+
# title :string(50) not null
799+
#
800+
EOS
801+
end
802+
803+
it 'returns schema info' do
804+
is_expected.to eq expected_result
805+
end
806+
end
764807
end
765808

766809
context 'when the primary key is an array (using composite_primary_keys)' do
@@ -1140,39 +1183,6 @@ def mock_column(name, type, options = {})
11401183
end
11411184
end
11421185

1143-
it 'should work with the Globalize gem' do
1144-
klass = mock_class(:posts,
1145-
:id,
1146-
[
1147-
mock_column(:id, :integer, limit: 8),
1148-
mock_column(:author_name, :string, limit: 50),
1149-
])
1150-
1151-
options = {
1152-
to_s: 'Post::Translation',
1153-
columns: [
1154-
mock_column(:id, :integer, limit: 8),
1155-
mock_column(:post_id, :integer, limit: 8),
1156-
mock_column(:locale, :string, limit: 50),
1157-
mock_column(:title, :string, limit: 50),
1158-
]
1159-
}
1160-
translation_klass = double('Post::Translation', options)
1161-
allow(klass).to receive(:translation_class).and_return(translation_klass)
1162-
1163-
expected_schema_info = <<~EOS
1164-
# Schema Info
1165-
#
1166-
# Table name: posts
1167-
#
1168-
# id :integer not null, primary key
1169-
# author_name :string(50) not null
1170-
# title :string(50) not null
1171-
#
1172-
EOS
1173-
expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(expected_schema_info)
1174-
end
1175-
11761186
describe '.set_defaults' do
11771187
subject do
11781188
Annotate::Helpers.true?(ENV['show_complete_foreign_keys'])

0 commit comments

Comments
 (0)