rails_best_practices 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -1
- data/Gemfile +0 -3
- data/Gemfile.lock +10 -9
- data/README.md +2 -0
- data/lib/rails_best_practices/analyzer.rb +40 -21
- data/lib/rails_best_practices/core.rb +1 -0
- data/lib/rails_best_practices/core/check.rb +12 -0
- data/lib/rails_best_practices/core/configs.rb +7 -0
- data/lib/rails_best_practices/core/error.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +11 -5
- data/lib/rails_best_practices/core/runner.rb +6 -2
- data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
- data/lib/rails_best_practices/prepares.rb +5 -0
- data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
- data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -0
- data/spec/rails_best_practices/analyzer_spec.rb +52 -32
- data/spec/rails_best_practices/core/check_spec.rb +64 -45
- data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
- data/spec/rails_best_practices/core/configs_spec.rb +7 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
- data/spec/rails_best_practices/core/error_spec.rb +28 -22
- data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
- data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
- data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
- data/spec/rails_best_practices/core/methods_spec.rb +37 -35
- data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
- data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
- data/spec/rails_best_practices/core/models_spec.rb +4 -2
- data/spec/rails_best_practices/core/modules_spec.rb +21 -19
- data/spec/rails_best_practices/core/nil_spec.rb +23 -21
- data/spec/rails_best_practices/core/routes_spec.rb +21 -14
- data/spec/rails_best_practices/core/runner_spec.rb +17 -15
- data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
- data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
- data/spec/spec_helper.rb +11 -20
- metadata +42 -26
- data/.watchr.example +0 -65
data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb
CHANGED
@@ -1,71 +1,72 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module RailsBestPractices
|
4
|
+
module Reviews
|
5
|
+
describe ReplaceComplexCreationWithFactoryMethodReview do
|
6
|
+
let(:runner) { Core::Runner.new(:reviews => ReplaceComplexCreationWithFactoryMethodReview.new) }
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
it "should replace complex creation with factory method" do
|
9
|
+
content = <<-EOF
|
10
|
+
class InvoiceController < ApplicationController
|
11
|
+
def create
|
12
|
+
@invoice = Invoice.new(params[:invoice])
|
13
|
+
@invoice.address = current_user.address
|
14
|
+
@invoice.phone = current_user.phone
|
15
|
+
@invoice.vip = (@invoice.amount > 1000)
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
if Time.now.day > 15
|
18
|
+
@invoice.deliver_time = Time.now + 2.month
|
19
|
+
else
|
20
|
+
@invoice.deliver_time = Time.now + 1.month
|
21
|
+
end
|
15
22
|
|
16
|
-
|
17
|
-
|
18
|
-
else
|
19
|
-
@invoice.deliver_time = Time.now + 1.month
|
23
|
+
@invoice.save
|
24
|
+
end
|
20
25
|
end
|
21
|
-
|
22
|
-
|
26
|
+
EOF
|
27
|
+
runner.review('app/controllers/invoices_controller.rb', content)
|
28
|
+
runner.should have(1).errors
|
29
|
+
runner.errors[0].to_s.should == "app/controllers/invoices_controller.rb:3 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)"
|
23
30
|
end
|
24
|
-
end
|
25
|
-
EOF
|
26
|
-
runner.review('app/controllers/invoices_controller.rb', content)
|
27
|
-
runner.should have(1).errors
|
28
|
-
runner.errors[0].to_s.should == "app/controllers/invoices_controller.rb:3 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should not replace complex creation with factory method with simple creation" do
|
32
|
-
content = <<-EOF
|
33
|
-
class InvoiceController < ApplicationController
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
it "should not replace complex creation with factory method with simple creation" do
|
33
|
+
content = <<-EOF
|
34
|
+
class InvoiceController < ApplicationController
|
35
|
+
def create
|
36
|
+
@invoice = Invoice.new(params[:invoice])
|
37
|
+
@invoice.address = current_user.address
|
38
|
+
@invoice.phone = current_user.phone
|
39
|
+
@invoice.save
|
40
|
+
end
|
41
|
+
end
|
42
|
+
EOF
|
43
|
+
runner.review('app/controllers/invoices_controller.rb', content)
|
44
|
+
runner.should have(0).errors
|
40
45
|
end
|
41
|
-
end
|
42
|
-
EOF
|
43
|
-
runner.review('app/controllers/invoices_controller.rb', content)
|
44
|
-
runner.should have(0).errors
|
45
|
-
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
it "should not replace complex creation with factory method when attrasgn_count is 5" do
|
48
|
+
content = <<-EOF
|
49
|
+
class InvoiceController < ApplicationController
|
50
|
+
def create
|
51
|
+
@invoice = Invoice.new(params[:invoice])
|
52
|
+
@invoice.address = current_user.address
|
53
|
+
@invoice.phone = current_user.phone
|
54
|
+
@invoice.vip = (@invoice.amount > 1000)
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
if Time.now.day > 15
|
57
|
+
@invoice.deliver_time = Time.now + 2.month
|
58
|
+
else
|
59
|
+
@invoice.deliver_time = Time.now + 1.month
|
60
|
+
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
else
|
60
|
-
@invoice.deliver_time = Time.now + 1.month
|
62
|
+
@invoice.save
|
63
|
+
end
|
61
64
|
end
|
62
|
-
|
63
|
-
|
65
|
+
EOF
|
66
|
+
runner = Core::Runner.new(:reviews => ReplaceComplexCreationWithFactoryMethodReview.new('attribute_assignment_count' => 5))
|
67
|
+
runner.review('app/controllers/invoices_controller.rb', content)
|
68
|
+
runner.should have(0).errors
|
64
69
|
end
|
65
70
|
end
|
66
|
-
EOF
|
67
|
-
runner = RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::ReplaceComplexCreationWithFactoryMethodReview.new('attribute_assignment_count' => 5))
|
68
|
-
runner.review('app/controllers/invoices_controller.rb', content)
|
69
|
-
runner.should have(0).errors
|
70
71
|
end
|
71
72
|
end
|
data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
CHANGED
@@ -1,40 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module RailsBestPractices
|
4
|
+
module Reviews
|
5
|
+
describe ReplaceInstanceVariableWithLocalVariableReview do
|
6
|
+
let(:runner) { Core::Runner.new(:reviews => ReplaceInstanceVariableWithLocalVariableReview.new) }
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
it "should replace instance variable with local varialbe" do
|
9
|
+
content = <<-EOF
|
10
|
+
<%= @post.title %>
|
11
|
+
EOF
|
12
|
+
runner.review('app/views/posts/_post.html.erb', content)
|
13
|
+
runner.should have(1).errors
|
14
|
+
runner.errors[0].to_s.should == "app/views/posts/_post.html.erb:1 - replace instance variable with local variable"
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
it "should replace instance variable with local varialbe in haml file" do
|
18
|
+
content = <<-EOF
|
17
19
|
= @post.title
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
EOF
|
21
|
+
runner.review('app/views/posts/_post.html.haml', content)
|
22
|
+
runner.should have(1).errors
|
23
|
+
runner.errors[0].to_s.should == "app/views/posts/_post.html.haml:1 - replace instance variable with local variable"
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
it "should replace instance variable with local varialbe in slim file" do
|
27
|
+
content = <<-EOF
|
26
28
|
= @post.title
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
EOF
|
30
|
+
runner.review('app/views/posts/_post.html.slim', content)
|
31
|
+
runner.should have(1).errors
|
32
|
+
runner.errors[0].to_s.should == "app/views/posts/_post.html.slim:1 - replace instance variable with local variable"
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
it "should not replace instance variable with local varialbe" do
|
36
|
+
content = <<-EOF
|
37
|
+
<%= post.title %>
|
38
|
+
EOF
|
39
|
+
runner.review('app/views/posts/_post.html.erb', content)
|
40
|
+
runner.should have(0).errors
|
41
|
+
end
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
@@ -1,98 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
:prepares =>
|
7
|
-
:reviews => RailsBestPractices::Reviews::RestrictAutoGeneratedRoutesReview.new
|
8
|
-
)
|
9
|
-
}
|
3
|
+
module RailsBestPractices
|
4
|
+
module Reviews
|
5
|
+
describe RestrictAutoGeneratedRoutesReview do
|
6
|
+
let(:runner) { Core::Runner.new(:prepares => Prepares::ControllerPrepare.new, :reviews => RestrictAutoGeneratedRoutesReview.new) }
|
10
7
|
|
11
|
-
|
12
|
-
before :each do
|
13
|
-
content =<<-EOF
|
14
|
-
class PostsController < ApplicationController
|
15
|
-
def show; end
|
16
|
-
def new; end
|
17
|
-
def create; end
|
18
|
-
def edit; end
|
19
|
-
def update; end
|
20
|
-
def destroy; end
|
21
|
-
end
|
22
|
-
EOF
|
23
|
-
runner.prepare('app/controllers/posts_controller.rb', content)
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "rails2" do
|
27
|
-
it "should restrict auto-generated routes" do
|
28
|
-
content =<<-EOF
|
29
|
-
ActionController::Routing::Routes.draw do |map|
|
30
|
-
map.resources :posts
|
31
|
-
end
|
32
|
-
EOF
|
33
|
-
runner.review('config/routes.rb', content)
|
34
|
-
runner.should have(1).errors
|
35
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should not restrict auto-generated routes with only" do
|
39
|
-
content =<<-EOF
|
40
|
-
ActionController::Routing::Routes.draw do |map|
|
41
|
-
map.resources :posts, :only => [:show, :new, :create, :edit, :update, :destroy]
|
42
|
-
end
|
43
|
-
EOF
|
44
|
-
runner.review('config/routes.rb', content)
|
45
|
-
runner.should have(0).errors
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should not restrict auto-generated routes with except" do
|
49
|
-
content =<<-EOF
|
50
|
-
ActionController::Routing::Routes.draw do |map|
|
51
|
-
map.resources :posts, :except => :index
|
52
|
-
end
|
53
|
-
EOF
|
54
|
-
runner.review('config/routes.rb', content)
|
55
|
-
runner.should have(0).errors
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should not restrict auto-generated routes with :only => :none" do
|
59
|
-
content =<<-EOF
|
60
|
-
ActionController::Routing::Routes.draw do |map|
|
61
|
-
map.resources :posts, :only => :none
|
62
|
-
end
|
63
|
-
EOF
|
64
|
-
runner.review('config/routes.rb', content)
|
65
|
-
runner.should have(0).errors
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not restrict auto-generated routes with :except => :all" do
|
69
|
-
content =<<-EOF
|
70
|
-
ActionController::Routing::Routes.draw do |map|
|
71
|
-
map.resources :posts, :except => :all
|
72
|
-
end
|
73
|
-
EOF
|
74
|
-
runner.review('config/routes.rb', content)
|
75
|
-
runner.should have(0).errors
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "specify a controller" do
|
79
|
-
it "should restrict auto-generated routes" do
|
80
|
-
content =<<-EOF
|
81
|
-
ActionController::Routing::Routes.draw do |map|
|
82
|
-
map.resources :articles, :controller => "posts"
|
83
|
-
end
|
84
|
-
EOF
|
85
|
-
runner.review('config/routes.rb', content)
|
86
|
-
runner.should have(1).errors
|
87
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "nested routes" do
|
8
|
+
describe "resources" do
|
92
9
|
before :each do
|
93
10
|
content =<<-EOF
|
94
|
-
class
|
95
|
-
def index; end
|
11
|
+
class PostsController < ApplicationController
|
96
12
|
def show; end
|
97
13
|
def new; end
|
98
14
|
def create; end
|
@@ -101,253 +17,336 @@ describe RailsBestPractices::Reviews::RestrictAutoGeneratedRoutesReview do
|
|
101
17
|
def destroy; end
|
102
18
|
end
|
103
19
|
EOF
|
104
|
-
runner.prepare('app/controllers/
|
20
|
+
runner.prepare('app/controllers/posts_controller.rb', content)
|
105
21
|
end
|
106
22
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
23
|
+
describe "rails2" do
|
24
|
+
it "should restrict auto-generated routes" do
|
25
|
+
content =<<-EOF
|
26
|
+
ActionController::Routing::Routes.draw do |map|
|
27
|
+
map.resources :posts
|
112
28
|
end
|
29
|
+
EOF
|
30
|
+
runner.review('config/routes.rb', content)
|
31
|
+
runner.should have(1).errors
|
32
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
113
33
|
end
|
114
|
-
EOF
|
115
|
-
runner.review('config/routes.rb', content)
|
116
|
-
runner.should have(1).errors
|
117
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
118
|
-
end
|
119
34
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
post.resources :comments
|
35
|
+
it "should not restrict auto-generated routes with only" do
|
36
|
+
content =<<-EOF
|
37
|
+
ActionController::Routing::Routes.draw do |map|
|
38
|
+
map.resources :posts, :only => [:show, :new, :create, :edit, :update, :destroy]
|
125
39
|
end
|
40
|
+
EOF
|
41
|
+
runner.review('config/routes.rb', content)
|
42
|
+
runner.should have(0).errors
|
126
43
|
end
|
127
|
-
EOF
|
128
|
-
runner.review('config/routes.rb', content)
|
129
|
-
runner.should have(0).errors
|
130
|
-
end
|
131
44
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
post.resources :comments
|
45
|
+
it "should not restrict auto-generated routes with except" do
|
46
|
+
content =<<-EOF
|
47
|
+
ActionController::Routing::Routes.draw do |map|
|
48
|
+
map.resources :posts, :except => :index
|
137
49
|
end
|
50
|
+
EOF
|
51
|
+
runner.review('config/routes.rb', content)
|
52
|
+
runner.should have(0).errors
|
138
53
|
end
|
139
|
-
EOF
|
140
|
-
runner.review('config/routes.rb', content)
|
141
|
-
runner.should have(0).errors
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
54
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
156
|
-
end
|
55
|
+
it "should not restrict auto-generated routes with :only => :none" do
|
56
|
+
content =<<-EOF
|
57
|
+
ActionController::Routing::Routes.draw do |map|
|
58
|
+
map.resources :posts, :only => :none
|
59
|
+
end
|
60
|
+
EOF
|
61
|
+
runner.review('config/routes.rb', content)
|
62
|
+
runner.should have(0).errors
|
63
|
+
end
|
157
64
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
65
|
+
it "should not restrict auto-generated routes with :except => :all" do
|
66
|
+
content =<<-EOF
|
67
|
+
ActionController::Routing::Routes.draw do |map|
|
68
|
+
map.resources :posts, :except => :all
|
69
|
+
end
|
70
|
+
EOF
|
71
|
+
runner.review('config/routes.rb', content)
|
72
|
+
runner.should have(0).errors
|
73
|
+
end
|
167
74
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
75
|
+
describe "specify a controller" do
|
76
|
+
it "should restrict auto-generated routes" do
|
77
|
+
content =<<-EOF
|
78
|
+
ActionController::Routing::Routes.draw do |map|
|
79
|
+
map.resources :articles, :controller => "posts"
|
80
|
+
end
|
81
|
+
EOF
|
82
|
+
runner.review('config/routes.rb', content)
|
83
|
+
runner.should have(1).errors
|
84
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
85
|
+
end
|
86
|
+
end
|
177
87
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
88
|
+
describe "nested routes" do
|
89
|
+
before :each do
|
90
|
+
content =<<-EOF
|
91
|
+
class CommentsController < ApplicationController
|
92
|
+
def index; end
|
93
|
+
def show; end
|
94
|
+
def new; end
|
95
|
+
def create; end
|
96
|
+
def edit; end
|
97
|
+
def update; end
|
98
|
+
def destroy; end
|
99
|
+
end
|
100
|
+
EOF
|
101
|
+
runner.prepare('app/controllers/comments_controller.rb', content)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should restrict auto-generated routes" do
|
105
|
+
content =<<-EOF
|
106
|
+
ActionController::Routing::Routes.draw do |map|
|
107
|
+
map.resources :posts do |post|
|
108
|
+
post.resources :comments
|
109
|
+
end
|
110
|
+
end
|
111
|
+
EOF
|
112
|
+
runner.review('config/routes.rb', content)
|
113
|
+
runner.should have(1).errors
|
114
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not restrict auto-generated routes with only" do
|
118
|
+
content =<<-EOF
|
119
|
+
ActionController::Routing::Routes.draw do |map|
|
120
|
+
map.resources :posts, :only => [:show, :new, :create, :edit, :update, :destroy] do |post|
|
121
|
+
post.resources :comments
|
122
|
+
end
|
123
|
+
end
|
124
|
+
EOF
|
125
|
+
runner.review('config/routes.rb', content)
|
126
|
+
runner.should have(0).errors
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not restrict auto-generated routes with except" do
|
130
|
+
content =<<-EOF
|
131
|
+
ActionController::Routing::Routes.draw do |map|
|
132
|
+
map.resources :posts, :except => :index do |post|
|
133
|
+
post.resources :comments
|
134
|
+
end
|
135
|
+
end
|
136
|
+
EOF
|
137
|
+
runner.review('config/routes.rb', content)
|
138
|
+
runner.should have(0).errors
|
139
|
+
end
|
183
140
|
end
|
184
|
-
EOF
|
185
|
-
runner.review('config/routes.rb', content)
|
186
|
-
runner.should have(1).errors
|
187
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
188
141
|
end
|
189
|
-
end
|
190
142
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
143
|
+
describe "rails3" do
|
144
|
+
it "should restrict auto-generated routes" do
|
145
|
+
content =<<-EOF
|
146
|
+
RailsBestPracticesCom::Application.routes.draw do
|
147
|
+
resources :posts
|
148
|
+
end
|
149
|
+
EOF
|
150
|
+
runner.review('config/routes.rb', content)
|
151
|
+
runner.should have(1).errors
|
152
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
201
153
|
end
|
202
|
-
EOF
|
203
|
-
runner.prepare('app/controllers/admin/comments_controller.rb', content)
|
204
154
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
resources :
|
155
|
+
it "should not restrict auto-generated routes with only" do
|
156
|
+
content =<<-EOF
|
157
|
+
RailsBestPracticesCom::Application.routes.draw do
|
158
|
+
resources :posts, :only => [:show, :new, :create, :edit, :update, :destroy]
|
159
|
+
end
|
160
|
+
EOF
|
161
|
+
runner.review('config/routes.rb', content)
|
162
|
+
runner.should have(0).errors
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should not restrict auto-generated routes with except" do
|
166
|
+
content =<<-EOF
|
167
|
+
RailsBestPracticesCom::Application.routes.draw do
|
168
|
+
resources :posts, :except => :index
|
169
|
+
end
|
170
|
+
EOF
|
171
|
+
runner.review('config/routes.rb', content)
|
172
|
+
runner.should have(0).errors
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "specify a controller" do
|
176
|
+
it "should restrict auto-generated routes" do
|
177
|
+
content =<<-EOF
|
178
|
+
RailsBestPracticesCom::Application.routes.draw do
|
179
|
+
resources :articles, :controller => "posts"
|
180
|
+
end
|
181
|
+
EOF
|
182
|
+
runner.review('config/routes.rb', content)
|
183
|
+
runner.should have(1).errors
|
184
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "namespace" do
|
189
|
+
it "should restrict auto-generated routes" do
|
190
|
+
content =<<-EOF
|
191
|
+
class Admin::CommentsController < ApplicationController
|
192
|
+
def show; end
|
193
|
+
def new; end
|
194
|
+
def create; end
|
195
|
+
def edit; end
|
196
|
+
def update; end
|
197
|
+
def destroy; end
|
198
|
+
end
|
199
|
+
EOF
|
200
|
+
runner.prepare('app/controllers/admin/comments_controller.rb', content)
|
201
|
+
|
202
|
+
content =<<-EOF
|
203
|
+
RailsBestPracticesCom::Application.routes.draw do
|
204
|
+
namespace :admin do
|
205
|
+
resources :comments
|
206
|
+
end
|
207
|
+
end
|
208
|
+
EOF
|
209
|
+
runner.review('config/routes.rb', content)
|
210
|
+
runner.should have(1).errors
|
211
|
+
runner.errors[0].to_s.should == "config/routes.rb:3 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "nested routes" do
|
216
|
+
before :each do
|
217
|
+
content =<<-EOF
|
218
|
+
class CommentsController < ApplicationController
|
219
|
+
def index; end
|
220
|
+
def show; end
|
221
|
+
def new; end
|
222
|
+
def create; end
|
223
|
+
def edit; end
|
224
|
+
def update; end
|
225
|
+
def destroy; end
|
226
|
+
end
|
227
|
+
EOF
|
228
|
+
runner.prepare('app/controllers/comments_controller.rb', content)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should restrict auto-generated routes" do
|
232
|
+
content =<<-EOF
|
233
|
+
RailsBestPracticesCom::Application.routes.draw do
|
234
|
+
resources :posts do
|
235
|
+
resources :comments
|
236
|
+
end
|
237
|
+
end
|
238
|
+
EOF
|
239
|
+
runner.review('config/routes.rb', content)
|
240
|
+
runner.should have(1).errors
|
241
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should not restrict auto-generated routes with only" do
|
245
|
+
content =<<-EOF
|
246
|
+
RailsBestPracticesCom::Application.routes.draw do
|
247
|
+
resources :posts, :only => [:show, :new, :create, :edit, :update, :destroy] do
|
248
|
+
resources :comments
|
249
|
+
end
|
250
|
+
end
|
251
|
+
EOF
|
252
|
+
runner.review('config/routes.rb', content)
|
253
|
+
runner.should have(0).errors
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should not restrict auto-generated routes with except" do
|
257
|
+
content =<<-EOF
|
258
|
+
RailsBestPracticesCom::Application.routes.draw do
|
259
|
+
resources :posts, :except => :index do
|
260
|
+
resources :comments
|
261
|
+
end
|
262
|
+
end
|
263
|
+
EOF
|
264
|
+
runner.review('config/routes.rb', content)
|
265
|
+
runner.should have(0).errors
|
209
266
|
end
|
210
267
|
end
|
211
|
-
EOF
|
212
|
-
runner.review('config/routes.rb', content)
|
213
|
-
runner.should have(1).errors
|
214
|
-
runner.errors[0].to_s.should == "config/routes.rb:3 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
215
268
|
end
|
216
269
|
end
|
217
270
|
|
218
|
-
describe "
|
271
|
+
describe "resource" do
|
219
272
|
before :each do
|
220
273
|
content =<<-EOF
|
221
|
-
class
|
222
|
-
def index; end
|
274
|
+
class AccountsController < ApplicationController
|
223
275
|
def show; end
|
224
276
|
def new; end
|
225
277
|
def create; end
|
226
278
|
def edit; end
|
227
279
|
def update; end
|
228
|
-
def destroy; end
|
229
280
|
end
|
230
281
|
EOF
|
231
|
-
runner.prepare('app/controllers/
|
282
|
+
runner.prepare('app/controllers/accounts_controller.rb', content)
|
232
283
|
end
|
233
284
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
285
|
+
describe "rails2" do
|
286
|
+
it "should restrict auto-generated routes" do
|
287
|
+
content =<<-EOF
|
288
|
+
ActionController::Routing::Routes.draw do |map|
|
289
|
+
map.resource :account
|
239
290
|
end
|
291
|
+
EOF
|
292
|
+
runner.review('config/routes.rb', content)
|
293
|
+
runner.should have(1).errors
|
294
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update])"
|
240
295
|
end
|
241
|
-
EOF
|
242
|
-
runner.review('config/routes.rb', content)
|
243
|
-
runner.should have(1).errors
|
244
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update, :destroy])"
|
245
|
-
end
|
246
296
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
resources :comments
|
297
|
+
it "should not restrict auto-generated routes with only" do
|
298
|
+
content =<<-EOF
|
299
|
+
ActionController::Routing::Routes.draw do |map|
|
300
|
+
map.resource :account, :only => [:show, :new, :create, :edit, :update]
|
252
301
|
end
|
302
|
+
EOF
|
303
|
+
runner.review('config/routes.rb', content)
|
304
|
+
runner.should have(0).errors
|
253
305
|
end
|
254
|
-
EOF
|
255
|
-
runner.review('config/routes.rb', content)
|
256
|
-
runner.should have(0).errors
|
257
|
-
end
|
258
306
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
resources :comments
|
307
|
+
it "should not restrict auto-generated routes with except" do
|
308
|
+
content =<<-EOF
|
309
|
+
ActionController::Routing::Routes.draw do |map|
|
310
|
+
map.resource :account, :except => :destroy
|
264
311
|
end
|
312
|
+
EOF
|
313
|
+
runner.review('config/routes.rb', content)
|
314
|
+
runner.should have(0).errors
|
265
315
|
end
|
266
|
-
EOF
|
267
|
-
runner.review('config/routes.rb', content)
|
268
|
-
runner.should have(0).errors
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
describe "resource" do
|
275
|
-
before :each do
|
276
|
-
content =<<-EOF
|
277
|
-
class AccountsController < ApplicationController
|
278
|
-
def show; end
|
279
|
-
def new; end
|
280
|
-
def create; end
|
281
|
-
def edit; end
|
282
|
-
def update; end
|
283
|
-
end
|
284
|
-
EOF
|
285
|
-
runner.prepare('app/controllers/accounts_controller.rb', content)
|
286
|
-
end
|
287
|
-
|
288
|
-
describe "rails2" do
|
289
|
-
it "should restrict auto-generated routes" do
|
290
|
-
content =<<-EOF
|
291
|
-
ActionController::Routing::Routes.draw do |map|
|
292
|
-
map.resource :account
|
293
|
-
end
|
294
|
-
EOF
|
295
|
-
runner.review('config/routes.rb', content)
|
296
|
-
runner.should have(1).errors
|
297
|
-
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update])"
|
298
|
-
end
|
299
|
-
|
300
|
-
it "should not restrict auto-generated routes with only" do
|
301
|
-
content =<<-EOF
|
302
|
-
ActionController::Routing::Routes.draw do |map|
|
303
|
-
map.resource :account, :only => [:show, :new, :create, :edit, :update]
|
304
316
|
end
|
305
|
-
EOF
|
306
|
-
runner.review('config/routes.rb', content)
|
307
|
-
runner.should have(0).errors
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should not restrict auto-generated routes with except" do
|
311
|
-
content =<<-EOF
|
312
|
-
ActionController::Routing::Routes.draw do |map|
|
313
|
-
map.resource :account, :except => :destroy
|
314
|
-
end
|
315
|
-
EOF
|
316
|
-
runner.review('config/routes.rb', content)
|
317
|
-
runner.should have(0).errors
|
318
|
-
end
|
319
|
-
end
|
320
317
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
318
|
+
describe "rails3" do
|
319
|
+
it "should restrict auto-generated routes" do
|
320
|
+
content =<<-EOF
|
321
|
+
ActionController::Routing::Routes.draw do |map|
|
322
|
+
map.resource :account
|
323
|
+
end
|
324
|
+
EOF
|
325
|
+
runner.review('config/routes.rb', content)
|
326
|
+
runner.should have(1).errors
|
327
|
+
runner.errors[0].to_s.should == "config/routes.rb:2 - restrict auto-generated routes (:only => [:show, :new, :create, :edit, :update])"
|
328
|
+
end
|
332
329
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
330
|
+
it "should not restrict auto-generated routes with only" do
|
331
|
+
content =<<-EOF
|
332
|
+
ActionController::Routing::Routes.draw do |map|
|
333
|
+
map.resource :account, :only => [:show, :new, :create, :edit, :update]
|
334
|
+
end
|
335
|
+
EOF
|
336
|
+
runner.review('config/routes.rb', content)
|
337
|
+
runner.should have(0).errors
|
338
|
+
end
|
342
339
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
340
|
+
it "should not restrict auto-generated routes with except" do
|
341
|
+
content =<<-EOF
|
342
|
+
ActionController::Routing::Routes.draw do |map|
|
343
|
+
map.resource :account, :except => :destroy
|
344
|
+
end
|
345
|
+
EOF
|
346
|
+
runner.review('config/routes.rb', content)
|
347
|
+
runner.should have(0).errors
|
348
|
+
end
|
347
349
|
end
|
348
|
-
EOF
|
349
|
-
runner.review('config/routes.rb', content)
|
350
|
-
runner.should have(0).errors
|
351
350
|
end
|
352
351
|
end
|
353
352
|
end
|