Skip to content

Commit 28b5bd4

Browse files
author
Shane da Silva
committed
Clean up RailsSchemaUpToDate
Address all Rubocop warnings. Change-Id: Iaeb984a988fd4910d0c21103473504e58120b1b0 Reviewed-on: http://gerrit.causes.com/37947 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane@causes.com>
1 parent 1fc3dd7 commit 28b5bd4

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ def run
1212
up_to_date = schema.include?(latest_version)
1313

1414
unless up_to_date
15-
return :bad, "The latest migration version you're committing is #{latest_version} but your schema file #{schema_files.join(' or ')} is on a different version."
15+
return :bad, "The latest migration version you're committing is " \
16+
"#{latest_version}, but your schema file " \
17+
"#{schema_files.join(' or ')} is on a different version."
1618
end
1719
end
1820

1921
:good
2022
end
2123

22-
private
24+
private
2325

2426
def migration_files
2527
@migration_files ||= applicable_files.select do |file|

spec/overcommit/hook/pre_commit/rails_schema_up_to_date_spec.rb

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
describe Overcommit::Hook::PreCommit::RailsSchemaUpToDate do
44
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
55
let(:context) { double('context') }
6-
let(:migration_files) { %w{db/migrate/20140304042233_some_migration.rb
7-
db/migrate/20140305123456_some_migration.rb} }
86
let(:ruby_schema_file) { 'db/schema.rb' }
97
let(:sql_schema_file) { 'db/structure.sql' }
108

11-
subject { described_class.new(config, context) }
9+
let(:migration_files) do
10+
%w[
11+
db/migrate/20140304042233_some_migration.rb
12+
db/migrate/20140305123456_some_migration.rb
13+
]
14+
end
15+
16+
subject { described_class.new(config, context) }
1217

1318
context "when a migration was added but the schema wasn't updated" do
1419
before do
@@ -31,7 +36,7 @@
3136
it { should fail_hook }
3237
end
3338

34-
context "when a ruby schema file was added but no migration files were" do
39+
context 'when a Ruby schema file was added but no migration files were' do
3540
before do
3641
subject.stub(:applicable_files).and_return([ruby_schema_file])
3742
end
@@ -48,7 +53,7 @@
4853
it { should fail_hook }
4954
end
5055

51-
context "when a SQL schema file was added but no migration files were" do
56+
context 'when a SQL schema file was added but no migration files were' do
5257
before do
5358
subject.stub(:applicable_files).and_return([sql_schema_file])
5459
end
@@ -65,7 +70,7 @@
6570
it { should fail_hook }
6671
end
6772

68-
context "when both a Ruby schema file with the latest version and migrations are added" do
73+
context 'when a Ruby schema file with the latest version and migrations are added' do
6974
before do
7075
subject.stub(:applicable_files).and_return(migration_files << ruby_schema_file)
7176
end
@@ -89,7 +94,7 @@
8994
it { should pass }
9095
end
9196

92-
context "when both a Ruby schema file which is not at the latest version and migrations are added" do
97+
context 'when a Ruby schema file which is not at the latest version and migrations are added' do
9398
before do
9499
subject.stub(:applicable_files).and_return(migration_files << ruby_schema_file)
95100
end
@@ -113,7 +118,7 @@
113118
it { should fail_hook }
114119
end
115120

116-
context "when both a SQL schema file with the latest version and migrations are added" do
121+
context 'when a SQL schema file with the latest version and migrations are added' do
117122
before do
118123
subject.stub(:applicable_files).and_return(migration_files << sql_schema_file)
119124
end
@@ -137,7 +142,7 @@
137142
it { should pass }
138143
end
139144

140-
context "when both a SQL schema file which is not at the latest version and migrations are added" do
145+
context 'when a SQL schema file which is not at the latest version and migrations are added' do
141146
before do
142147
subject.stub(:applicable_files).and_return(migration_files << sql_schema_file)
143148
end

0 commit comments

Comments
 (0)