rails_best_practices 0.1.1 → 0.1.2
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/README.textile +1 -1
- data/VERSION +1 -1
- data/lib/rails_best_practices/checks/overuse_route_customizations_check.rb +6 -1
- data/lib/rails_best_practices/core/runner.rb +0 -1
- data/lib/rails_best_practices/core/visitable_sexp.rb +5 -0
- data/rails_best_practices.gemspec +1 -1
- data/rails_best_practices.yml +1 -1
- data/spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb +11 -0
- metadata +1 -1
data/README.textile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
h1. rails_best_practices
|
2
2
|
|
3
|
-
rails_best_practices is a gem to check quality of rails app files according to ihower's presentation "Rails Best Practices".
|
3
|
+
rails_best_practices is a gem to check quality of rails app files according to ihower's presentation "Rails Best Practices":http://www.slideshare.net/ihower/rails-best-practices.
|
4
4
|
rails_best_practices is a static file parser tool based on ruby_parser.
|
5
5
|
|
6
6
|
*************************************************
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -2,6 +2,9 @@ require 'rails_best_practices/checks/check'
|
|
2
2
|
|
3
3
|
module RailsBestPractices
|
4
4
|
module Checks
|
5
|
+
# Check config/routes.rb to make sure there are no much route customizations.
|
6
|
+
#
|
7
|
+
# Implementation: check member and collection route count, if more than customize_count, then it is overuse route customizations.
|
5
8
|
class OveruseRouteCustomizationsCheck < Check
|
6
9
|
|
7
10
|
def interesting_nodes
|
@@ -26,7 +29,9 @@ module RailsBestPractices
|
|
26
29
|
private
|
27
30
|
|
28
31
|
def member_and_collection_count(node)
|
29
|
-
|
32
|
+
hash_nodes = node.grep_nodes(:node_type => :hash)
|
33
|
+
return 0 if hash_nodes.empty?
|
34
|
+
customize_hash = eval(hash_nodes.first.to_ruby)
|
30
35
|
(customize_hash[:member].size || 0) + (customize_hash[:collection].size || 0)
|
31
36
|
end
|
32
37
|
end
|
data/rails_best_practices.yml
CHANGED
@@ -7,4 +7,4 @@ ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
|
|
7
7
|
MoveModelLogicIntoModelCheck: { called_count: 4 }
|
8
8
|
# ManyToManyCollectionCheck: { }
|
9
9
|
# NestedModelFormsCheck: { }
|
10
|
-
|
10
|
+
OveruseRouteCustomizationsCheck: { customize_count: 3 }
|
@@ -34,6 +34,17 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
34
34
|
errors.should_not be_empty
|
35
35
|
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations"
|
36
36
|
end
|
37
|
+
|
38
|
+
it "should not overuse route customizations without customization" do
|
39
|
+
content = <<-EOF
|
40
|
+
ActionController::Routing::Routes.draw do |map|
|
41
|
+
map.resources :posts
|
42
|
+
end
|
43
|
+
EOF
|
44
|
+
@runner.check('config/routes.rb', content)
|
45
|
+
errors = @runner.errors
|
46
|
+
errors.should be_empty
|
47
|
+
end
|
37
48
|
|
38
49
|
it "should not overuse route customizations when customize route is only one" do
|
39
50
|
content = <<-EOF
|