rails_best_practices 0.3.8 → 0.3.9

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.8
1
+ 0.3.9
@@ -54,20 +54,20 @@ module RailsBestPractices
54
54
  node.grep_nodes({:node_type => :call, :message => :integer}).each do |integer_node|
55
55
  column_name = integer_node.arguments[1].to_ruby_string
56
56
  if column_name =~ /_id$/ and !@@indexes[table_name].include? column_name
57
- add_error "always add db index (#{table_name} => #{column_name})"
57
+ add_error "always add db index (#{table_name} => #{column_name})", integer_node
58
58
  end
59
59
  end
60
60
  node.grep_nodes({:node_type => :call, :message => :references}).each do |references_node|
61
61
  column_name = references_node.arguments[1].to_ruby_string + "_id"
62
62
  if !@@indexes[table_name].include? column_name
63
- add_error "always add db index (#{table_name} => #{column_name})"
63
+ add_error "always add db index (#{table_name} => #{column_name})", references_node
64
64
  end
65
65
  end
66
66
  node.grep_nodes({:node_type => :call, :message => :column}).each do |column_node|
67
67
  if 'integer' == column_node.arguments[2].to_ruby_string
68
68
  column_name = column_node.arguments[1].to_ruby_string
69
69
  if column_name =~ /_id$/ and !@@indexes[table_name].include? column_name
70
- add_error "always add db index (#{table_name} => #{column_name})"
70
+ add_error "always add db index (#{table_name} => #{column_name})", column_node
71
71
  end
72
72
  end
73
73
  end
@@ -52,9 +52,9 @@ module RailsBestPractices
52
52
  evaluate_end(node)
53
53
  end
54
54
 
55
- def add_error(error, line = nil)
56
- line = @node.line if line.nil?
57
- @errors << RailsBestPractices::Core::Error.new("#{@node.file}", "#{line}", error)
55
+ def add_error(error, node = nil)
56
+ node ||= @node
57
+ @errors << RailsBestPractices::Core::Error.new("#{node.file}", "#{node.line}", error)
58
58
  end
59
59
 
60
60
  def errors
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_best_practices}
8
- s.version = "0.3.8"
8
+ s.version = "0.3.9"
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"]
@@ -88,27 +88,27 @@ Gem::Specification.new do |s|
88
88
  s.rubygems_version = %q{1.3.5}
89
89
  s.summary = %q{check rails files according to ihower's presentation 'rails best practices'}
90
90
  s.test_files = [
91
- "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
92
- "spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
93
- "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
94
- "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
95
- "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
96
- "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
97
- "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
98
- "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
99
- "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
91
+ "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
100
92
  "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
101
- "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
102
- "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
103
- "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
93
+ "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
94
+ "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
95
+ "spec/rails_best_practices/checks/use_observer_check_spec.rb",
104
96
  "spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
97
+ "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
98
+ "spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
99
+ "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
100
+ "spec/rails_best_practices/checks/use_before_filter_check_spec.rb",
101
+ "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
102
+ "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
105
103
  "spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
104
+ "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
105
+ "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
106
+ "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
107
+ "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
106
108
  "spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb",
107
- "spec/rails_best_practices/checks/use_before_filter_check_spec.rb",
108
109
  "spec/rails_best_practices/checks/use_model_association_check_spec.rb",
109
- "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
110
- "spec/rails_best_practices/checks/use_observer_check_spec.rb",
111
- "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
110
+ "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
111
+ "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
112
112
  "spec/spec_helper.rb"
113
113
  ]
114
114
 
@@ -25,8 +25,8 @@ describe RailsBestPractices::Checks::AlwaysAddDbIndexCheck do
25
25
  @runner.check('db/migrate/20090918130258_create_comments.rb', content)
26
26
  errors = @runner.errors
27
27
  errors.should_not be_empty
28
- errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:2 - always add db index (comments => post_id)"
29
- errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:2 - always add db index (comments => user_id)"
28
+ errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:5 - always add db index (comments => post_id)"
29
+ errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:6 - always add db index (comments => user_id)"
30
30
  end
31
31
 
32
32
  it "should always add db index with column has no id" do
@@ -70,8 +70,8 @@ describe RailsBestPractices::Checks::AlwaysAddDbIndexCheck do
70
70
  @runner.check('db/migrate/20090918130258_create_comments.rb', content)
71
71
  errors = @runner.errors
72
72
  errors.should_not be_empty
73
- errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:2 - always add db index (comments => post_id)"
74
- errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:2 - always add db index (comments => user_id)"
73
+ errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:5 - always add db index (comments => post_id)"
74
+ errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:6 - always add db index (comments => user_id)"
75
75
  end
76
76
 
77
77
  it "should always add db index with column" do
@@ -94,8 +94,8 @@ describe RailsBestPractices::Checks::AlwaysAddDbIndexCheck do
94
94
  @runner.check('db/migrate/20090918130258_create_comments.rb', content)
95
95
  errors = @runner.errors
96
96
  errors.should_not be_empty
97
- errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:2 - always add db index (comments => post_id)"
98
- errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:2 - always add db index (comments => user_id)"
97
+ errors[0].to_s.should == "db/migrate/20090918130258_create_comments.rb:5 - always add db index (comments => post_id)"
98
+ errors[1].to_s.should == "db/migrate/20090918130258_create_comments.rb:6 - always add db index (comments => user_id)"
99
99
  end
100
100
 
101
101
  it "should not always add db index with add_index" do
@@ -215,7 +215,7 @@ describe RailsBestPractices::Checks::AlwaysAddDbIndexCheck do
215
215
  @runner.check('db/migrate/20090204160203_all_tables.rb', content)
216
216
  errors = @runner.errors
217
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)"
218
+ errors[0].to_s.should == "db/migrate/20090204160203_all_tables.rb:9 - always add db index (lab_data => input_biologist_id)"
219
+ errors[1].to_s.should == "db/migrate/20090204160203_all_tables.rb:10 - always add db index (lab_data => owner_biologist_id)"
220
220
  end
221
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.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
@@ -133,25 +133,25 @@ signing_key:
133
133
  specification_version: 3
134
134
  summary: check rails files according to ihower's presentation 'rails best practices'
135
135
  test_files:
136
- - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
137
- - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
138
136
  - spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb
139
- - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
140
- - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
141
- - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
142
- - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
143
- - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
144
- - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
145
137
  - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
146
- - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
147
- - spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
148
- - spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
138
+ - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
139
+ - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
140
+ - spec/rails_best_practices/checks/use_observer_check_spec.rb
149
141
  - spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
142
+ - spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
143
+ - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
144
+ - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
145
+ - spec/rails_best_practices/checks/use_before_filter_check_spec.rb
146
+ - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
147
+ - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
150
148
  - spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
149
+ - spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
150
+ - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
151
+ - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
152
+ - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
151
153
  - spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb
152
- - spec/rails_best_practices/checks/use_before_filter_check_spec.rb
153
154
  - spec/rails_best_practices/checks/use_model_association_check_spec.rb
154
- - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
155
- - spec/rails_best_practices/checks/use_observer_check_spec.rb
156
- - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
155
+ - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
156
+ - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
157
157
  - spec/spec_helper.rb