rails_best_practices 0.3.18 → 0.3.19
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.19
|
@@ -76,6 +76,14 @@ module RailsBestPractices
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
+
if :call == node.node_type and :add_column == node.message
|
80
|
+
table_name = node.arguments[1].to_ruby_string
|
81
|
+
column_name = node.arguments[2].to_ruby_string
|
82
|
+
column_type = node.arguments[3].to_ruby_string
|
83
|
+
if column_name =~ /_id$/ and column_type == "integer" and !@@indexes[table_name].include? column_name
|
84
|
+
add_error "always add db index (#{table_name} => #{column_name})", node.file, node.line
|
85
|
+
end
|
86
|
+
end
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_best_practices}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Richard Huang"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-19}
|
13
13
|
s.default_executable = %q{rails_best_practices}
|
14
14
|
s.description = %q{check rails files according to ihower's presentation 'rails best practices'}
|
15
15
|
s.email = %q{flyerhzm@gmail.com}
|
@@ -296,4 +296,28 @@ describe RailsBestPractices::Checks::AlwaysAddDbIndexCheck do
|
|
296
296
|
errors = @runner.errors
|
297
297
|
errors.should be_empty
|
298
298
|
end
|
299
|
+
|
300
|
+
it "should always add db index when add_column" do
|
301
|
+
content = <<-EOF
|
302
|
+
class CreateComments < ActiveRecord::Migration
|
303
|
+
def self.up
|
304
|
+
create_table "comments", :force => true do |t|
|
305
|
+
t.string :content
|
306
|
+
end
|
307
|
+
add_column :comments, :post_id, :integer
|
308
|
+
add_column :comments, :user_id, :integer
|
309
|
+
end
|
310
|
+
|
311
|
+
def self.down
|
312
|
+
drop_table "comments"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
EOF
|
316
|
+
@runner.check('db/migrate/20090918130258_create_comments.rb', content)
|
317
|
+
@runner.check('db/migrate/20090918130258_create_comments.rb', content)
|
318
|
+
errors = @runner.errors
|
319
|
+
errors.should_not be_empty
|
320
|
+
errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:7 - always add db index (comments => post_id)"
|
321
|
+
errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:8 - always add db index (comments => user_id)"
|
322
|
+
end
|
299
323
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 19
|
9
|
+
version: 0.3.19
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Richard Huang
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-19 00:00:00 +08:00
|
18
18
|
default_executable: rails_best_practices
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|