rails_best_practices 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +25 -3
- data/VERSION +1 -1
- data/lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb +2 -2
- data/lib/rails_best_practices/checks/move_model_logic_into_model_check.rb +5 -4
- data/lib/rails_best_practices/checks/needless_deep_nesting_check.rb +35 -0
- data/lib/rails_best_practices/checks/not_use_default_route_check.rb +26 -0
- data/lib/rails_best_practices/checks/overuse_route_customizations_check.rb +1 -1
- data/lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb +3 -3
- data/lib/rails_best_practices/checks/use_model_association_check.rb +2 -2
- data/lib/rails_best_practices/checks.rb +3 -1
- data/lib/rails_best_practices/core/runner.rb +6 -1
- data/lib/rails_best_practices/core/visitable_sexp.rb +7 -20
- data/rails_best_practices.gemspec +8 -2
- data/rails_best_practices.yml +2 -0
- data/spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb +2 -2
- data/spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb +1 -1
- data/spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb +36 -0
- data/spec/rails_best_practices/checks/not_use_default_route_check_spec.rb +34 -0
- data/spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb +2 -2
- data/spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb +1 -1
- data/spec/rails_best_practices/checks/use_model_association_check_spec.rb +3 -3
- metadata +8 -2
data/README.textile
CHANGED
@@ -15,7 +15,7 @@ sudo gem install rails_best_practices --source http://gemcutter.org
|
|
15
15
|
|
16
16
|
h2. Usage
|
17
17
|
|
18
|
-
at the root of rails
|
18
|
+
at the root directory of rails app
|
19
19
|
|
20
20
|
<pre><code>
|
21
21
|
rails_best_practices .
|
@@ -23,6 +23,28 @@ rails_best_practices .
|
|
23
23
|
|
24
24
|
*************************************************
|
25
25
|
|
26
|
+
h2. Customize Configuration
|
27
|
+
|
28
|
+
Copy <code>rails_best_practices.yml</code> in the root directory of rails_best_practices gem to <code>config</code> directory
|
29
|
+
Now you can customize the configuration, the default configuration is as follows:
|
30
|
+
|
31
|
+
<pre><code>
|
32
|
+
MoveFinderToNamedScopeCheck: { }
|
33
|
+
UseModelAssociationCheck: { }
|
34
|
+
UseScopeAccessCheck: { }
|
35
|
+
AddModelVirtualAttributeCheck: { }
|
36
|
+
# UseModelCallbackCheck: { }
|
37
|
+
ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
|
38
|
+
MoveModelLogicIntoModelCheck: { called_count: 4 }
|
39
|
+
# ManyToManyCollectionCheck: { }
|
40
|
+
# NestedModelFormsCheck: { }
|
41
|
+
OveruseRouteCustomizationsCheck: { customize_count: 3 }
|
42
|
+
NeedlessDeepNestingCheck: { nested_count: 2 }
|
43
|
+
NotUseDefaultRouteCheck: { }
|
44
|
+
</code></pre>
|
45
|
+
|
46
|
+
*************************************************
|
47
|
+
|
26
48
|
h2. Progress
|
27
49
|
|
28
50
|
* Lesson 1. Move code from Controller to Model
|
@@ -39,8 +61,8 @@ h2. Progress
|
|
39
61
|
|
40
62
|
* Lesson 2. RESTful Conventions
|
41
63
|
## [-Overuse route customizations-]
|
42
|
-
## Needless deep nesting
|
43
|
-
## Not use default route
|
64
|
+
## [-Needless deep nesting-]
|
65
|
+
## [-Not use default route-]
|
44
66
|
|
45
67
|
* Lesson 3. Model
|
46
68
|
## Keep Finders on Their Own Model
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -42,7 +42,7 @@ module RailsBestPractices
|
|
42
42
|
def call_assignment(node)
|
43
43
|
if node.message == :save
|
44
44
|
variable = node.subject
|
45
|
-
add_error "add model virtual attribute" if params_dup?(@variables[variable].collect {|h| h[:arguments] })
|
45
|
+
add_error "add model virtual attribute (for #{node.subject.to_ruby})" if params_dup?(@variables[variable].collect {|h| h[:arguments] })
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -54,4 +54,4 @@ module RailsBestPractices
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
@@ -29,8 +29,9 @@ module RailsBestPractices
|
|
29
29
|
call_node(child)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
@variables.each do |variable, count|
|
34
|
+
add_error "move model logic into model (#{variable.to_ruby} called_count > #{@called_count})" if count > @called_count
|
34
35
|
end
|
35
36
|
@variables = nil
|
36
37
|
end
|
@@ -39,10 +40,10 @@ module RailsBestPractices
|
|
39
40
|
|
40
41
|
def call_node(node)
|
41
42
|
variable = node.subject
|
42
|
-
return if variable.nil?
|
43
|
+
return if variable.nil? or ![:lvar, :ivar].include? node.subject.node_type
|
43
44
|
@variables[variable] ||= 0
|
44
45
|
@variables[variable] += 1
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
48
|
-
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails_best_practices/checks/check'
|
2
|
+
|
3
|
+
module RailsBestPractices
|
4
|
+
module Checks
|
5
|
+
# Check config/routes.rb to make sure not to use too deep nesting routes.
|
6
|
+
#
|
7
|
+
# Implementation: check nested route count, if more than nested_count, then it is needless deep nesting.
|
8
|
+
class NeedlessDeepNestingCheck < Check
|
9
|
+
|
10
|
+
def interesting_nodes
|
11
|
+
[:call]
|
12
|
+
end
|
13
|
+
|
14
|
+
def interesting_files
|
15
|
+
/config\/routes.rb/
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
super()
|
20
|
+
@nested_count = options['nested_count'] || 2
|
21
|
+
end
|
22
|
+
|
23
|
+
def evaluate_start(node)
|
24
|
+
if node.message == :resources
|
25
|
+
if node.subject == s(:call, nil, :map, s(:arglist))
|
26
|
+
@counter = 0
|
27
|
+
else
|
28
|
+
@counter += 1
|
29
|
+
add_error "needless deep nesting (nested_count > #{@nested_count})" if @counter >= @nested_count
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails_best_practices/checks/check'
|
2
|
+
|
3
|
+
module RailsBestPractices
|
4
|
+
module Checks
|
5
|
+
# Check config/routes to make sure not use default route that rails generated.
|
6
|
+
#
|
7
|
+
# Implementation: compare route sentence to see if it is equal to rails default route.
|
8
|
+
class NotUseDefaultRouteCheck < Check
|
9
|
+
|
10
|
+
def interesting_nodes
|
11
|
+
[:call]
|
12
|
+
end
|
13
|
+
|
14
|
+
def interesting_files
|
15
|
+
/config\/routes.rb/
|
16
|
+
end
|
17
|
+
|
18
|
+
def evaluate_start(node)
|
19
|
+
if node == s(:call, s(:lvar, :map), :connect, s(:arglist, s(:str, ":controller/:action/:id"))) or
|
20
|
+
node == s(:call, s(:lvar, :map), :connect, s(:arglist, s(:str, ":controller/:action/:id.:format")))
|
21
|
+
add_error "not use default route"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -22,7 +22,7 @@ module RailsBestPractices
|
|
22
22
|
|
23
23
|
def evaluate_start(node)
|
24
24
|
if s(:lvar, :map) == node.subject and :resources == node.message
|
25
|
-
add_error "overuse route customizations" if member_and_collection_count(node) > @customize_count
|
25
|
+
add_error "overuse route customizations (customize_count > #{@customize_count})" if member_and_collection_count(node) > @customize_count
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -39,7 +39,7 @@ module RailsBestPractices
|
|
39
39
|
|
40
40
|
def attribute_assignment(node)
|
41
41
|
variable = node.subject
|
42
|
-
return if variable.nil?
|
42
|
+
return if variable.nil? or ![:lvar, :ivar].include? node.subject.node_type
|
43
43
|
@variables[variable] ||= 0
|
44
44
|
@variables[variable] += 1
|
45
45
|
end
|
@@ -47,9 +47,9 @@ module RailsBestPractices
|
|
47
47
|
def call_assignment(node)
|
48
48
|
if node.message == :save
|
49
49
|
variable = node.subject
|
50
|
-
add_error "replace complex creation with factory method" if @variables[variable] > @attrasgn_count
|
50
|
+
add_error "replace complex creation with factory method (#{variable.to_ruby} attribute_assignment_count > #{@attrasgn_count})" if @variables[variable] > @attrasgn_count
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
@@ -39,9 +39,9 @@ module RailsBestPractices
|
|
39
39
|
def call_assignment(node)
|
40
40
|
if node.message == :save
|
41
41
|
variable = node.subject[1]
|
42
|
-
add_error "use model association" if @variables[variable]
|
42
|
+
add_error "use model association (for #{node.subject.to_ruby})" if @variables[variable]
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
@@ -7,4 +7,6 @@ require 'rails_best_practices/checks/replace_complex_creation_with_factory_metho
|
|
7
7
|
require 'rails_best_practices/checks/move_model_logic_into_model_check'
|
8
8
|
require 'rails_best_practices/checks/many_to_many_collection_check'
|
9
9
|
require 'rails_best_practices/checks/nested_model_forms_check'
|
10
|
-
require 'rails_best_practices/checks/overuse_route_customizations_check'
|
10
|
+
require 'rails_best_practices/checks/overuse_route_customizations_check'
|
11
|
+
require 'rails_best_practices/checks/needless_deep_nesting_check'
|
12
|
+
require 'rails_best_practices/checks/not_use_default_route_check'
|
@@ -6,9 +6,14 @@ module RailsBestPractices
|
|
6
6
|
module Core
|
7
7
|
class Runner
|
8
8
|
DEFAULT_CONFIG = File.join(File.dirname(__FILE__), "..", "..", "..", "rails_best_practices.yml")
|
9
|
+
CUSTOM_CONFIG = File.join('config', 'rails_best_practices.yml')
|
9
10
|
|
10
11
|
def initialize(*checks)
|
11
|
-
|
12
|
+
if File.exists?(CUSTOM_CONFIG)
|
13
|
+
@config = CUSTOM_CONFIG
|
14
|
+
else
|
15
|
+
@config = DEFAULT_CONFIG
|
16
|
+
end
|
12
17
|
@checks = checks unless checks.empty?
|
13
18
|
@checks ||= load_checks
|
14
19
|
@checker ||= CheckingVisitor.new(@checks)
|
@@ -47,56 +47,43 @@ class Sexp
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def subject
|
50
|
-
|
51
|
-
when :attrasgn, :call, :iasgn, :lasgn
|
50
|
+
if [:attrasgn, :call, :iasgn, :lasgn].include? node_type
|
52
51
|
self[1]
|
53
|
-
else
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
def message
|
58
|
-
|
59
|
-
when :attrasgn, :call
|
56
|
+
if [:attrasgn, :call].include? node_type
|
60
57
|
self[2]
|
61
|
-
else
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
61
|
def arguments
|
66
|
-
|
67
|
-
when :attrasgn, :call
|
62
|
+
if [:attrasgn, :call].include? node_type
|
68
63
|
self[3]
|
69
|
-
else
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
73
67
|
def call
|
74
|
-
|
75
|
-
when :if, :arglist
|
68
|
+
if [:if, :arglist].include? node_type
|
76
69
|
self[1]
|
77
|
-
else
|
78
70
|
end
|
79
71
|
end
|
80
72
|
|
81
73
|
def true_node
|
82
|
-
|
83
|
-
when :if
|
74
|
+
if :if == node_type
|
84
75
|
self[2]
|
85
|
-
else
|
86
76
|
end
|
87
77
|
end
|
88
78
|
|
89
79
|
def false_node
|
90
|
-
|
91
|
-
when :if
|
80
|
+
if :if == node_type
|
92
81
|
self[3]
|
93
|
-
else
|
94
82
|
end
|
95
83
|
end
|
96
84
|
|
97
85
|
def method_body
|
98
|
-
|
99
|
-
when :block
|
86
|
+
if :block == node_type
|
100
87
|
self[1..-1]
|
101
88
|
else
|
102
89
|
end
|
@@ -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.
|
8
|
+
s.version = "0.2.0"
|
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-06}
|
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}
|
@@ -32,7 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/rails_best_practices/checks/many_to_many_collection_check.rb",
|
33
33
|
"lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb",
|
34
34
|
"lib/rails_best_practices/checks/move_model_logic_into_model_check.rb",
|
35
|
+
"lib/rails_best_practices/checks/needless_deep_nesting_check.rb",
|
35
36
|
"lib/rails_best_practices/checks/nested_model_forms_check.rb",
|
37
|
+
"lib/rails_best_practices/checks/not_use_default_route_check.rb",
|
36
38
|
"lib/rails_best_practices/checks/overuse_route_customizations_check.rb",
|
37
39
|
"lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb",
|
38
40
|
"lib/rails_best_practices/checks/use_model_association_check.rb",
|
@@ -51,7 +53,9 @@ Gem::Specification.new do |s|
|
|
51
53
|
"spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
|
52
54
|
"spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
|
53
55
|
"spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
|
56
|
+
"spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
|
54
57
|
"spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
|
58
|
+
"spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
|
55
59
|
"spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
|
56
60
|
"spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
|
57
61
|
"spec/rails_best_practices/checks/use_model_association_check_spec.rb",
|
@@ -67,6 +71,7 @@ Gem::Specification.new do |s|
|
|
67
71
|
s.summary = %q{check rails files according to ihower's presentation 'rails best practices'}
|
68
72
|
s.test_files = [
|
69
73
|
"spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
|
74
|
+
"spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
|
70
75
|
"spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
|
71
76
|
"spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
|
72
77
|
"spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
|
@@ -75,6 +80,7 @@ Gem::Specification.new do |s|
|
|
75
80
|
"spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
|
76
81
|
"spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
|
77
82
|
"spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
|
83
|
+
"spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
|
78
84
|
"spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
|
79
85
|
"spec/spec_helper.rb"
|
80
86
|
]
|
data/rails_best_practices.yml
CHANGED
@@ -20,7 +20,7 @@ describe RailsBestPractices::Checks::AddModelVirtualAttributeCheck do
|
|
20
20
|
@runner.check('app/controller/users_controller.rb', content)
|
21
21
|
errors = @runner.errors
|
22
22
|
errors.should_not be_empty
|
23
|
-
errors[0].to_s.should == "app/controller/users_controller.rb:3 - add model virtual attribute"
|
23
|
+
errors[0].to_s.should == "app/controller/users_controller.rb:3 - add model virtual attribute (for @user)"
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should not add model virtual attribute with differen param" do
|
@@ -57,4 +57,4 @@ describe RailsBestPractices::Checks::AddModelVirtualAttributeCheck do
|
|
57
57
|
errors = @runner.errors
|
58
58
|
errors.should be_empty
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
@@ -26,7 +26,7 @@ describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
|
|
26
26
|
@runner.check('app/controller/posts_controller.rb', content)
|
27
27
|
errors = @runner.errors
|
28
28
|
errors.should_not be_empty
|
29
|
-
errors[0].to_s.should == "app/controller/posts_controller.rb:3 - move model logic into model"
|
29
|
+
errors[0].to_s.should == "app/controller/posts_controller.rb:3 - move model logic into model (@post called_count > 4)"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should not move model logic into model with simple model calling" do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
4
|
+
before(:each) do
|
5
|
+
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::NeedlessDeepNestingCheck.new)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should needless deep nesting" do
|
9
|
+
content = <<-EOF
|
10
|
+
map.resources :posts do |post|
|
11
|
+
post.resources :comments do |comment|
|
12
|
+
comment.resources :favorites
|
13
|
+
end
|
14
|
+
end
|
15
|
+
EOF
|
16
|
+
@runner.check('config/routes.rb', content)
|
17
|
+
errors = @runner.errors
|
18
|
+
errors.should_not be_empty
|
19
|
+
errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should no needless deep nesting" do
|
23
|
+
content = <<-EOF
|
24
|
+
map.resources :posts do |post|
|
25
|
+
post.resources :comments
|
26
|
+
end
|
27
|
+
|
28
|
+
map.resources :comments do |comment|
|
29
|
+
comment.resources :favorites
|
30
|
+
end
|
31
|
+
EOF
|
32
|
+
@runner.check('config/routes.rb', content)
|
33
|
+
errors = @runner.errors
|
34
|
+
errors.should be_empty
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
|
4
|
+
before(:each) do
|
5
|
+
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::NotUseDefaultRouteCheck.new)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should not use default route" do
|
9
|
+
content = <<-EOF
|
10
|
+
ActionController::Routing::Routes.draw do |map|
|
11
|
+
map.resources :posts, :member => { :push => :post }
|
12
|
+
|
13
|
+
map.connect ':controller/:action/:id'
|
14
|
+
map.connect ':controller/:action/:id.:format'
|
15
|
+
end
|
16
|
+
EOF
|
17
|
+
@runner.check('config/routes.rb', content)
|
18
|
+
errors = @runner.errors
|
19
|
+
errors.should_not be_empty
|
20
|
+
errors[0].to_s.should == "config/routes.rb:4 - not use default route"
|
21
|
+
errors[1].to_s.should == "config/routes.rb:5 - not use default route"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should no not use default route" do
|
25
|
+
content = <<-EOF
|
26
|
+
ActionController::Routing::Routes.draw do |map|
|
27
|
+
map.resources :posts, :member => { :push => :post }
|
28
|
+
end
|
29
|
+
EOF
|
30
|
+
@runner.check('config/routes.rb', content)
|
31
|
+
errors = @runner.errors
|
32
|
+
errors.should be_empty
|
33
|
+
end
|
34
|
+
end
|
@@ -17,7 +17,7 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
17
17
|
@runner.check('config/routes.rb', content)
|
18
18
|
errors = @runner.errors
|
19
19
|
errors.should_not be_empty
|
20
|
-
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations"
|
20
|
+
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should overuse route customizations with collection" do
|
@@ -32,7 +32,7 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
32
32
|
@runner.check('config/routes.rb', content)
|
33
33
|
errors = @runner.errors
|
34
34
|
errors.should_not be_empty
|
35
|
-
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations"
|
35
|
+
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should not overuse route customizations without customization" do
|
data/spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe RailsBestPractices::Checks::ReplaceComplexCreationWithFactoryMethodChec
|
|
28
28
|
@runner.check('app/controller/invoices_controller.rb', content)
|
29
29
|
errors = @runner.errors
|
30
30
|
errors.should_not be_empty
|
31
|
-
errors[0].to_s.should == "app/controller/invoices_controller.rb:3 - replace complex creation with factory method"
|
31
|
+
errors[0].to_s.should == "app/controller/invoices_controller.rb:3 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should not replace complex creation with factory method with simple creation" do
|
@@ -19,7 +19,7 @@ describe RailsBestPractices::Checks::UseModelAssociationCheck do
|
|
19
19
|
@runner.check('app/controller/posts_controller.rb', content)
|
20
20
|
errors = @runner.errors
|
21
21
|
errors.should_not be_empty
|
22
|
-
errors[0].to_s.should == "app/controller/posts_controller.rb:3 - use model association"
|
22
|
+
errors[0].to_s.should == "app/controller/posts_controller.rb:3 - use model association (for @post)"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should not use model association without association assign" do
|
@@ -51,7 +51,7 @@ describe RailsBestPractices::Checks::UseModelAssociationCheck do
|
|
51
51
|
@runner.check('app/controller/posts_controller.rb', content)
|
52
52
|
errors = @runner.errors
|
53
53
|
errors.should_not be_empty
|
54
|
-
errors[0].to_s.should == "app/controller/posts_controller.rb:3 - use model association"
|
54
|
+
errors[0].to_s.should == "app/controller/posts_controller.rb:3 - use model association (for post)"
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should not use model association" do
|
@@ -68,4 +68,4 @@ describe RailsBestPractices::Checks::UseModelAssociationCheck do
|
|
68
68
|
errors = @runner.errors
|
69
69
|
errors.should be_empty
|
70
70
|
end
|
71
|
-
end
|
71
|
+
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.
|
4
|
+
version: 0.2.0
|
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-06 00:00:00 +08:00
|
13
13
|
default_executable: rails_best_practices
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,7 +55,9 @@ files:
|
|
55
55
|
- lib/rails_best_practices/checks/many_to_many_collection_check.rb
|
56
56
|
- lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
|
57
57
|
- lib/rails_best_practices/checks/move_model_logic_into_model_check.rb
|
58
|
+
- lib/rails_best_practices/checks/needless_deep_nesting_check.rb
|
58
59
|
- lib/rails_best_practices/checks/nested_model_forms_check.rb
|
60
|
+
- lib/rails_best_practices/checks/not_use_default_route_check.rb
|
59
61
|
- lib/rails_best_practices/checks/overuse_route_customizations_check.rb
|
60
62
|
- lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb
|
61
63
|
- lib/rails_best_practices/checks/use_model_association_check.rb
|
@@ -74,7 +76,9 @@ files:
|
|
74
76
|
- spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
|
75
77
|
- spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
|
76
78
|
- spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
|
79
|
+
- spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
|
77
80
|
- spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
|
81
|
+
- spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
|
78
82
|
- spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
|
79
83
|
- spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
|
80
84
|
- spec/rails_best_practices/checks/use_model_association_check_spec.rb
|
@@ -112,6 +116,7 @@ specification_version: 3
|
|
112
116
|
summary: check rails files according to ihower's presentation 'rails best practices'
|
113
117
|
test_files:
|
114
118
|
- spec/rails_best_practices/checks/use_scope_access_check_spec.rb
|
119
|
+
- spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
|
115
120
|
- spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
|
116
121
|
- spec/rails_best_practices/checks/use_model_callback_check_spec.rb
|
117
122
|
- spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
|
@@ -120,5 +125,6 @@ test_files:
|
|
120
125
|
- spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
|
121
126
|
- spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
|
122
127
|
- spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
|
128
|
+
- spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
|
123
129
|
- spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
|
124
130
|
- spec/spec_helper.rb
|