From 050726a73420426ace1c0deb8ca765e12af045ba Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:07:42 +0900 Subject: [PATCH 01/17] =?UTF-8?q?Add=20context=20'when=20option=20is=20not?= =?UTF-8?q?=20present=E2=80=99=20and=20refactor=20test=20cases=20when=20th?= =?UTF-8?q?e=20primary=20key=20is=20not=20specified?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/lib/annotate/annotate_models_spec.rb | 162 ++++++++++++---------- 1 file changed, 87 insertions(+), 75 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index f188fddd1..fc0401039 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -192,99 +192,111 @@ def mock_column(name, type, options = {}) [] end - context 'when header is "Schema Info"' do - let :header do - 'Schema Info' + context 'when option is not present' do + subject do + AnnotateModels.get_schema_info(klass, header) end - context 'when the primary key is not specified' do - let :primary_key do - nil + context 'when header is "Schema Info"' do + let :header do + 'Schema Info' end - context 'when the columns are normal' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:name, :string, limit: 50) - ] + context 'when the primary key is not specified' do + let :primary_key do + nil end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null - # name :string(50) not null - # - EOS - end + context 'when the columns are normal' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:name, :string, limit: 50) + ] + end - it 'returns schema info' do - is_expected.to eq(expected_result) - end - end + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null + # name :string(50) not null + # + EOS + end - context 'when an enum column exists' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:name, :enum, limit: [:enum1, :enum2]) - ] + it 'returns schema info' do + is_expected.to eq(expected_result) + end end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null - # name :enum not null, (enum1, enum2) - # - EOS - end + context 'when an enum column exists' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:name, :enum, limit: [:enum1, :enum2]) + ] + end - it 'returns schema info' do - is_expected.to eq(expected_result) - end - end + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null + # name :enum not null, (enum1, enum2) + # + EOS + end - context 'when unsigned columns exist' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:integer, :integer, unsigned?: true), - mock_column(:bigint, :integer, unsigned?: true, bigint?: true), - mock_column(:bigint, :bigint, unsigned?: true), - mock_column(:float, :float, unsigned?: true), - mock_column(:decimal, :decimal, unsigned?: true, precision: 10, scale: 2), - ] + it 'returns schema info' do + is_expected.to eq(expected_result) + end end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null - # integer :integer unsigned, not null - # bigint :bigint unsigned, not null - # bigint :bigint unsigned, not null - # float :float unsigned, not null - # decimal :decimal(10, 2) unsigned, not null - # - EOS - end + context 'when unsigned columns exist' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:integer, :integer, unsigned?: true), + mock_column(:bigint, :integer, unsigned?: true, bigint?: true), + mock_column(:bigint, :bigint, unsigned?: true), + mock_column(:float, :float, unsigned?: true), + mock_column(:decimal, :decimal, unsigned?: true, precision: 10, scale: 2), + ] + end - it 'returns schema info' do - is_expected.to eq(expected_result) + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null + # integer :integer unsigned, not null + # bigint :bigint unsigned, not null + # bigint :bigint unsigned, not null + # float :float unsigned, not null + # decimal :decimal(10, 2) unsigned, not null + # + EOS + end + + it 'returns schema info' do + is_expected.to eq(expected_result) + end end end end + end + + context 'when header is "Schema Info"' do + let :header do + 'Schema Info' + end context 'when the primary key is specified' do context 'when the primary_key is :id' do From 71ed751cf5aed2ae12a7d65db71e93b35ec613b9 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:09:08 +0900 Subject: [PATCH 02/17] Move test cases when the primary key is specified --- spec/lib/annotate/annotate_models_spec.rb | 176 +++++++++++----------- 1 file changed, 92 insertions(+), 84 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index fc0401039..b53035fad 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -290,105 +290,113 @@ def mock_column(name, type, options = {}) end end end - end - end - context 'when header is "Schema Info"' do - let :header do - 'Schema Info' - end + context 'when the primary key is specified' do + context 'when the primary_key is :id' do + let :primary_key do + :id + end - context 'when the primary key is specified' do - context 'when the primary_key is :id' do - let :primary_key do - :id - end + context 'when columns are normal' do + let :columns do + [ + mock_column(:id, :integer, limit: 8), + mock_column(:name, :string, limit: 50), + mock_column(:notes, :text, limit: 55) + ] + end - context 'when columns are normal' do - let :columns do - [ - mock_column(:id, :integer, limit: 8), - mock_column(:name, :string, limit: 50), - mock_column(:notes, :text, limit: 55) - ] - end + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # name :string(50) not null + # notes :text(55) not null + # + EOS + end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # name :string(50) not null - # notes :text(55) not null - # - EOS + it 'returns schema info' do + is_expected.to eq(expected_result) + end end - it 'returns schema info' do - is_expected.to eq(expected_result) - end - end + context 'when columns have default values' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:size, :integer, default: 20), + mock_column(:flag, :boolean, default: false) + ] + end - context 'when columns have default values' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:size, :integer, default: 20), - mock_column(:flag, :boolean, default: false) - ] - end + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # size :integer default(20), not null + # flag :boolean default(FALSE), not null + # + EOS + end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # size :integer default(20), not null - # flag :boolean default(FALSE), not null - # - EOS + it 'returns schema info with default values' do + is_expected.to eq(expected_result) + end end - it 'returns schema info with default values' do - is_expected.to eq(expected_result) - end - end + context 'when an integer column using ActiveRecord::Enum exists' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:status, :integer, default: 0) + ] + end - context 'when an integer column using ActiveRecord::Enum exists' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:status, :integer, default: 0) - ] - end + before :each do + # column_defaults may be overritten when ActiveRecord::Enum is used, e.g: + # class User < ActiveRecord::Base + # enum status: [ :disabled, :enabled ] + # end + allow(klass).to receive(:column_defaults).and_return('id' => nil, 'status' => 'disabled') + end - before :each do - # column_defaults may be overritten when ActiveRecord::Enum is used, e.g: - # class User < ActiveRecord::Base - # enum status: [ :disabled, :enabled ] - # end - allow(klass).to receive(:column_defaults).and_return('id' => nil, 'status' => 'disabled') - end + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # status :integer default(0), not null + # + EOS + end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # status :integer default(0), not null - # - EOS + it 'returns schema info with default values' do + is_expected.to eq(expected_result) + end end + end + end + end + end - it 'returns schema info with default values' do - is_expected.to eq(expected_result) - end + context 'when header is "Schema Info"' do + let :header do + 'Schema Info' + end + + context 'when the primary key is specified' do + context 'when the primary_key is :id' do + let :primary_key do + :id end context 'when indexes exist' do From 741c813ccad4e281a5d5a1e2d73142576b7a27cf Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:16:57 +0900 Subject: [PATCH 03/17] Add context 'when option is present' and refactor test cases when option "show_indexes" is true --- spec/lib/annotate/annotate_models_spec.rb | 410 +++++++++++----------- 1 file changed, 214 insertions(+), 196 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index b53035fad..3f6e28a8f 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -388,219 +388,237 @@ def mock_column(name, type, options = {}) end end - context 'when header is "Schema Info"' do - let :header do - 'Schema Info' - end - - context 'when the primary key is specified' do - context 'when the primary_key is :id' do - let :primary_key do - :id - end - - context 'when indexes exist' do - context 'when option "show_indexes" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, show_indexes: true) - end - - context 'when indexes are normal' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:foreign_thing_id, :integer) - ] - end - - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', columns: ['foreign_thing_id']) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # foreign_thing_id :integer not null - # - # Indexes - # - # index_rails_02e851e3b7 (id) - # index_rails_02e851e3b8 (foreign_thing_id) - # - EOS - end - - it 'returns schema info with index information' do - is_expected.to eq expected_result - end - end - - context 'when one of indexes includes orderd index key' do - let :columns do - [ - mock_column("id", :integer), - mock_column("firstname", :string), - mock_column("surname", :string), - mock_column("value", :string) - ] - end - - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: %w(firstname surname value), - orders: { 'surname' => :asc, 'value' => :desc }) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # firstname :string not null - # surname :string not null - # value :string not null - # - # Indexes - # - # index_rails_02e851e3b7 (id) - # index_rails_02e851e3b8 (firstname,surname ASC,value DESC) - # - EOS - end - - it 'returns schema info with index information' do - is_expected.to eq expected_result - end - end - - context 'when one of indexes includes "where" clause' do - let :columns do - [ - mock_column("id", :integer), - mock_column("firstname", :string), - mock_column("surname", :string), - mock_column("value", :string) - ] - end + context 'when option is present' do + context 'when header is "Schema Info"' do + let :header do + 'Schema Info' + end - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: %w(firstname surname), - where: 'value IS NOT NULL') - ] - end + context 'when the primary key is specified' do + context 'when the primary_key is :id' do + let :primary_key do + :id + end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # firstname :string not null - # surname :string not null - # value :string not null - # - # Indexes - # - # index_rails_02e851e3b7 (id) - # index_rails_02e851e3b8 (firstname,surname) WHERE value IS NOT NULL - # - EOS + context 'when indexes exist' do + context 'when option "show_indexes" is true' do + subject do + AnnotateModels.get_schema_info(klass, header, show_indexes: true) end - it 'returns schema info with index information' do - is_expected.to eq expected_result + context 'when indexes are normal' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:foreign_thing_id, :integer) + ] + end + + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', columns: ['foreign_thing_id']) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # foreign_thing_id :integer not null + # + # Indexes + # + # index_rails_02e851e3b7 (id) + # index_rails_02e851e3b8 (foreign_thing_id) + # + EOS + end + + it 'returns schema info with index information' do + is_expected.to eq expected_result + end end - end - context 'when one of indexes includes "using" clause other than "btree"' do - let :columns do - [ - mock_column("id", :integer), - mock_column("firstname", :string), - mock_column("surname", :string), - mock_column("value", :string) - ] + context 'when one of indexes includes orderd index key' do + let :columns do + [ + mock_column("id", :integer), + mock_column("firstname", :string), + mock_column("surname", :string), + mock_column("value", :string) + ] + end + + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: %w(firstname surname value), + orders: { 'surname' => :asc, 'value' => :desc }) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # firstname :string not null + # surname :string not null + # value :string not null + # + # Indexes + # + # index_rails_02e851e3b7 (id) + # index_rails_02e851e3b8 (firstname,surname ASC,value DESC) + # + EOS + end + + it 'returns schema info with index information' do + is_expected.to eq expected_result + end end - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: %w(firstname surname), - using: 'hash') - ] + context 'when one of indexes includes "where" clause' do + let :columns do + [ + mock_column("id", :integer), + mock_column("firstname", :string), + mock_column("surname", :string), + mock_column("value", :string) + ] + end + + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: %w(firstname surname), + where: 'value IS NOT NULL') + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # firstname :string not null + # surname :string not null + # value :string not null + # + # Indexes + # + # index_rails_02e851e3b7 (id) + # index_rails_02e851e3b8 (firstname,surname) WHERE value IS NOT NULL + # + EOS + end + + it 'returns schema info with index information' do + is_expected.to eq expected_result + end end - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # firstname :string not null - # surname :string not null - # value :string not null - # - # Indexes - # - # index_rails_02e851e3b7 (id) - # index_rails_02e851e3b8 (firstname,surname) USING hash - # - EOS + context 'when one of indexes includes "using" clause other than "btree"' do + let :columns do + [ + mock_column("id", :integer), + mock_column("firstname", :string), + mock_column("surname", :string), + mock_column("value", :string) + ] + end + + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: %w(firstname surname), + using: 'hash') + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # firstname :string not null + # surname :string not null + # value :string not null + # + # Indexes + # + # index_rails_02e851e3b7 (id) + # index_rails_02e851e3b8 (firstname,surname) USING hash + # + EOS + end + + it 'returns schema info with index information' do + is_expected.to eq expected_result + end end - it 'returns schema info with index information' do - is_expected.to eq expected_result + context 'when index is not defined' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:foreign_thing_id, :integer) + ] + end + + let :indexes do + [] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # foreign_thing_id :integer not null + # + EOS + end + + it 'returns schema info without index information' do + is_expected.to eq expected_result + end end end + end + end + end + end + end - context 'when index is not defined' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:foreign_thing_id, :integer) - ] - end - - let :indexes do - [] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # foreign_thing_id :integer not null - # - EOS - end + context 'when header is "Schema Info"' do + let :header do + 'Schema Info' + end - it 'returns schema info without index information' do - is_expected.to eq expected_result - end - end - end + context 'when the primary key is specified' do + context 'when the primary_key is :id' do + let :primary_key do + :id + end + context 'when indexes exist' do context 'when option "simple_indexes" is true' do subject do AnnotateModels.get_schema_info(klass, header, simple_indexes: true) From e54109b5f7e98b8127f834ca66e251cd66ef1e84 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:20:29 +0900 Subject: [PATCH 04/17] Move test cases when option "simple_indexes" is true --- spec/lib/annotate/annotate_models_spec.rb | 146 +++++++++++----------- 1 file changed, 72 insertions(+), 74 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 3f6e28a8f..6ba137e5e 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -601,6 +601,78 @@ def mock_column(name, type, options = {}) end end end + + context 'when option "simple_indexes" is true' do + subject do + AnnotateModels.get_schema_info(klass, header, simple_indexes: true) + end + + context 'when one of indexes includes "orders" clause' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:foreign_thing_id, :integer) + ] + end + + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: ['foreign_thing_id'], + orders: { 'foreign_thing_id' => :desc }) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # foreign_thing_id :integer not null + # + EOS + end + + it 'returns schema info with index information' do + is_expected.to eq expected_result + end + end + + context 'when one of indexes is in string form' do + let :columns do + [ + mock_column("id", :integer), + mock_column("name", :string) + ] + end + + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', columns: 'LOWER(name)') + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key, indexed + # name :string not null + # + EOS + end + + it 'returns schema info with index information' do + is_expected.to eq expected_result + end + end + end end end end @@ -618,80 +690,6 @@ def mock_column(name, type, options = {}) :id end - context 'when indexes exist' do - context 'when option "simple_indexes" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, simple_indexes: true) - end - - context 'when one of indexes includes "orders" clause' do # TODO - let :columns do - [ - mock_column(:id, :integer), - mock_column(:foreign_thing_id, :integer) - ] - end - - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: ['foreign_thing_id'], - orders: { 'foreign_thing_id' => :desc }) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # foreign_thing_id :integer not null - # - EOS - end - - it 'returns schema info with index information' do - is_expected.to eq expected_result - end - end - - context 'when one of indexes is in string form' do - let :columns do - [ - mock_column("id", :integer), - mock_column("name", :string) - ] - end - - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', columns: 'LOWER(name)') - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key, indexed - # name :string not null - # - EOS - end - - it 'returns schema info with index information' do - is_expected.to eq expected_result - end - end - end - end - context 'when foreign keys exist' do let :columns do [ From d33b277fb0a1301d1faf6d05c1a832af6b595e1b Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:23:12 +0900 Subject: [PATCH 05/17] Move test cases when foreign keys exist --- spec/lib/annotate/annotate_models_spec.rb | 176 +++++++++++----------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 6ba137e5e..a60bdd8ae 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -674,77 +674,89 @@ def mock_column(name, type, options = {}) end end end - end - end - end - end - - context 'when header is "Schema Info"' do - let :header do - 'Schema Info' - end - context 'when the primary key is specified' do - context 'when the primary_key is :id' do - let :primary_key do - :id - end + context 'when foreign keys exist' do + let :columns do + [ + mock_column(:id, :integer), + mock_column(:foreign_thing_id, :integer) + ] + end - context 'when foreign keys exist' do - let :columns do - [ - mock_column(:id, :integer), - mock_column(:foreign_thing_id, :integer) - ] - end + let :foreign_keys do + [ + mock_foreign_key('fk_rails_cf2568e89e', 'foreign_thing_id', 'foreign_things'), + mock_foreign_key('custom_fk_name', 'other_thing_id', 'other_things'), + mock_foreign_key('fk_rails_a70234b26c', 'third_thing_id', 'third_things') + ] + end - let :foreign_keys do - [ - mock_foreign_key('fk_rails_cf2568e89e', 'foreign_thing_id', 'foreign_things'), - mock_foreign_key('custom_fk_name', 'other_thing_id', 'other_things'), - mock_foreign_key('fk_rails_a70234b26c', 'third_thing_id', 'third_things') - ] - end + context 'when option "show_foreign_keys" is specified' do + subject do + AnnotateModels.get_schema_info(klass, header, show_foreign_keys: true) + end - context 'when option "show_foreign_keys" is specified' do - subject do - AnnotateModels.get_schema_info(klass, header, show_foreign_keys: true) - end + context 'when foreign_keys does not have option' do + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # foreign_thing_id :integer not null + # + # Foreign Keys + # + # custom_fk_name (other_thing_id => other_things.id) + # fk_rails_... (foreign_thing_id => foreign_things.id) + # fk_rails_... (third_thing_id => third_things.id) + # + EOS + end - context 'when foreign_keys does not have option' do - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # foreign_thing_id :integer not null - # - # Foreign Keys - # - # custom_fk_name (other_thing_id => other_things.id) - # fk_rails_... (foreign_thing_id => foreign_things.id) - # fk_rails_... (third_thing_id => third_things.id) - # - EOS + it 'returns schema info with foreign keys' do + is_expected.to eq(expected_result) + end end - it 'returns schema info with foreign keys' do - is_expected.to eq(expected_result) + context 'when foreign_keys have option "on_delete" and "on_update"' do + let :foreign_keys do + [ + mock_foreign_key('fk_rails_02e851e3b7', + 'foreign_thing_id', + 'foreign_things', + 'id', + on_delete: 'on_delete_value', + on_update: 'on_update_value') + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # foreign_thing_id :integer not null + # + # Foreign Keys + # + # fk_rails_... (foreign_thing_id => foreign_things.id) ON DELETE => on_delete_value ON UPDATE => on_update_value + # + EOS + end + + it 'returns schema info with foreign keys' do + is_expected.to eq(expected_result) + end end end - context 'when foreign_keys have option "on_delete" and "on_update"' do - let :foreign_keys do - [ - mock_foreign_key('fk_rails_02e851e3b7', - 'foreign_thing_id', - 'foreign_things', - 'id', - on_delete: 'on_delete_value', - on_update: 'on_update_value') - ] + context 'when option "show_foreign_keys" and "show_complete_foreign_keys" are specified' do + subject do + AnnotateModels.get_schema_info(klass, header, show_foreign_keys: true, show_complete_foreign_keys: true) end let :expected_result do @@ -758,7 +770,9 @@ def mock_column(name, type, options = {}) # # Foreign Keys # - # fk_rails_... (foreign_thing_id => foreign_things.id) ON DELETE => on_delete_value ON UPDATE => on_update_value + # custom_fk_name (other_thing_id => other_things.id) + # fk_rails_a70234b26c (third_thing_id => third_things.id) + # fk_rails_cf2568e89e (foreign_thing_id => foreign_things.id) # EOS end @@ -768,34 +782,20 @@ def mock_column(name, type, options = {}) end end end + end + end + end + end - context 'when option "show_foreign_keys" and "show_complete_foreign_keys" are specified' do - subject do - AnnotateModels.get_schema_info(klass, header, show_foreign_keys: true, show_complete_foreign_keys: true) - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # foreign_thing_id :integer not null - # - # Foreign Keys - # - # custom_fk_name (other_thing_id => other_things.id) - # fk_rails_a70234b26c (third_thing_id => third_things.id) - # fk_rails_cf2568e89e (foreign_thing_id => foreign_things.id) - # - EOS - end + context 'when header is "Schema Info"' do + let :header do + 'Schema Info' + end - it 'returns schema info with foreign keys' do - is_expected.to eq(expected_result) - end - end + context 'when the primary key is specified' do + context 'when the primary_key is :id' do + let :primary_key do + :id end context 'with Globalize gem' do From d9618a0d9bcf559b9aa35d43c9313459b671b09b Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:24:09 +0900 Subject: [PATCH 06/17] Move test cases with Globalize gem --- spec/lib/annotate/annotate_models_spec.rb | 92 +++++++++++------------ 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index a60bdd8ae..c4582e89a 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -383,6 +383,49 @@ def mock_column(name, type, options = {}) is_expected.to eq(expected_result) end end + + context 'with Globalize gem' do + let :translation_klass do + double('Post::Translation', + to_s: 'Post::Translation', + columns: [ + mock_column(:id, :integer, limit: 8), + mock_column(:post_id, :integer, limit: 8), + mock_column(:locale, :string, limit: 50), + mock_column(:title, :string, limit: 50), + ]) + end + + let :klass do + mock_class(:posts, primary_key, columns, indexes, foreign_keys).tap do |mock_klass| + allow(mock_klass).to receive(:translation_class).and_return(translation_klass) + end + end + + let :columns do + [ + mock_column(:id, :integer, limit: 8), + mock_column(:author_name, :string, limit: 50), + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: posts + # + # id :integer not null, primary key + # author_name :string(50) not null + # title :string(50) not null + # + EOS + end + + it 'returns schema info' do + is_expected.to eq expected_result + end + end end end end @@ -793,55 +836,6 @@ def mock_column(name, type, options = {}) end context 'when the primary key is specified' do - context 'when the primary_key is :id' do - let :primary_key do - :id - end - - context 'with Globalize gem' do - let :translation_klass do - double('Post::Translation', - to_s: 'Post::Translation', - columns: [ - mock_column(:id, :integer, limit: 8), - mock_column(:post_id, :integer, limit: 8), - mock_column(:locale, :string, limit: 50), - mock_column(:title, :string, limit: 50), - ]) - end - - let :klass do - mock_class(:posts, primary_key, columns, indexes, foreign_keys).tap do |mock_klass| - allow(mock_klass).to receive(:translation_class).and_return(translation_klass) - end - end - - let :columns do - [ - mock_column(:id, :integer, limit: 8), - mock_column(:author_name, :string, limit: 50), - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: posts - # - # id :integer not null, primary key - # author_name :string(50) not null - # title :string(50) not null - # - EOS - end - - it 'returns schema info' do - is_expected.to eq expected_result - end - end - end - context 'when the primary key is an array (using composite_primary_keys)' do let :primary_key do [:a_id, :b_id] From 536b6f847054be06d0f2f682d6017c5359de003c Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:25:39 +0900 Subject: [PATCH 07/17] Move test cases when the primary key is an array (using composite_primary_keys) --- spec/lib/annotate/annotate_models_spec.rb | 70 ++++++++++------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index c4582e89a..066ca1d1e 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -427,6 +427,37 @@ def mock_column(name, type, options = {}) end end end + + context 'when the primary key is an array (using composite_primary_keys)' do + let :primary_key do + [:a_id, :b_id] + end + + let :columns do + [ + mock_column(:a_id, :integer), + mock_column(:b_id, :integer), + mock_column(:name, :string, limit: 50) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # a_id :integer not null, primary key + # b_id :integer not null, primary key + # name :string(50) not null + # + EOS + end + + it 'returns schema info' do + is_expected.to eq(expected_result) + end + end end end end @@ -830,45 +861,6 @@ def mock_column(name, type, options = {}) end end - context 'when header is "Schema Info"' do - let :header do - 'Schema Info' - end - - context 'when the primary key is specified' do - context 'when the primary key is an array (using composite_primary_keys)' do - let :primary_key do - [:a_id, :b_id] - end - - let :columns do - [ - mock_column(:a_id, :integer), - mock_column(:b_id, :integer), - mock_column(:name, :string, limit: 50) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # a_id :integer not null, primary key - # b_id :integer not null, primary key - # name :string(50) not null - # - EOS - end - - it 'returns schema info' do - is_expected.to eq(expected_result) - end - end - end - end - context 'when header is "== Schema Information"' do let :header do AnnotateModels::PREFIX From dfb04ed4c25ddb42a8996a0343602efd8c12d758 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:37:49 +0900 Subject: [PATCH 08/17] Move test cases when header is "== Schema Information" --- spec/lib/annotate/annotate_models_spec.rb | 530 +++++++++++----------- 1 file changed, 265 insertions(+), 265 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 066ca1d1e..616dfcf87 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -859,112 +859,77 @@ def mock_column(name, type, options = {}) end end end - end - - context 'when header is "== Schema Information"' do - let :header do - AnnotateModels::PREFIX - end - context 'when the primary key is specified' do - context 'when the primary_key is :id' do - let :primary_key do - :id - end - - let :columns do - [ - mock_column(:id, :integer), - mock_column(:name, :string, limit: 50) - ] - end - - context 'when option "format_rdoc" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_rdoc: true) - end + context 'when header is "== Schema Information"' do + let :header do + AnnotateModels::PREFIX + end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: users - # - # *id*:: integer, not null, primary key - # *name*:: string(50), not null - #-- - # == Schema Information End - #++ - EOS + context 'when the primary key is specified' do + context 'when the primary_key is :id' do + let :primary_key do + :id end - it 'returns schema info in RDoc format' do - is_expected.to eq(expected_result) + let :columns do + [ + mock_column(:id, :integer), + mock_column(:name, :string, limit: 50) + ] end - end - context 'when option "format_yard" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_yard: true) - end + context 'when option "format_rdoc" is true' do + subject do + AnnotateModels.get_schema_info(klass, header, format_rdoc: true) + end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: users - # - # @!attribute id - # @return [Integer] - # @!attribute name - # @return [String] - # - EOS - end + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: users + # + # *id*:: integer, not null, primary key + # *name*:: string(50), not null + #-- + # == Schema Information End + #++ + EOS + end - it 'returns schema info in YARD format' do - is_expected.to eq(expected_result) + it 'returns schema info in RDoc format' do + is_expected.to eq(expected_result) + end end - end - context 'when option "format_markdown" is true' do - context 'when other option is not specified' do + context 'when option "format_yard" is true' do subject do - AnnotateModels.get_schema_info(klass, header, format_markdown: true) + AnnotateModels.get_schema_info(klass, header, format_yard: true) end let :expected_result do <<~EOS # == Schema Information # - # Table name: `users` - # - # ### Columns + # Table name: users # - # Name | Type | Attributes - # ----------- | ------------------ | --------------------------- - # **`id`** | `integer` | `not null, primary key` - # **`name`** | `string(50)` | `not null` + # @!attribute id + # @return [Integer] + # @!attribute name + # @return [String] # EOS end - it 'returns schema info in Markdown format' do + it 'returns schema info in YARD format' do is_expected.to eq(expected_result) end end - context 'when option "show_indexes" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_markdown: true, show_indexes: true) - end - - context 'when indexes are normal' do - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', columns: ['foreign_thing_id']) - ] + context 'when option "format_markdown" is true' do + context 'when other option is not specified' do + subject do + AnnotateModels.get_schema_info(klass, header, format_markdown: true) end let :expected_result do @@ -980,222 +945,257 @@ def mock_column(name, type, options = {}) # **`id`** | `integer` | `not null, primary key` # **`name`** | `string(50)` | `not null` # - # ### Indexes - # - # * `index_rails_02e851e3b7`: - # * **`id`** - # * `index_rails_02e851e3b8`: - # * **`foreign_thing_id`** - # EOS end - it 'returns schema info with index information in Markdown format' do - is_expected.to eq expected_result + it 'returns schema info in Markdown format' do + is_expected.to eq(expected_result) end end - context 'when one of indexes includes "unique" clause' do - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: ['foreign_thing_id'], - unique: true) - ] + context 'when option "show_indexes" is true' do + subject do + AnnotateModels.get_schema_info(klass, header, format_markdown: true, show_indexes: true) end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # ----------- | ------------------ | --------------------------- - # **`id`** | `integer` | `not null, primary key` - # **`name`** | `string(50)` | `not null` - # - # ### Indexes - # - # * `index_rails_02e851e3b7`: - # * **`id`** - # * `index_rails_02e851e3b8` (_unique_): - # * **`foreign_thing_id`** - # - EOS - end + context 'when indexes are normal' do + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', columns: ['foreign_thing_id']) + ] + end - it 'returns schema info with index information in Markdown format' do - is_expected.to eq expected_result - end - end + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------- | ------------------ | --------------------------- + # **`id`** | `integer` | `not null, primary key` + # **`name`** | `string(50)` | `not null` + # + # ### Indexes + # + # * `index_rails_02e851e3b7`: + # * **`id`** + # * `index_rails_02e851e3b8`: + # * **`foreign_thing_id`** + # + EOS + end - context 'when one of indexes includes orderd index key' do - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: ['foreign_thing_id'], - orders: { 'foreign_thing_id' => :desc }) - ] + it 'returns schema info with index information in Markdown format' do + is_expected.to eq expected_result + end end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # ----------- | ------------------ | --------------------------- - # **`id`** | `integer` | `not null, primary key` - # **`name`** | `string(50)` | `not null` - # - # ### Indexes - # - # * `index_rails_02e851e3b7`: - # * **`id`** - # * `index_rails_02e851e3b8`: - # * **`foreign_thing_id DESC`** - # - EOS - end + context 'when one of indexes includes "unique" clause' do + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: ['foreign_thing_id'], + unique: true) + ] + end - it 'returns schema info with index information in Markdown format' do - is_expected.to eq expected_result - end - end + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------- | ------------------ | --------------------------- + # **`id`** | `integer` | `not null, primary key` + # **`name`** | `string(50)` | `not null` + # + # ### Indexes + # + # * `index_rails_02e851e3b7`: + # * **`id`** + # * `index_rails_02e851e3b8` (_unique_): + # * **`foreign_thing_id`** + # + EOS + end - context 'when one of indexes includes "where" clause and "unique" clause' do - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: ['foreign_thing_id'], - unique: true, - where: 'name IS NOT NULL') - ] + it 'returns schema info with index information in Markdown format' do + is_expected.to eq expected_result + end end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # ----------- | ------------------ | --------------------------- - # **`id`** | `integer` | `not null, primary key` - # **`name`** | `string(50)` | `not null` - # - # ### Indexes - # - # * `index_rails_02e851e3b7`: - # * **`id`** - # * `index_rails_02e851e3b8` (_unique_ _where_ name IS NOT NULL): - # * **`foreign_thing_id`** - # - EOS - end + context 'when one of indexes includes orderd index key' do + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: ['foreign_thing_id'], + orders: { 'foreign_thing_id' => :desc }) + ] + end - it 'returns schema info with index information in Markdown format' do - is_expected.to eq expected_result - end - end + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------- | ------------------ | --------------------------- + # **`id`** | `integer` | `not null, primary key` + # **`name`** | `string(50)` | `not null` + # + # ### Indexes + # + # * `index_rails_02e851e3b7`: + # * **`id`** + # * `index_rails_02e851e3b8`: + # * **`foreign_thing_id DESC`** + # + EOS + end - context 'when one of indexes includes "using" clause other than "btree"' do - let :indexes do - [ - mock_index('index_rails_02e851e3b7', columns: ['id']), - mock_index('index_rails_02e851e3b8', - columns: ['foreign_thing_id'], - using: 'hash') - ] + it 'returns schema info with index information in Markdown format' do + is_expected.to eq expected_result + end end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # ----------- | ------------------ | --------------------------- - # **`id`** | `integer` | `not null, primary key` - # **`name`** | `string(50)` | `not null` - # - # ### Indexes - # - # * `index_rails_02e851e3b7`: - # * **`id`** - # * `index_rails_02e851e3b8` (_using_ hash): - # * **`foreign_thing_id`** - # - EOS - end + context 'when one of indexes includes "where" clause and "unique" clause' do + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: ['foreign_thing_id'], + unique: true, + where: 'name IS NOT NULL') + ] + end + + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------- | ------------------ | --------------------------- + # **`id`** | `integer` | `not null, primary key` + # **`name`** | `string(50)` | `not null` + # + # ### Indexes + # + # * `index_rails_02e851e3b7`: + # * **`id`** + # * `index_rails_02e851e3b8` (_unique_ _where_ name IS NOT NULL): + # * **`foreign_thing_id`** + # + EOS + end - it 'returns schema info with index information in Markdown format' do - is_expected.to eq expected_result + it 'returns schema info with index information in Markdown format' do + is_expected.to eq expected_result + end end - end - end - context 'when option "show_foreign_keys" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_markdown: true, show_foreign_keys: true) - end + context 'when one of indexes includes "using" clause other than "btree"' do + let :indexes do + [ + mock_index('index_rails_02e851e3b7', columns: ['id']), + mock_index('index_rails_02e851e3b8', + columns: ['foreign_thing_id'], + using: 'hash') + ] + end - let :columns do - [ - mock_column(:id, :integer), - mock_column(:foreign_thing_id, :integer) - ] + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------- | ------------------ | --------------------------- + # **`id`** | `integer` | `not null, primary key` + # **`name`** | `string(50)` | `not null` + # + # ### Indexes + # + # * `index_rails_02e851e3b7`: + # * **`id`** + # * `index_rails_02e851e3b8` (_using_ hash): + # * **`foreign_thing_id`** + # + EOS + end + + it 'returns schema info with index information in Markdown format' do + is_expected.to eq expected_result + end + end end - context 'when foreign_keys have option "on_delete" and "on_update"' do - let :foreign_keys do + context 'when option "show_foreign_keys" is true' do + subject do + AnnotateModels.get_schema_info(klass, header, format_markdown: true, show_foreign_keys: true) + end + + let :columns do [ - mock_foreign_key('fk_rails_02e851e3b7', - 'foreign_thing_id', - 'foreign_things', - 'id', - on_delete: 'on_delete_value', - on_update: 'on_update_value') + mock_column(:id, :integer), + mock_column(:foreign_thing_id, :integer) ] end - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # ----------------------- | ------------------ | --------------------------- - # **`id`** | `integer` | `not null, primary key` - # **`foreign_thing_id`** | `integer` | `not null` - # - # ### Foreign Keys - # - # * `fk_rails_...` (_ON DELETE => on_delete_value ON UPDATE => on_update_value_): - # * **`foreign_thing_id => foreign_things.id`** - # - EOS - end + context 'when foreign_keys have option "on_delete" and "on_update"' do + let :foreign_keys do + [ + mock_foreign_key('fk_rails_02e851e3b7', + 'foreign_thing_id', + 'foreign_things', + 'id', + on_delete: 'on_delete_value', + on_update: 'on_update_value') + ] + end - it 'returns schema info with foreign_keys in Markdown format' do - is_expected.to eq(expected_result) + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------------------- | ------------------ | --------------------------- + # **`id`** | `integer` | `not null, primary key` + # **`foreign_thing_id`** | `integer` | `not null` + # + # ### Foreign Keys + # + # * `fk_rails_...` (_ON DELETE => on_delete_value ON UPDATE => on_update_value_): + # * **`foreign_thing_id => foreign_things.id`** + # + EOS + end + + it 'returns schema info with foreign_keys in Markdown format' do + is_expected.to eq(expected_result) + end end end end From 7263d55ecda9fc64fcd3ff5c7af5f4e5a8b606b2 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:43:21 +0900 Subject: [PATCH 09/17] Refactor options of AnnotateModels.get_schema_info --- spec/lib/annotate/annotate_models_spec.rb | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 616dfcf87..a3edb48b0 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -177,7 +177,7 @@ def mock_column(name, type, options = {}) describe '.get_schema_info' do subject do - AnnotateModels.get_schema_info(klass, header) + AnnotateModels.get_schema_info(klass, header, **options) end let :klass do @@ -193,8 +193,8 @@ def mock_column(name, type, options = {}) end context 'when option is not present' do - subject do - AnnotateModels.get_schema_info(klass, header) + let :options do + {} end context 'when header is "Schema Info"' do @@ -476,8 +476,8 @@ def mock_column(name, type, options = {}) context 'when indexes exist' do context 'when option "show_indexes" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, show_indexes: true) + let :options do + { show_indexes: true } end context 'when indexes are normal' do @@ -677,8 +677,8 @@ def mock_column(name, type, options = {}) end context 'when option "simple_indexes" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, simple_indexes: true) + let :options do + { simple_indexes: true } end context 'when one of indexes includes "orders" clause' do @@ -766,8 +766,8 @@ def mock_column(name, type, options = {}) end context 'when option "show_foreign_keys" is specified' do - subject do - AnnotateModels.get_schema_info(klass, header, show_foreign_keys: true) + let :options do + { show_foreign_keys: true } end context 'when foreign_keys does not have option' do @@ -829,8 +829,8 @@ def mock_column(name, type, options = {}) end context 'when option "show_foreign_keys" and "show_complete_foreign_keys" are specified' do - subject do - AnnotateModels.get_schema_info(klass, header, show_foreign_keys: true, show_complete_foreign_keys: true) + let :options do + { show_foreign_keys: true, show_complete_foreign_keys: true } end let :expected_result do @@ -879,8 +879,8 @@ def mock_column(name, type, options = {}) end context 'when option "format_rdoc" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_rdoc: true) + let :options do + { format_rdoc: true } end let :expected_result do @@ -903,8 +903,8 @@ def mock_column(name, type, options = {}) end context 'when option "format_yard" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_yard: true) + let :options do + { format_yard: true } end let :expected_result do @@ -928,8 +928,8 @@ def mock_column(name, type, options = {}) context 'when option "format_markdown" is true' do context 'when other option is not specified' do - subject do - AnnotateModels.get_schema_info(klass, header, format_markdown: true) + let :options do + { format_markdown: true } end let :expected_result do @@ -954,8 +954,8 @@ def mock_column(name, type, options = {}) end context 'when option "show_indexes" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_markdown: true, show_indexes: true) + let :options do + { format_markdown: true, show_indexes: true } end context 'when indexes are normal' do @@ -1149,8 +1149,8 @@ def mock_column(name, type, options = {}) end context 'when option "show_foreign_keys" is true' do - subject do - AnnotateModels.get_schema_info(klass, header, format_markdown: true, show_foreign_keys: true) + let :options do + { format_markdown: true, show_foreign_keys: true } end let :columns do @@ -1623,8 +1623,8 @@ def mock_column(name, type, options = {}) end context 'when "format_doc" and "with_comment" are specified in options' do - subject do - AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, format_rdoc: true, with_comment: true) + let :options do + { format_rdoc: true, with_comment: true } end context 'when columns are normal' do @@ -1656,8 +1656,8 @@ def mock_column(name, type, options = {}) end context 'when "format_markdown" and "with_comment" are specified in options' do - subject do - AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, format_markdown: true, with_comment: true) + let :options do + { format_markdown: true, with_comment: true } end context 'when columns have comments' do From 96e5e023f7fa18670f7adc3970fae5cb357700f4 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:46:46 +0900 Subject: [PATCH 10/17] Move test cases when "hide_limit_column_types" is specified in options --- spec/lib/annotate/annotate_models_spec.rb | 166 +++++++++++----------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index a3edb48b0..ac2f5bafd 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -856,6 +856,89 @@ def mock_column(name, type, options = {}) end end end + + context 'when "hide_limit_column_types" is specified in options' do + let :columns do + [ + mock_column(:id, :integer, limit: 8), + mock_column(:active, :boolean, limit: 1), + mock_column(:name, :string, limit: 50), + mock_column(:notes, :text, limit: 55) + ] + end + + context 'when "hide_limit_column_types" is blank string' do + let :options do + { hide_limit_column_types: '' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # active :boolean not null + # name :string(50) not null + # notes :text(55) not null + # + EOS + end + + it 'works with option "hide_limit_column_types"' do + is_expected.to eq expected_result + end + end + + context 'when "hide_limit_column_types" is "integer,boolean"' do + let :options do + { hide_limit_column_types: 'integer,boolean' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # active :boolean not null + # name :string(50) not null + # notes :text(55) not null + # + EOS + end + + it 'works with option "hide_limit_column_types"' do + is_expected.to eq expected_result + end + end + + context 'when "hide_limit_column_types" is "integer,boolean,string,text"' do + let :options do + { hide_limit_column_types: 'integer,boolean,string,text' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # active :boolean not null + # name :string not null + # notes :text not null + # + EOS + end + + it 'works with option "hide_limit_column_types"' do + is_expected.to eq expected_result + end + end + end end end end @@ -1309,89 +1392,6 @@ def mock_column(name, type, options = {}) end context 'with options' do - context 'when "hide_limit_column_types" is specified in options' do - let :columns do - [ - mock_column(:id, :integer, limit: 8), - mock_column(:active, :boolean, limit: 1), - mock_column(:name, :string, limit: 50), - mock_column(:notes, :text, limit: 55) - ] - end - - context 'when "hide_limit_column_types" is blank string' do - let :options do - { hide_limit_column_types: '' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # active :boolean not null - # name :string(50) not null - # notes :text(55) not null - # - EOS - end - - it 'works with option "hide_limit_column_types"' do - is_expected.to eq expected_result - end - end - - context 'when "hide_limit_column_types" is "integer,boolean"' do - let :options do - { hide_limit_column_types: 'integer,boolean' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # active :boolean not null - # name :string(50) not null - # notes :text(55) not null - # - EOS - end - - it 'works with option "hide_limit_column_types"' do - is_expected.to eq expected_result - end - end - - context 'when "hide_limit_column_types" is "integer,boolean,string,text"' do - let :options do - { hide_limit_column_types: 'integer,boolean,string,text' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # active :boolean not null - # name :string not null - # notes :text not null - # - EOS - end - - it 'works with option "hide_limit_column_types"' do - is_expected.to eq expected_result - end - end - end - context 'when "hide_default_column_types" is specified in options' do let :columns do [ From c781605e5542bcf48e568063089cc5e22319b582 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:48:00 +0900 Subject: [PATCH 11/17] Move test cases when "hide_default_column_types" is specified in options --- spec/lib/annotate/annotate_models_spec.rb | 158 +++++++++++----------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index ac2f5bafd..0370b124e 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -939,6 +939,85 @@ def mock_column(name, type, options = {}) end end end + + context 'when "hide_default_column_types" is specified in options' do + let :columns do + [ + mock_column(:profile, :json, default: {}), + mock_column(:settings, :jsonb, default: {}), + mock_column(:parameters, :hstore, default: {}) + ] + end + + context 'when "hide_default_column_types" is blank string' do + let :options do + { hide_default_column_types: '' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # profile :json not null + # settings :jsonb not null + # parameters :hstore not null + # + EOS + end + + it 'works with option "hide_default_column_types"' do + is_expected.to eq expected_result + end + end + + context 'when "hide_default_column_types" is "skip"' do + let :options do + { hide_default_column_types: 'skip' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # profile :json default({}), not null + # settings :jsonb default({}), not null + # parameters :hstore default({}), not null + # + EOS + end + + it 'works with option "hide_default_column_types"' do + is_expected.to eq expected_result + end + end + + context 'when "hide_default_column_types" is "json"' do + let :options do + { hide_default_column_types: 'json' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # profile :json not null + # settings :jsonb default({}), not null + # parameters :hstore default({}), not null + # + EOS + end + + it 'works with option "hide_limit_column_types"' do + is_expected.to eq expected_result + end + end + end end end end @@ -1392,85 +1471,6 @@ def mock_column(name, type, options = {}) end context 'with options' do - context 'when "hide_default_column_types" is specified in options' do - let :columns do - [ - mock_column(:profile, :json, default: {}), - mock_column(:settings, :jsonb, default: {}), - mock_column(:parameters, :hstore, default: {}) - ] - end - - context 'when "hide_default_column_types" is blank string' do - let :options do - { hide_default_column_types: '' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # profile :json not null - # settings :jsonb not null - # parameters :hstore not null - # - EOS - end - - it 'works with option "hide_default_column_types"' do - is_expected.to eq expected_result - end - end - - context 'when "hide_default_column_types" is "skip"' do - let :options do - { hide_default_column_types: 'skip' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # profile :json default({}), not null - # settings :jsonb default({}), not null - # parameters :hstore default({}), not null - # - EOS - end - - it 'works with option "hide_default_column_types"' do - is_expected.to eq expected_result - end - end - - context 'when "hide_default_column_types" is "json"' do - let :options do - { hide_default_column_types: 'json' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # profile :json not null - # settings :jsonb default({}), not null - # parameters :hstore default({}), not null - # - EOS - end - - it 'works with option "hide_limit_column_types"' do - is_expected.to eq expected_result - end - end - end - context 'when "classified_sort" is specified in options' do let :columns do [ From bdaa07b08bba5b67b6a99f401b773c4abae2ed3d Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:49:17 +0900 Subject: [PATCH 12/17] Move test cases 'when "classified_sort" is specified in options' --- spec/lib/annotate/annotate_models_spec.rb | 66 +++++++++++------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 0370b124e..d8c4f3d1f 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -1018,6 +1018,39 @@ def mock_column(name, type, options = {}) end end end + + context 'when "classified_sort" is specified in options' do + let :columns do + [ + mock_column(:active, :boolean, limit: 1), + mock_column(:name, :string, limit: 50), + mock_column(:notes, :text, limit: 55) + ] + end + + context 'when "classified_sort" is "yes"' do + let :options do + { classified_sort: 'yes' } + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # active :boolean not null + # name :string(50) not null + # notes :text(55) not null + # + EOS + end + + it 'works with option "classified_sort"' do + is_expected.to eq expected_result + end + end + end end end end @@ -1471,39 +1504,6 @@ def mock_column(name, type, options = {}) end context 'with options' do - context 'when "classified_sort" is specified in options' do - let :columns do - [ - mock_column(:active, :boolean, limit: 1), - mock_column(:name, :string, limit: 50), - mock_column(:notes, :text, limit: 55) - ] - end - - context 'when "classified_sort" is "yes"' do - let :options do - { classified_sort: 'yes' } - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # active :boolean not null - # name :string(50) not null - # notes :text(55) not null - # - EOS - end - - it 'works with option "classified_sort"' do - is_expected.to eq expected_result - end - end - end - context 'when "with_comment" is specified in options' do context 'when "with_comment" is "yes"' do let :options do From ecb2a0bd422d8a70ce7a7a44e7d91067aeece42f Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:50:51 +0900 Subject: [PATCH 13/17] Move test cases when "with_comment" is specified in options --- spec/lib/annotate/annotate_models_spec.rb | 230 +++++++++++----------- 1 file changed, 111 insertions(+), 119 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index d8c4f3d1f..bec059718 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -1051,6 +1051,117 @@ def mock_column(name, type, options = {}) end end end + + context 'when "with_comment" is specified in options' do + context 'when "with_comment" is "yes"' do + let :options do + { with_comment: 'yes' } + end + + context 'when columns have comments' do + let :columns do + [ + mock_column(:id, :integer, limit: 8, comment: 'ID'), + mock_column(:active, :boolean, limit: 1, comment: 'Active'), + mock_column(:name, :string, limit: 50, comment: 'Name'), + mock_column(:notes, :text, limit: 55, comment: 'Notes'), + mock_column(:no_comment, :text, limit: 20, comment: nil) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id(ID) :integer not null, primary key + # active(Active) :boolean not null + # name(Name) :string(50) not null + # notes(Notes) :text(55) not null + # no_comment :text(20) not null + # + EOS + end + + it 'works with option "with_comment"' do + is_expected.to eq expected_result + end + end + + context 'when columns have multibyte comments' do + let :columns do + [ + mock_column(:id, :integer, limit: 8, comment: 'ID'), + mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'), + mock_column(:name, :string, limit: 50, comment: 'NAME'), + mock_column(:notes, :text, limit: 55, comment: 'NOTES'), + mock_column(:cyrillic, :text, limit: 30, comment: 'Кириллица'), + mock_column(:japanese, :text, limit: 60, comment: '熊本大学 イタリア 宝島'), + mock_column(:arabic, :text, limit: 20, comment: 'لغة'), + mock_column(:no_comment, :text, limit: 20, comment: nil), + mock_column(:location, :geometry_collection, limit: nil, comment: nil) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id(ID) :integer not null, primary key + # active(ACTIVE) :boolean not null + # name(NAME) :string(50) not null + # notes(NOTES) :text(55) not null + # cyrillic(Кириллица) :text(30) not null + # japanese(熊本大学 イタリア 宝島) :text(60) not null + # arabic(لغة) :text(20) not null + # no_comment :text(20) not null + # location :geometry_collect not null + # + EOS + end + + it 'works with option "with_comment"' do + is_expected.to eq expected_result + end + end + + context 'when geometry columns are included' do + let :columns do + [ + mock_column(:id, :integer, limit: 8), + mock_column(:active, :boolean, default: false, null: false), + mock_column(:geometry, :geometry, + geometric_type: 'Geometry', srid: 4326, + limit: { srid: 4326, type: 'geometry' }), + mock_column(:location, :geography, + geometric_type: 'Point', srid: 0, + limit: { srid: 0, type: 'geometry' }) + ] + end + + let :expected_result do + <<~EOS + # Schema Info + # + # Table name: users + # + # id :integer not null, primary key + # active :boolean default(FALSE), not null + # geometry :geometry not null, geometry, 4326 + # location :geography not null, point, 0 + # + EOS + end + + it 'works with option "with_comment"' do + is_expected.to eq expected_result + end + end + end + end end end end @@ -1498,125 +1609,6 @@ def mock_column(name, type, options = {}) AnnotateModels.get_schema_info(klass, header, options) end - context 'when header is "Schema Info"' do - let :header do - 'Schema Info' - end - - context 'with options' do - context 'when "with_comment" is specified in options' do - context 'when "with_comment" is "yes"' do - let :options do - { with_comment: 'yes' } - end - - context 'when columns have comments' do - let :columns do - [ - mock_column(:id, :integer, limit: 8, comment: 'ID'), - mock_column(:active, :boolean, limit: 1, comment: 'Active'), - mock_column(:name, :string, limit: 50, comment: 'Name'), - mock_column(:notes, :text, limit: 55, comment: 'Notes'), - mock_column(:no_comment, :text, limit: 20, comment: nil) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id(ID) :integer not null, primary key - # active(Active) :boolean not null - # name(Name) :string(50) not null - # notes(Notes) :text(55) not null - # no_comment :text(20) not null - # - EOS - end - - it 'works with option "with_comment"' do - is_expected.to eq expected_result - end - end - - context 'when columns have multibyte comments' do - let :columns do - [ - mock_column(:id, :integer, limit: 8, comment: 'ID'), - mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'), - mock_column(:name, :string, limit: 50, comment: 'NAME'), - mock_column(:notes, :text, limit: 55, comment: 'NOTES'), - mock_column(:cyrillic, :text, limit: 30, comment: 'Кириллица'), - mock_column(:japanese, :text, limit: 60, comment: '熊本大学 イタリア 宝島'), - mock_column(:arabic, :text, limit: 20, comment: 'لغة'), - mock_column(:no_comment, :text, limit: 20, comment: nil), - mock_column(:location, :geometry_collection, limit: nil, comment: nil) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id(ID) :integer not null, primary key - # active(ACTIVE) :boolean not null - # name(NAME) :string(50) not null - # notes(NOTES) :text(55) not null - # cyrillic(Кириллица) :text(30) not null - # japanese(熊本大学 イタリア 宝島) :text(60) not null - # arabic(لغة) :text(20) not null - # no_comment :text(20) not null - # location :geometry_collect not null - # - EOS - end - - it 'works with option "with_comment"' do - is_expected.to eq expected_result - end - end - - context 'when geometry columns are included' do - let :columns do - [ - mock_column(:id, :integer, limit: 8), - mock_column(:active, :boolean, default: false, null: false), - mock_column(:geometry, :geometry, - geometric_type: 'Geometry', srid: 4326, - limit: { srid: 4326, type: 'geometry' }), - mock_column(:location, :geography, - geometric_type: 'Point', srid: 0, - limit: { srid: 0, type: 'geometry' }) - ] - end - - let :expected_result do - <<~EOS - # Schema Info - # - # Table name: users - # - # id :integer not null, primary key - # active :boolean default(FALSE), not null - # geometry :geometry not null, geometry, 4326 - # location :geography not null, point, 0 - # - EOS - end - - it 'works with option "with_comment"' do - is_expected.to eq expected_result - end - end - end - end - end - end - context 'when header is "== Schema Information"' do let :header do AnnotateModels::PREFIX From 5464b757cde298af64ddaa125cf51efd7357da74 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:58:01 +0900 Subject: [PATCH 14/17] Move test cases when "format_doc" and "with_comment" are specified in options --- spec/lib/annotate/annotate_models_spec.rb | 66 +++++++++++------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index bec059718..19fc44589 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -1505,6 +1505,39 @@ def mock_column(name, type, options = {}) end end end + + context 'when "format_doc" and "with_comment" are specified in options' do + let :options do + { format_rdoc: true, with_comment: true } + end + + context 'when columns are normal' do + let :columns do + [ + mock_column(:id, :integer, comment: 'ID'), + mock_column(:name, :string, limit: 50, comment: 'Name') + ] + end + + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: users + # + # *id(ID)*:: integer, not null, primary key + # *name(Name)*:: string(50), not null + #-- + # == Schema Information End + #++ + EOS + end + + it 'returns schema info in RDoc format' do + is_expected.to eq expected_result + end + end + end end end end @@ -1614,39 +1647,6 @@ def mock_column(name, type, options = {}) AnnotateModels::PREFIX end - context 'when "format_doc" and "with_comment" are specified in options' do - let :options do - { format_rdoc: true, with_comment: true } - end - - context 'when columns are normal' do - let :columns do - [ - mock_column(:id, :integer, comment: 'ID'), - mock_column(:name, :string, limit: 50, comment: 'Name') - ] - end - - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: users - # - # *id(ID)*:: integer, not null, primary key - # *name(Name)*:: string(50), not null - #-- - # == Schema Information End - #++ - EOS - end - - it 'returns schema info in RDoc format' do - is_expected.to eq expected_result - end - end - end - context 'when "format_markdown" and "with_comment" are specified in options' do let :options do { format_markdown: true, with_comment: true } From 227e80cf80f47adca2329d297159480c6637449f Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sat, 8 Feb 2020 21:59:12 +0900 Subject: [PATCH 15/17] Move test cases when "format_markdown" and "with_comment" are specified in options --- spec/lib/annotate/annotate_models_spec.rb | 144 ++++++++++------------ 1 file changed, 64 insertions(+), 80 deletions(-) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 19fc44589..c078afcf1 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -1538,6 +1538,70 @@ def mock_column(name, type, options = {}) end end end + + context 'when "format_markdown" and "with_comment" are specified in options' do + let :options do + { format_markdown: true, with_comment: true } + end + + context 'when columns have comments' do + let :columns do + [ + mock_column(:id, :integer, comment: 'ID'), + mock_column(:name, :string, limit: 50, comment: 'Name') + ] + end + + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # ----------------- | ------------------ | --------------------------- + # **`id(ID)`** | `integer` | `not null, primary key` + # **`name(Name)`** | `string(50)` | `not null` + # + EOS + end + + it 'returns schema info in Markdown format' do + is_expected.to eq expected_result + end + end + + context 'when columns have multibyte comments' do + let :columns do + [ + mock_column(:id, :integer, comment: 'ID'), + mock_column(:name, :string, limit: 50, comment: 'NAME') + ] + end + + let :expected_result do + <<~EOS + # == Schema Information + # + # Table name: `users` + # + # ### Columns + # + # Name | Type | Attributes + # --------------------- | ------------------ | --------------------------- + # **`id(ID)`** | `integer` | `not null, primary key` + # **`name(NAME)`** | `string(50)` | `not null` + # + EOS + end + + it 'returns schema info in Markdown format' do + is_expected.to eq expected_result + end + end + end end end end @@ -1633,86 +1697,6 @@ def mock_column(name, type, options = {}) end end - describe '.get_schema_info (with custom options)' do - let :klass do - mock_class(:users, :id, columns) - end - - subject do - AnnotateModels.get_schema_info(klass, header, options) - end - - context 'when header is "== Schema Information"' do - let :header do - AnnotateModels::PREFIX - end - - context 'when "format_markdown" and "with_comment" are specified in options' do - let :options do - { format_markdown: true, with_comment: true } - end - - context 'when columns have comments' do - let :columns do - [ - mock_column(:id, :integer, comment: 'ID'), - mock_column(:name, :string, limit: 50, comment: 'Name') - ] - end - - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # ----------------- | ------------------ | --------------------------- - # **`id(ID)`** | `integer` | `not null, primary key` - # **`name(Name)`** | `string(50)` | `not null` - # - EOS - end - - it 'returns schema info in Markdown format' do - is_expected.to eq expected_result - end - end - - context 'when columns have multibyte comments' do - let :columns do - [ - mock_column(:id, :integer, comment: 'ID'), - mock_column(:name, :string, limit: 50, comment: 'NAME') - ] - end - - let :expected_result do - <<~EOS - # == Schema Information - # - # Table name: `users` - # - # ### Columns - # - # Name | Type | Attributes - # --------------------- | ------------------ | --------------------------- - # **`id(ID)`** | `integer` | `not null, primary key` - # **`name(NAME)`** | `string(50)` | `not null` - # - EOS - end - - it 'returns schema info in Markdown format' do - is_expected.to eq expected_result - end - end - end - end - end - describe '.get_model_files' do subject { described_class.get_model_files(options) } From 9695b9b7d34e40b95b42d5cb9258d3c8876006ab Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Sun, 9 Feb 2020 00:55:43 +0900 Subject: [PATCH 16/17] Execute `rubocop --auto-gen-config` --- .rubocop_todo.yml | 401 ++++++---------------------------------------- 1 file changed, 52 insertions(+), 349 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5c0697b68..acb9f3749 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,35 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-12-24 20:33:53 -0800 using RuboCop version 0.68.1. +# on 2020-02-09 01:08:44 +0900 using RuboCop version 0.68.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 9 -# Configuration parameters: Include. -# Include: **/*.gemfile, **/Gemfile, **/gems.rb -Bundler/DuplicatedGem: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/Gemfile' - - 'spec/integration/rails_3.2.2/Gemfile' - - 'spec/integration/rails_3.2.8/Gemfile' - - 'spec/integration/rails_3.2_autoloading_factory_girl/Gemfile' - - 'spec/integration/rails_3.2_custom_inflections/Gemfile' - - 'spec/integration/rails_3.2_with_asset_pipeline/Gemfile' - - 'spec/integration/rails_4.1.1/Gemfile' - - 'spec/integration/rails_4.2.0/Gemfile' - - 'spec/integration/standalone/Gemfile' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: TreatCommentsAsGroupSeparators, Include. -# Include: **/*.gemfile, **/Gemfile, **/gems.rb -Bundler/OrderedGems: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/Gemfile' - - 'spec/integration/rails_3.2_with_asset_pipeline/Gemfile' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: TreatCommentsAsGroupSeparators, Include. @@ -45,13 +21,7 @@ Gemspec/RequiredRubyVersion: Exclude: - 'annotate.gemspec' -# Offense count: 2 -# Cop supports --auto-correct. -Layout/AlignArray: - Exclude: - - 'spec/lib/annotate/annotate_models_spec.rb' - -# Offense count: 111 +# Offense count: 65 # Cop supports --auto-correct. # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. # SupportedHashRocketStyles: key, separator, table @@ -60,10 +30,6 @@ Layout/AlignArray: Layout/AlignHash: Exclude: - 'lib/generators/annotate/templates/auto_annotate_models.rake' - - 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb' - - 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake' - - 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake' - - 'spec/integration/standalone/config/init.rb' - 'spec/lib/annotate/annotate_models_spec.rb' # Offense count: 1 @@ -74,80 +40,22 @@ Layout/BlockAlignment: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 47 -# Cop supports --auto-correct. -Layout/ClosingHeredocIndentation: - Exclude: - - 'spec/integration/rails_2.3_with_bundler.rb' - - 'spec/integration/rails_3.2.2.rb' - - 'spec/integration/rails_3.2.8.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl.rb' - - 'spec/integration/rails_3.2_custom_inflections.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline.rb' - - 'spec/integration/standalone.rb' - - 'spec/lib/annotate/annotate_models_spec.rb' - -# Offense count: 14 +# Offense count: 9 # Cop supports --auto-correct. Layout/EmptyLineAfterGuardClause: Exclude: - 'Rakefile' - 'lib/annotate.rb' - 'lib/annotate/annotate_models.rb' - - 'lib/annotate/annotate_routes.rb' - - 'spec/integration/integration_spec.rb' -# Offense count: 10 +# Offense count: 2 # Cop supports --auto-correct. Layout/EmptyLineAfterMagicComment: Exclude: - 'annotate.gemspec' - - 'spec/integration/rails_3.2.2/db/schema.rb' - - 'spec/integration/rails_3.2.8/db/schema.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb' - - 'spec/integration/rails_3.2_custom_inflections/db/schema.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline/db/schema.rb' - - 'spec/integration/rails_4.1.1/db/schema.rb' - - 'spec/integration/rails_4.2.0/db/schema.rb' - - 'spec/integration/standalone/db/schema.rb' - 'spec/lib/annotate/annotate_models_spec.rb' -# Offense count: 2 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'spec/integration/rails_4.1.1/Gemfile' - - 'spec/integration/rails_4.2.0/Gemfile' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundAccessModifier: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundArguments: - Exclude: - - 'spec/lib/annotate/annotate_routes_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/db/schema.rb' - - 'spec/integration/rails_4.1.1/db/schema.rb' - - 'spec/integration/rails_4.2.0/db/schema.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundExceptionHandlingKeywords: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - -# Offense count: 24 +# Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. Layout/ExtraSpacing: @@ -155,58 +63,6 @@ Layout/ExtraSpacing: - 'Guardfile' - 'lib/annotate/annotate_models.rb' - 'lib/tasks/annotate_routes.rake' - - 'spec/integration/rails_2.3_with_bundler/script/console' - - 'spec/integration/rails_3.2.2/script/rails' - - 'spec/integration/rails_3.2.8/script/rails' - - 'spec/integration/rails_3.2_autoloading_factory_girl/script/rails' - - 'spec/integration/rails_3.2_custom_inflections/script/rails' - - 'spec/integration/rails_3.2_with_asset_pipeline/script/rails' - - 'spec/integration/rails_4.1.1/Gemfile' - - 'spec/integration/rails_4.1.1/config.ru' - - 'spec/integration/rails_4.2.0/Gemfile' - - 'spec/integration/rails_4.2.0/config.ru' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/IndentFirstHashElement: - EnforcedStyle: consistent - -# Offense count: 55 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: - Exclude: - - 'spec/integration/integration_spec.rb' - - 'spec/integration/rails_2.3_with_bundler.rb' - - 'spec/integration/rails_3.2.2.rb' - - 'spec/integration/rails_3.2.8.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl.rb' - - 'spec/integration/rails_3.2_custom_inflections.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline.rb' - - 'spec/integration/standalone.rb' - - 'spec/lib/annotate/annotate_models_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: normal, rails -Layout/IndentationConsistency: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - - 'spec/integration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb' - - 'spec/integration/rails_4.1.1/app/models/task.rb' - - 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb' - - 'spec/integration/rails_4.2.0/app/models/task.rb' # Offense count: 4 # Cop supports --auto-correct. @@ -224,30 +80,15 @@ Layout/MultilineOperationIndentation: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 3 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: space, no_space Layout/SpaceAroundEqualsInParameterDefault: Exclude: - 'lib/annotate/annotate_routes.rb' - - 'spec/integration/common_validation.rb' - -# Offense count: 9 -# Cop supports --auto-correct. -Layout/SpaceAroundKeyword: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/Gemfile' - - 'spec/integration/rails_3.2.2/Gemfile' - - 'spec/integration/rails_3.2.8/Gemfile' - - 'spec/integration/rails_3.2_autoloading_factory_girl/Gemfile' - - 'spec/integration/rails_3.2_custom_inflections/Gemfile' - - 'spec/integration/rails_3.2_with_asset_pipeline/Gemfile' - - 'spec/integration/rails_4.1.1/Gemfile' - - 'spec/integration/rails_4.2.0/Gemfile' - - 'spec/integration/standalone/Gemfile' -# Offense count: 5 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceAroundOperators: @@ -270,15 +111,6 @@ Layout/SpaceBeforeComment: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideArrayLiteralBrackets: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/environment.rb' - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. @@ -313,57 +145,18 @@ Layout/SpaceInsideStringInterpolation: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -Layout/Tab: - Exclude: - - 'spec/integration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb' - - 'spec/integration/rails_4.1.1/app/models/task.rb' - - 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb' - - 'spec/integration/rails_4.2.0/app/models/task.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingBlankLines: - Exclude: - - 'spec/integration/rails_4.1.1/app/models/task_observer.rb' - - 'spec/integration/rails_4.1.1/config/initializers/cookies_serializer.rb' - - 'spec/integration/rails_4.2.0/app/models/task_observer.rb' - - 'spec/integration/rails_4.2.0/config/initializers/cookies_serializer.rb' - -# Offense count: 3 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: AllowInHeredoc. Layout/TrailingWhitespace: Exclude: - - 'spec/integration/rails_2.3_with_bundler/db/schema.rb' - 'spec/lib/annotate/annotate_routes_spec.rb' -# Offense count: 3 +# Offense count: 2 # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: Exclude: - 'lib/annotate/annotate_models.rb' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -Lint/DeprecatedClassMethods: - Exclude: - - 'lib/annotate/annotate_routes.rb' - - 'spec/integration/rails_3.2.2/config/boot.rb' - - 'spec/integration/rails_3.2.8/config/boot.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl/config/boot.rb' - - 'spec/integration/rails_3.2_custom_inflections/config/boot.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline/config/boot.rb' - -# Offense count: 1 -Lint/DuplicateMethods: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' # Offense count: 1 Lint/HandleExceptions: @@ -378,11 +171,10 @@ Lint/InheritException: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 3 +# Offense count: 2 # Configuration parameters: MaximumRangeSize. Lint/MissingCopEnableDirective: Exclude: - - 'lib/annotate.rb' - 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_routes.rb' @@ -391,55 +183,45 @@ Lint/RescueException: Exclude: - 'Rakefile' -# Offense count: 5 -# Cop supports --auto-correct. -Lint/ScriptPermission: - Exclude: - - 'spec/integration/rails_3.2.2/Rakefile' - - 'spec/integration/rails_3.2.8/Rakefile' - - 'spec/integration/rails_3.2_autoloading_factory_girl/Rakefile' - - 'spec/integration/rails_3.2_custom_inflections/Rakefile' - - 'spec/integration/rails_3.2_with_asset_pipeline/Rakefile' - # Offense count: 1 Lint/ShadowingOuterLocalVariable: Exclude: - 'Rakefile' -# Offense count: 20 +# Offense count: 21 Metrics/AbcSize: - Max: 155 + Max: 145 -# Offense count: 31 +# Offense count: 8 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 268 + Max: 53 # Offense count: 1 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 4 -# Offense count: 10 +# Offense count: 11 Metrics/CyclomaticComplexity: - Max: 41 + Max: 37 -# Offense count: 30 +# Offense count: 29 # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: - Max: 80 + Max: 71 # Offense count: 8 Metrics/PerceivedComplexity: - Max: 47 + Max: 42 # Offense count: 1 Naming/AccessorMethodName: Exclude: - 'lib/annotate.rb' -# Offense count: 79 +# Offense count: 82 # Configuration parameters: Blacklist. # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) Naming/HeredocDelimiterNaming: @@ -447,13 +229,12 @@ Naming/HeredocDelimiterNaming: - 'spec/lib/annotate/annotate_models_spec.rb' - 'spec/lib/annotate/annotate_routes_spec.rb' -# Offense count: 2 +# Offense count: 1 # Configuration parameters: EnforcedStyleForLeadingUnderscores. # SupportedStylesForLeadingUnderscores: disallowed, required, optional Naming/MemoizedInstanceVariableName: Exclude: - 'lib/annotate/annotate_routes.rb' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' # Offense count: 1 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. @@ -469,49 +250,18 @@ Style/AccessModifierDeclarations: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: percent_q, bare_percent -Style/BarePercentLiterals: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake' - - 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake' - - 'spec/integration/standalone/config/init.rb' - # Offense count: 1 Style/CaseEquality: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 14 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: Exclude: - 'lib/annotate/active_record_patch.rb' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - - 'spec/integration/rails_2.3_with_bundler/test/test_helper.rb' - - 'spec/integration/rails_3.2.2/test/test_helper.rb' - - 'spec/integration/rails_3.2.8/test/test_helper.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl/test/test_helper.rb' - - 'spec/integration/rails_3.2_custom_inflections/test/test_helper.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline/test/test_helper.rb' - - 'spec/integration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb' - - 'spec/integration/rails_4.1.1/app/models/sub1/user.rb' - - 'spec/integration/rails_4.1.1/test/test_helper.rb' - - 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb' - - 'spec/integration/rails_4.2.0/app/models/sub1/user.rb' - - 'spec/integration/rails_4.2.0/test/test_helper.rb' # Offense count: 2 Style/ClassVars: @@ -536,25 +286,19 @@ Style/Documentation: - 'lib/generators/annotate/install_generator.rb' - 'lib/tasks/annotate_models_migrate.rake' -# Offense count: 10 +# Offense count: 2 # Cop supports --auto-correct. Style/Encoding: Exclude: - 'annotate.gemspec' - - 'spec/integration/rails_3.2.2/db/schema.rb' - - 'spec/integration/rails_3.2.8/db/schema.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb' - - 'spec/integration/rails_3.2_custom_inflections/db/schema.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline/db/schema.rb' - - 'spec/integration/rails_4.1.1/db/schema.rb' - - 'spec/integration/rails_4.2.0/db/schema.rb' - - 'spec/integration/standalone/db/schema.rb' - 'spec/lib/annotate/annotate_models_spec.rb' -# Offense count: 48 +# Offense count: 2 # Cop supports --auto-correct. Style/ExpandPathArguments: - Enabled: false + Exclude: + - 'annotate.gemspec' + - 'spec/spec_helper.rb' # Offense count: 10 # Cop supports --auto-correct. @@ -572,29 +316,29 @@ Style/FormatStringToken: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 189 +# Offense count: 26 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: when_needed, always, never Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 5 +# Offense count: 1 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: - - 'lib/annotate/annotate_routes.rb' - 'lib/tasks/annotate_models_migrate.rake' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' -# Offense count: 57 +# Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys Style/HashSyntax: - Enabled: false + Exclude: + - 'lib/tasks/annotate_routes.rake' + - 'spec/lib/annotate/annotate_models_spec.rb' -# Offense count: 11 +# Offense count: 8 # Cop supports --auto-correct. Style/IfUnlessModifier: Exclude: @@ -620,11 +364,10 @@ Style/MissingRespondToMissing: Exclude: - 'lib/annotate/active_record_patch.rb' -# Offense count: 3 +# Offense count: 1 Style/MixinUsage: Exclude: - 'Rakefile' - - 'spec/integration/integration_spec.rb' # Offense count: 3 Style/MultilineBlockChain: @@ -633,16 +376,6 @@ Style/MultilineBlockChain: - 'lib/annotate/annotate_models.rb' - 'spec/spec_helper.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Exclude: - - 'lib/annotate/annotate_routes.rb' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - - 'spec/integration/rails_2.3_with_bundler/config/environment.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: Whitelist. @@ -651,12 +384,6 @@ Style/NestedParenthesizedCalls: Exclude: - 'bin/annotate' -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 15 - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. @@ -667,7 +394,7 @@ Style/NumericPredicate: - 'lib/annotate.rb' - 'lib/annotate/annotate_models.rb' -# Offense count: 20 +# Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -676,23 +403,10 @@ Style/PercentLiteralDelimiters: - 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_routes.rb' - 'lib/tasks/annotate_models_migrate.rake' - - 'spec/integration/rails_3.2.2/config/application.rb' - - 'spec/integration/rails_3.2.8/config/application.rb' - - 'spec/integration/rails_3.2_autoloading_factory_girl/config/application.rb' - - 'spec/integration/rails_3.2_custom_inflections/config/application.rb' - - 'spec/integration/rails_3.2_with_asset_pipeline/config/application.rb' - - 'spec/integration/rails_4.1.1/app/models/task.rb' - - 'spec/integration/rails_4.2.0/app/models/task.rb' - 'spec/lib/annotate/annotate_models_spec.rb' - 'spec/lib/tasks/annotate_models_migrate_spec.rb' - 'spec/spec_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/PerlBackrefs: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -737,12 +451,11 @@ Style/RegexpLiteral: - 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_routes.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. Style/RescueModifier: Exclude: - 'lib/annotate/annotate_models.rb' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -760,28 +473,28 @@ Style/SafeNavigation: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Exclude: - - 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb' - -# Offense count: 18 +# Offense count: 15 # Cop supports --auto-correct. Style/StderrPuts: Exclude: - 'Rakefile' - 'lib/annotate.rb' - 'lib/annotate/annotate_models.rb' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' -# Offense count: 249 +# Offense count: 111 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: - Enabled: false + Exclude: + - 'annotate.gemspec' + - 'lib/annotate/annotate_models.rb' + - 'lib/annotate/parser.rb' + - 'lib/tasks/annotate_models_migrate.rake' + - 'lib/tasks/annotate_routes.rake' + - 'spec/lib/annotate/annotate_models_spec.rb' + - 'spec/lib/annotate/annotate_routes_spec.rb' + - 'spec/lib/annotate/parser_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -791,7 +504,7 @@ Style/StringLiteralsInInterpolation: Exclude: - 'lib/annotate/annotate_models.rb' -# Offense count: 10 +# Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: MinSize. # SupportedStyles: percent, brackets @@ -804,7 +517,7 @@ Style/SymbolLiteral: Exclude: - 'spec/lib/annotate/annotate_models_spec.rb' -# Offense count: 1 +# Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma @@ -814,23 +527,13 @@ Style/TrailingCommaInArrayLiteral: # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake' - - 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake' - -# Offense count: 4 -# Cop supports --auto-correct. Style/UnneededPercentQ: Exclude: - 'annotate.gemspec' - - 'spec/integration/rails_2.3_with_bundler/config/boot.rb' -# Offense count: 477 +# Offense count: 354 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 276 + Max: 264 From 6d1e32bb9b4962be967a5007c2ea9482703633a3 Mon Sep 17 00:00:00 2001 From: Shu Fujita Date: Mon, 10 Feb 2020 20:05:51 +0900 Subject: [PATCH 17/17] Execute `rubocop --auto-gen-config` --- .rubocop_todo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index acb9f3749..ca4c82679 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-02-09 01:08:44 +0900 using RuboCop version 0.68.1. +# on 2020-02-10 20:05:28 +0900 using RuboCop version 0.68.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new