rails_best_practices 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +28 -24
- data/Rakefile +0 -8
- data/install_supported_rubies.sh +2 -3
- data/lib/rails_best_practices.rb +8 -7
- data/lib/rails_best_practices/core.rb +1 -0
- data/lib/rails_best_practices/core/check.rb +68 -0
- data/lib/rails_best_practices/core/checking_visitor.rb +18 -15
- data/lib/rails_best_practices/core/runner.rb +22 -12
- data/lib/rails_best_practices/core/visitable_sexp.rb +6 -2
- data/lib/rails_best_practices/prepares.rb +11 -0
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +33 -0
- data/lib/rails_best_practices/prepares/model_prepare.rb +60 -0
- data/lib/rails_best_practices/reviews.rb +23 -0
- data/lib/rails_best_practices/{checks/add_model_virtual_attribute_check.rb → reviews/add_model_virtual_attribute_review.rb} +6 -9
- data/lib/rails_best_practices/{checks/always_add_db_index_check.rb → reviews/always_add_db_index_review.rb} +9 -12
- data/lib/rails_best_practices/{checks/dry_bundler_in_capistrano_check.rb → reviews/dry_bundler_in_capistrano_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/isolate_seed_data_check.rb → reviews/isolate_seed_data_review.rb} +11 -14
- data/lib/rails_best_practices/{checks/keep_finders_on_their_own_model_check.rb → reviews/keep_finders_on_their_own_model_review.rb} +7 -10
- data/lib/rails_best_practices/{checks/law_of_demeter_check.rb → reviews/law_of_demeter_review.rb} +10 -14
- data/lib/rails_best_practices/{checks/move_code_into_controller_check.rb → reviews/move_code_into_controller_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/move_code_into_helper_check.rb → reviews/move_code_into_helper_review.rb} +7 -10
- data/lib/rails_best_practices/{checks/move_code_into_model_check.rb → reviews/move_code_into_model_review.rb} +7 -10
- data/lib/rails_best_practices/{checks/move_finder_to_named_scope_check.rb → reviews/move_finder_to_named_scope_review.rb} +7 -10
- data/lib/rails_best_practices/{checks/move_model_logic_into_model_check.rb → reviews/move_model_logic_into_model_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/needless_deep_nesting_check.rb → reviews/needless_deep_nesting_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/not_use_default_route_check.rb → reviews/not_use_default_route_review.rb} +7 -10
- data/lib/rails_best_practices/{checks/overuse_route_customizations_check.rb → reviews/overuse_route_customizations_review.rb} +10 -13
- data/lib/rails_best_practices/{checks/replace_complex_creation_with_factory_method_check.rb → reviews/replace_complex_creation_with_factory_method_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/replace_instance_variable_with_local_variable_check.rb → reviews/replace_instance_variable_with_local_variable_review.rb} +7 -10
- data/lib/rails_best_practices/reviews/review.rb +92 -0
- data/lib/rails_best_practices/{checks/use_before_filter_check.rb → reviews/use_before_filter_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/use_model_association_check.rb → reviews/use_model_association_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/use_observer_check.rb → reviews/use_observer_review.rb} +14 -41
- data/lib/rails_best_practices/{checks/use_query_attribute_check.rb → reviews/use_query_attribute_review.rb} +20 -16
- data/lib/rails_best_practices/{checks/use_say_with_time_in_migrations_check.rb → reviews/use_say_with_time_in_migrations_review.rb} +8 -11
- data/lib/rails_best_practices/{checks/use_scope_access_check.rb → reviews/use_scope_access_review.rb} +8 -11
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +3 -2
- data/rails_best_practices.yml +22 -22
- data/rake_rubies.sh +3 -2
- data/spec/rails_best_practices/core/check_spec.rb +41 -0
- data/spec/rails_best_practices/core/checking_visitor_spec.rb +78 -0
- data/spec/rails_best_practices/core/visitable_sexp_spec.rb +39 -36
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +14 -0
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +22 -0
- data/spec/rails_best_practices/{checks/add_model_virtual_attribute_check_spec.rb → reviews/add_model_virtual_attribute_review_spec.rb} +17 -25
- data/spec/rails_best_practices/{checks/always_add_db_index_check_spec.rb → reviews/always_add_db_index_review_spec.rb} +28 -41
- data/spec/rails_best_practices/{checks/dry_bundler_in_capistrano_check_spec.rb → reviews/dry_bundler_in_capistrano_review_spec.rb} +7 -11
- data/spec/rails_best_practices/{checks/isolate_seed_data_check_spec.rb → reviews/isolate_seed_data_review_spec.rb} +13 -20
- data/spec/rails_best_practices/{checks/keep_finders_on_their_own_model_check_spec.rb → reviews/keep_finders_on_their_own_model_review_spec.rb} +16 -24
- data/spec/rails_best_practices/{checks/law_of_demeter_check_spec.rb → reviews/law_of_demeter_review_spec.rb} +24 -26
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +29 -0
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +24 -0
- data/spec/rails_best_practices/{checks/move_code_into_model_check_spec.rb → reviews/move_code_into_model_review_spec.rb} +12 -18
- data/spec/rails_best_practices/{checks/move_finder_to_named_scope_check_spec.rb → reviews/move_finder_to_named_scope_review_spec.rb} +12 -16
- data/spec/rails_best_practices/{checks/move_model_logic_into_model_check_spec.rb → reviews/move_model_logic_into_model_review_spec.rb} +7 -11
- data/spec/rails_best_practices/{checks/needless_deep_nesting_check_spec.rb → reviews/needless_deep_nesting_review_spec.rb} +26 -37
- data/spec/rails_best_practices/{checks/not_use_default_route_check_spec.rb → reviews/not_use_default_route_review_spec.rb} +13 -19
- data/spec/rails_best_practices/{checks/overuse_route_customizations_check_spec.rb → reviews/overuse_route_customizations_review_spec.rb} +27 -39
- data/spec/rails_best_practices/{checks/replace_complex_creation_with_factory_method_check_spec.rb → reviews/replace_complex_creation_with_factory_method_review_spec.rb} +10 -15
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +31 -0
- data/spec/rails_best_practices/reviews/review_spec.rb +11 -0
- data/spec/rails_best_practices/{checks/use_before_filter_check_spec.rb → reviews/use_before_filter_review_spec.rb} +11 -17
- data/spec/rails_best_practices/{checks/use_model_association_check_spec.rb → reviews/use_model_association_review_spec.rb} +12 -18
- data/spec/rails_best_practices/{checks/use_observer_check_spec.rb → reviews/use_observer_review_spec.rb} +28 -29
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +190 -0
- data/spec/rails_best_practices/{checks/use_say_with_time_in_migrations_check_spec.rb → reviews/use_say_with_time_in_migrations_review_spec.rb} +14 -23
- data/spec/rails_best_practices/{checks/use_scope_access_check_spec.rb → reviews/use_scope_access_review_spec.rb} +28 -37
- data/spec/rails_best_practices_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -0
- metadata +128 -102
- data/lib/rails_best_practices/checks.rb +0 -23
- data/lib/rails_best_practices/checks/check.rb +0 -203
- data/spec/rails_best_practices/checks/check_spec.rb +0 -57
- data/spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb +0 -33
- data/spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb +0 -28
- data/spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb +0 -36
- data/spec/rails_best_practices/checks/use_query_attribute_check_spec.rb +0 -192
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsBestPractices::Reviews::MoveCodeIntoHelperReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoHelperReview.new('array_count' => 2)) }
|
5
|
+
|
6
|
+
it "should move code into helper" do
|
7
|
+
content = <<-EOF
|
8
|
+
<%= select_tag :state, options_for_select( [[t(:draft), "draft"],
|
9
|
+
[t(:published), "published"]],
|
10
|
+
params[:default_state] ) %>
|
11
|
+
EOF
|
12
|
+
runner.review('app/views/posts/show.html.erb', content)
|
13
|
+
runner.should have(1).errors
|
14
|
+
runner.errors[0].to_s.should == "app/views/posts/show.html.erb:3 - move code into helper (array_count >= 2)"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not move code into helper with simple arguments" do
|
18
|
+
content = <<-EOF
|
19
|
+
<%= select_tag :state, options_for_select( Post.STATES ) %>
|
20
|
+
EOF
|
21
|
+
runner.review('app/views/posts/show.html.erb', content)
|
22
|
+
runner.should have(0).errors
|
23
|
+
end
|
24
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RailsBestPractices::
|
4
|
-
|
5
|
-
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveCodeIntoModelCheck.new)
|
6
|
-
end
|
3
|
+
describe RailsBestPractices::Reviews::MoveCodeIntoModelReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoModelReview.new) }
|
7
5
|
|
8
6
|
it "should move code into model" do
|
9
7
|
content =<<-EOF
|
@@ -11,10 +9,9 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
|
|
11
9
|
<%= link_to 'Edit this post', edit_post_url(@post) %>
|
12
10
|
<% end %>
|
13
11
|
EOF
|
14
|
-
|
15
|
-
|
16
|
-
errors.
|
17
|
-
errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
|
12
|
+
runner.review('app/views/posts/show.html.erb', content)
|
13
|
+
runner.should have(1).errors
|
14
|
+
runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
|
18
15
|
end
|
19
16
|
|
20
17
|
it "should move code into model with haml" do
|
@@ -22,10 +19,9 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
|
|
22
19
|
- if current_user && (current_user == @post.user || @post.editors.include?(current_user))
|
23
20
|
= link_to 'Edit this post', edit_post_url(@post)
|
24
21
|
EOF
|
25
|
-
|
26
|
-
|
27
|
-
errors.
|
28
|
-
errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
|
22
|
+
runner.review('app/views/posts/show.html.haml', content)
|
23
|
+
runner.should have(1).errors
|
24
|
+
runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
|
29
25
|
end
|
30
26
|
|
31
27
|
it "should move code into model only review for current if conditional statement" do
|
@@ -37,9 +33,8 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
|
|
37
33
|
<% end %>
|
38
34
|
<% end %>
|
39
35
|
EOF
|
40
|
-
|
41
|
-
|
42
|
-
errors.should be_empty
|
36
|
+
runner.review('app/views/posts/show.html.erb', content)
|
37
|
+
runner.should have(0).errors
|
43
38
|
end
|
44
39
|
|
45
40
|
it "should not move code into model" do
|
@@ -48,8 +43,7 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
|
|
48
43
|
<%= link_to 'Edit this post', edit_post_url(@post) %>
|
49
44
|
<% end %>
|
50
45
|
EOF
|
51
|
-
|
52
|
-
|
53
|
-
errors.should be_empty
|
46
|
+
runner.review('app/views/posts/show.html.erb', content)
|
47
|
+
runner.should have(0).errors
|
54
48
|
end
|
55
49
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RailsBestPractices::
|
4
|
-
|
5
|
-
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveFinderToNamedScopeCheck.new)
|
6
|
-
end
|
3
|
+
describe RailsBestPractices::Reviews::MoveFinderToNamedScopeReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveFinderToNamedScopeReview.new) }
|
7
5
|
|
8
6
|
it "should move finder to named_scope" do
|
9
7
|
content = <<-EOF
|
@@ -20,11 +18,10 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
|
|
20
18
|
end
|
21
19
|
end
|
22
20
|
EOF
|
23
|
-
|
24
|
-
|
25
|
-
errors.
|
26
|
-
errors[
|
27
|
-
errors[1].to_s.should == "app/controllers/posts_controller.rb:8 - move finder to named_scope"
|
21
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
22
|
+
runner.should have(2).errors
|
23
|
+
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:4 - move finder to named_scope"
|
24
|
+
runner.errors[1].to_s.should == "app/controllers/posts_controller.rb:8 - move finder to named_scope"
|
28
25
|
end
|
29
26
|
|
30
27
|
it "should not move simple finder" do
|
@@ -41,8 +38,8 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
|
|
41
38
|
end
|
42
39
|
end
|
43
40
|
EOF
|
44
|
-
|
45
|
-
|
41
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
42
|
+
runner.should have(0).errors
|
46
43
|
end
|
47
44
|
|
48
45
|
it "should not move namd_scope" do
|
@@ -55,8 +52,8 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
|
|
55
52
|
end
|
56
53
|
end
|
57
54
|
EOF
|
58
|
-
|
59
|
-
|
55
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
56
|
+
runner.should have(0).errors
|
60
57
|
end
|
61
58
|
|
62
59
|
it "should not review model file" do
|
@@ -75,8 +72,7 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
|
|
75
72
|
|
76
73
|
end
|
77
74
|
EOF
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
runner.review('app/model/post.rb', content)
|
76
|
+
runner.should have(0).errors
|
81
77
|
end
|
82
78
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RailsBestPractices::
|
4
|
-
|
5
|
-
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveModelLogicIntoModelCheck.new)
|
6
|
-
end
|
3
|
+
describe RailsBestPractices::Reviews::MoveModelLogicIntoModelReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveModelLogicIntoModelReview.new) }
|
7
5
|
|
8
6
|
it "should move model logic into model" do
|
9
7
|
content = <<-EOF
|
@@ -23,10 +21,9 @@ describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
|
|
23
21
|
redirect_to post_url(@post)
|
24
22
|
end
|
25
23
|
EOF
|
26
|
-
|
27
|
-
|
28
|
-
errors.
|
29
|
-
errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
|
24
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
25
|
+
runner.should have(1).errors
|
26
|
+
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
|
30
27
|
end
|
31
28
|
|
32
29
|
it "should not move model logic into model with simple model calling" do
|
@@ -42,8 +39,7 @@ describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
|
|
42
39
|
redirect_to post_url(@post)
|
43
40
|
end
|
44
41
|
EOF
|
45
|
-
|
46
|
-
|
47
|
-
errors.should be_empty
|
42
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
43
|
+
runner.should have(0).errors
|
48
44
|
end
|
49
45
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RailsBestPractices::
|
4
|
-
|
5
|
-
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::NeedlessDeepNestingCheck.new)
|
6
|
-
end
|
3
|
+
describe RailsBestPractices::Reviews::NeedlessDeepNestingReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::NeedlessDeepNestingReview.new) }
|
7
5
|
|
8
6
|
describe "rails2" do
|
9
7
|
it "should needless deep nesting" do
|
@@ -14,10 +12,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
14
12
|
end
|
15
13
|
end
|
16
14
|
EOF
|
17
|
-
|
18
|
-
|
19
|
-
errors.
|
20
|
-
errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
15
|
+
runner.review('config/routes.rb', content)
|
16
|
+
runner.should have(1).errors
|
17
|
+
runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
21
18
|
end
|
22
19
|
|
23
20
|
it "should needless deep nesting with resource" do
|
@@ -28,10 +25,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
28
25
|
end
|
29
26
|
end
|
30
27
|
EOF
|
31
|
-
|
32
|
-
|
33
|
-
errors.
|
34
|
-
errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
28
|
+
runner.review('config/routes.rb', content)
|
29
|
+
runner.should have(1).errors
|
30
|
+
runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
35
31
|
end
|
36
32
|
|
37
33
|
it "should needless deep nesting with block node" do
|
@@ -43,10 +39,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
43
39
|
post.resources :votes
|
44
40
|
end
|
45
41
|
EOF
|
46
|
-
|
47
|
-
|
48
|
-
errors.
|
49
|
-
errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
42
|
+
runner.review('config/routes.rb', content)
|
43
|
+
runner.should have(1).errors
|
44
|
+
runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
|
50
45
|
end
|
51
46
|
|
52
47
|
it "should no needless deep nesting" do
|
@@ -59,9 +54,8 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
59
54
|
comment.resources :favorites
|
60
55
|
end
|
61
56
|
EOF
|
62
|
-
|
63
|
-
|
64
|
-
errors.should be_empty
|
57
|
+
runner.review('config/routes.rb', content)
|
58
|
+
runner.should have(0).errors
|
65
59
|
end
|
66
60
|
|
67
61
|
it "should no needless deep nesting with block node" do
|
@@ -71,9 +65,8 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
71
65
|
comment.resources :votes
|
72
66
|
end
|
73
67
|
EOF
|
74
|
-
|
75
|
-
|
76
|
-
errors.should be_empty
|
68
|
+
runner.review('config/routes.rb', content)
|
69
|
+
runner.should have(0).errors
|
77
70
|
end
|
78
71
|
end
|
79
72
|
|
@@ -86,10 +79,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
86
79
|
end
|
87
80
|
end
|
88
81
|
EOF
|
89
|
-
|
90
|
-
|
91
|
-
errors.
|
92
|
-
errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
|
82
|
+
runner.review('config/routes.rb', content)
|
83
|
+
runner.should have(1).errors
|
84
|
+
runner.errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
|
93
85
|
end
|
94
86
|
|
95
87
|
it "should needless deep nesting with resource" do
|
@@ -100,10 +92,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
100
92
|
end
|
101
93
|
end
|
102
94
|
EOF
|
103
|
-
|
104
|
-
|
105
|
-
errors.
|
106
|
-
errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
|
95
|
+
runner.review('config/routes.rb', content)
|
96
|
+
runner.should have(1).errors
|
97
|
+
runner.errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
|
107
98
|
end
|
108
99
|
|
109
100
|
it "should needless deep nesting with block node" do
|
@@ -115,10 +106,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
115
106
|
resources :votes
|
116
107
|
end
|
117
108
|
EOF
|
118
|
-
|
119
|
-
|
120
|
-
errors.
|
121
|
-
errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
|
109
|
+
runner.review('config/routes.rb', content)
|
110
|
+
runner.should have(1).errors
|
111
|
+
runner.errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
|
122
112
|
end
|
123
113
|
|
124
114
|
it "should no needless deep nesting" do
|
@@ -132,9 +122,8 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
|
|
132
122
|
resources :favorites
|
133
123
|
end
|
134
124
|
EOF
|
135
|
-
|
136
|
-
|
137
|
-
errors.should be_empty
|
125
|
+
runner.review('config/routes.rb', content)
|
126
|
+
runner.should have(0).errors
|
138
127
|
end
|
139
128
|
end
|
140
129
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RailsBestPractices::
|
4
|
-
|
5
|
-
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::NotUseDefaultRouteCheck.new)
|
6
|
-
end
|
3
|
+
describe RailsBestPractices::Reviews::NotUseDefaultRouteReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::NotUseDefaultRouteReview.new) }
|
7
5
|
|
8
6
|
describe "rails2" do
|
9
7
|
it "should not use default route" do
|
@@ -15,11 +13,10 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
|
|
15
13
|
map.connect ':controller/:action/:id.:format'
|
16
14
|
end
|
17
15
|
EOF
|
18
|
-
|
19
|
-
|
20
|
-
errors.
|
21
|
-
errors[
|
22
|
-
errors[1].to_s.should == "config/routes.rb:5 - not use default route"
|
16
|
+
runner.review('config/routes.rb', content)
|
17
|
+
runner.should have(2).errors
|
18
|
+
runner.errors[0].to_s.should == "config/routes.rb:4 - not use default route"
|
19
|
+
runner.errors[1].to_s.should == "config/routes.rb:5 - not use default route"
|
23
20
|
end
|
24
21
|
|
25
22
|
it "should no not use default route" do
|
@@ -28,9 +25,8 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
|
|
28
25
|
map.resources :posts, :member => { :push => :post }
|
29
26
|
end
|
30
27
|
EOF
|
31
|
-
|
32
|
-
|
33
|
-
errors.should be_empty
|
28
|
+
runner.review('config/routes.rb', content)
|
29
|
+
runner.should have(0).errors
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
@@ -43,10 +39,9 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
|
|
43
39
|
match ':controller(/:action(/:id(.:format)))'
|
44
40
|
end
|
45
41
|
EOF
|
46
|
-
|
47
|
-
|
48
|
-
errors.
|
49
|
-
errors[0].to_s.should == "config/routes.rb:5 - not use default route"
|
42
|
+
runner.review('config/routes.rb', content)
|
43
|
+
runner.should have(1).errors
|
44
|
+
runner.errors[0].to_s.should == "config/routes.rb:5 - not use default route"
|
50
45
|
end
|
51
46
|
|
52
47
|
it "should no not use default route" do
|
@@ -55,9 +50,8 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
|
|
55
50
|
resources :posts
|
56
51
|
end
|
57
52
|
EOF
|
58
|
-
|
59
|
-
|
60
|
-
errors.should be_empty
|
53
|
+
runner.review('config/routes.rb', content)
|
54
|
+
runner.should have(0).errors
|
61
55
|
end
|
62
56
|
end
|
63
57
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RailsBestPractices::
|
4
|
-
|
5
|
-
@runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::OveruseRouteCustomizationsCheck.new)
|
6
|
-
end
|
3
|
+
describe RailsBestPractices::Reviews::OveruseRouteCustomizationsReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::OveruseRouteCustomizationsReview.new) }
|
7
5
|
|
8
6
|
describe "rails2" do
|
9
7
|
it "should overuse route customizations" do
|
@@ -15,10 +13,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
15
13
|
:delete_comment => :delete }
|
16
14
|
end
|
17
15
|
EOF
|
18
|
-
|
19
|
-
|
20
|
-
errors.
|
21
|
-
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
16
|
+
runner.review('config/routes.rb', content)
|
17
|
+
runner.should have(1).errors
|
18
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
22
19
|
end
|
23
20
|
|
24
21
|
it "should overuse route customizations with collection" do
|
@@ -30,10 +27,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
30
27
|
:collection => { :comments => :get }
|
31
28
|
end
|
32
29
|
EOF
|
33
|
-
|
34
|
-
|
35
|
-
errors.
|
36
|
-
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
30
|
+
runner.review('config/routes.rb', content)
|
31
|
+
runner.should have(1).errors
|
32
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
37
33
|
end
|
38
34
|
|
39
35
|
it "should overuse route customizations with collection 2" do
|
@@ -47,10 +43,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
47
43
|
end
|
48
44
|
end
|
49
45
|
EOF
|
50
|
-
|
51
|
-
|
52
|
-
errors.
|
53
|
-
errors[0].to_s.should == "config/routes.rb:3 - overuse route customizations (customize_count > 3)"
|
46
|
+
runner.review('config/routes.rb', content)
|
47
|
+
runner.should have(1).errors
|
48
|
+
runner.errors[0].to_s.should == "config/routes.rb:3 - overuse route customizations (customize_count > 3)"
|
54
49
|
end
|
55
50
|
|
56
51
|
it "should not overuse route customizations without customization" do
|
@@ -59,9 +54,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
59
54
|
map.resources :posts
|
60
55
|
end
|
61
56
|
EOF
|
62
|
-
|
63
|
-
|
64
|
-
errors.should be_empty
|
57
|
+
runner.review('config/routes.rb', content)
|
58
|
+
runner.should have(0).errors
|
65
59
|
end
|
66
60
|
|
67
61
|
it "should not overuse route customizations when customize route is only one" do
|
@@ -70,9 +64,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
70
64
|
map.resources :posts, :member => { :vote => :post }
|
71
65
|
end
|
72
66
|
EOF
|
73
|
-
|
74
|
-
|
75
|
-
errors.should be_empty
|
67
|
+
runner.review('config/routes.rb', content)
|
68
|
+
runner.should have(0).errors
|
76
69
|
end
|
77
70
|
|
78
71
|
it "should not raise error for constants in routes" do
|
@@ -84,9 +77,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
84
77
|
end
|
85
78
|
end
|
86
79
|
EOF
|
87
|
-
|
88
|
-
|
89
|
-
errors.should be_empty
|
80
|
+
runner.review('config/routes.rb', content)
|
81
|
+
runner.should have(0).errors
|
90
82
|
end
|
91
83
|
end
|
92
84
|
|
@@ -107,10 +99,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
107
99
|
end
|
108
100
|
end
|
109
101
|
EOF
|
110
|
-
|
111
|
-
|
112
|
-
errors.
|
113
|
-
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
102
|
+
runner.review('config/routes.rb', content)
|
103
|
+
runner.should have(1).errors
|
104
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
114
105
|
end
|
115
106
|
|
116
107
|
it "should overuse route customizations another way" do
|
@@ -124,10 +115,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
124
115
|
end
|
125
116
|
end
|
126
117
|
EOF
|
127
|
-
|
128
|
-
|
129
|
-
errors.
|
130
|
-
errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
118
|
+
runner.review('config/routes.rb', content)
|
119
|
+
runner.should have(1).errors
|
120
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
|
131
121
|
end
|
132
122
|
|
133
123
|
it "should not overuse route customizations without customization" do
|
@@ -136,9 +126,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
136
126
|
resources :posts
|
137
127
|
end
|
138
128
|
EOF
|
139
|
-
|
140
|
-
|
141
|
-
errors.should be_empty
|
129
|
+
runner.review('config/routes.rb', content)
|
130
|
+
runner.should have(0).errors
|
142
131
|
end
|
143
132
|
|
144
133
|
it "should not overuse route customizations when customize route is only one" do
|
@@ -151,9 +140,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
|
|
151
140
|
end
|
152
141
|
end
|
153
142
|
EOF
|
154
|
-
|
155
|
-
|
156
|
-
errors.should be_empty
|
143
|
+
runner.review('config/routes.rb', content)
|
144
|
+
runner.should have(0).errors
|
157
145
|
end
|
158
146
|
end
|
159
147
|
end
|