rails_best_practices 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
@@ -46,29 +46,31 @@ module RailsBestPractices
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def check_references(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
add_error "always add db index (#{table_name} => #{column_name})"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
node.grep_nodes({:node_type => :call, :message => :references}).each do |references_node|
|
60
|
-
column_name = references_node.arguments[1].to_ruby_string + "_id"
|
61
|
-
if !@@indexes[table_name].include? column_name
|
62
|
-
add_error "always add db index (#{table_name} => #{column_name})"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
node.grep_nodes({:node_type => :call, :message => :column}).each do |column_node|
|
66
|
-
if 'integer' == column_node.arguments[2].to_ruby_string
|
67
|
-
column_name = column_node.arguments[1].to_ruby_string
|
49
|
+
def check_references(nodes)
|
50
|
+
nodes[1..-1].each do |node|
|
51
|
+
create_table_node = node.grep_nodes({:node_type => :call, :message => :create_table}).first
|
52
|
+
if create_table_node
|
53
|
+
table_name = create_table_node.arguments[1].to_ruby_string
|
54
|
+
node.grep_nodes({:node_type => :call, :message => :integer}).each do |integer_node|
|
55
|
+
column_name = integer_node.arguments[1].to_ruby_string
|
68
56
|
if column_name =~ /_id$/ and !@@indexes[table_name].include? column_name
|
69
57
|
add_error "always add db index (#{table_name} => #{column_name})"
|
70
58
|
end
|
71
59
|
end
|
60
|
+
node.grep_nodes({:node_type => :call, :message => :references}).each do |references_node|
|
61
|
+
column_name = references_node.arguments[1].to_ruby_string + "_id"
|
62
|
+
if !@@indexes[table_name].include? column_name
|
63
|
+
add_error "always add db index (#{table_name} => #{column_name})"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
node.grep_nodes({:node_type => :call, :message => :column}).each do |column_node|
|
67
|
+
if 'integer' == column_node.arguments[2].to_ruby_string
|
68
|
+
column_name = column_node.arguments[1].to_ruby_string
|
69
|
+
if column_name =~ /_id$/ and !@@indexes[table_name].include? column_name
|
70
|
+
add_error "always add db index (#{table_name} => #{column_name})"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
@@ -79,7 +81,7 @@ module RailsBestPractices
|
|
79
81
|
# add_index *args
|
80
82
|
# end
|
81
83
|
def remember_indexes(nodes)
|
82
|
-
nodes.each do |node|
|
84
|
+
nodes[1..-1].each do |node|
|
83
85
|
begin
|
84
86
|
eval(node.to_ruby)
|
85
87
|
rescue Exception
|
@@ -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.8"
|
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{2009-11-
|
12
|
+
s.date = %q{2009-11-26}
|
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}
|
@@ -193,4 +193,29 @@ describe RailsBestPractices::Checks::AlwaysAddDbIndexCheck do
|
|
193
193
|
@runner.check('db/migrate/20090706091635_move_categories_to_profile_area.rb', content)
|
194
194
|
errors = @runner.errors
|
195
195
|
end
|
196
|
+
|
197
|
+
it "should always add db index without duplicate error outputs" do
|
198
|
+
content = <<-EOF
|
199
|
+
class AllTables < ActiveRecord::Migration
|
200
|
+
def self.up
|
201
|
+
create_table "ducks" do |t|
|
202
|
+
t.column "registration", :string, :limit => 32
|
203
|
+
t.column "description", :string
|
204
|
+
end
|
205
|
+
|
206
|
+
create_table "lab_data" do |t|
|
207
|
+
t.integer "input_biologist_id", :null => true
|
208
|
+
t.integer "owner_biologist_id", :null => false
|
209
|
+
t.column "remark", :string, :limit => 250
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
EOF
|
214
|
+
@runner.check('db/migrate/20090204160203_all_tables.rb', content)
|
215
|
+
@runner.check('db/migrate/20090204160203_all_tables.rb', content)
|
216
|
+
errors = @runner.errors
|
217
|
+
errors.should_not be_empty
|
218
|
+
errors[0].to_s.should == "db/migrate/20090204160203_all_tables.rb:2 - always add db index (lab_data => input_biologist_id)"
|
219
|
+
errors[1].to_s.should == "db/migrate/20090204160203_all_tables.rb:2 - always add db index (lab_data => owner_biologist_id)"
|
220
|
+
end
|
196
221
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-26 00:00:00 +08:00
|
13
13
|
default_executable: rails_best_practices
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|