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 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
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
- customize_hash = eval(Ruby2Ruby.new.process(node.grep_nodes(:node_type => :hash).first))
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
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'ruby_parser'
3
- require 'ruby2ruby'
4
3
  require 'yaml'
5
4
 
6
5
  module RailsBestPractices
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'sexp'
3
+ require 'ruby2ruby'
3
4
 
4
5
  class Sexp
5
6
  def accept(visitor)
@@ -100,4 +101,8 @@ class Sexp
100
101
  else
101
102
  end
102
103
  end
104
+
105
+ def to_ruby
106
+ Ruby2Ruby.new.process(self)
107
+ end
103
108
  end
@@ -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.1.1"
8
+ s.version = "0.1.2"
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"]
@@ -7,4 +7,4 @@ ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
7
7
  MoveModelLogicIntoModelCheck: { called_count: 4 }
8
8
  # ManyToManyCollectionCheck: { }
9
9
  # NestedModelFormsCheck: { }
10
- OveruseRouteCustomizations: { customize_count: 3 }
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
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang