rails_best_practices 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +18 -3
  3. data/Guardfile +19 -0
  4. data/README.md +5 -13
  5. data/lib/rails_best_practices.rb +3 -2
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +37 -6
  8. data/lib/rails_best_practices/core/routes.rb +3 -1
  9. data/lib/rails_best_practices/core/runner.rb +4 -7
  10. data/lib/rails_best_practices/core_ext/erubis.rb +36 -0
  11. data/lib/rails_best_practices/core_ext/sexp.rb +1 -1
  12. data/lib/rails_best_practices/prepares/controller_prepare.rb +1 -1
  13. data/lib/rails_best_practices/prepares/model_prepare.rb +12 -6
  14. data/lib/rails_best_practices/prepares/route_prepare.rb +35 -16
  15. data/lib/rails_best_practices/prepares/schema_prepare.rb +2 -2
  16. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +3 -3
  17. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
  18. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +3 -3
  19. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +25 -5
  20. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -5
  21. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +3 -3
  22. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -1
  23. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +1 -1
  24. data/lib/rails_best_practices/version.rb +1 -1
  25. data/rails_best_practices.gemspec +4 -1
  26. data/spec/rails_best_practices/core/routes_spec.rb +12 -0
  27. data/spec/rails_best_practices/core_ext/erubis_spec.rb +24 -0
  28. data/spec/rails_best_practices/core_ext/sexp_spec.rb +5 -0
  29. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +60 -0
  30. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +67 -27
  31. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +68 -1
  32. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +1 -1
  33. data/spec/spec_helper.rb +20 -11
  34. metadata +65 -29
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe RailsBestPractices::Reviews::RemoveUnusedMethodsInControllersReview do
4
4
  let(:runner) { RailsBestPractices::Core::Runner.new(
5
5
  :prepares => [RailsBestPractices::Prepares::ControllerPrepare.new, RailsBestPractices::Prepares::RoutePrepare.new],
6
- :reviews => RailsBestPractices::Reviews::RemoveUnusedMethodsInControllersReview.new({'except_methods' => []})
6
+ :reviews => RailsBestPractices::Reviews::RemoveUnusedMethodsInControllersReview.new({'except_methods' => ["ExceptableController#*"]})
7
7
  ) }
8
8
 
9
9
  context "private/protected" do
@@ -116,5 +116,72 @@ describe RailsBestPractices::Reviews::RemoveUnusedMethodsInControllersReview do
116
116
  runner.on_complete
117
117
  runner.should have(0).errors
118
118
  end
119
+
120
+ it "should not remove unused methods if they are except_methods" do
121
+ content =<<-EOF
122
+ class ExceptableController < ApplicationController
123
+ def list; end
124
+ end
125
+ EOF
126
+ runner.prepare('app/controllers/exceptable_controller.rb', content)
127
+ runner.review('app/controllers/exceptable_controller.rb', content)
128
+ runner.on_complete
129
+ runner.should have(0).errors
130
+ end
131
+ end
132
+
133
+ context "cells" do
134
+ it "should remove unused methods" do
135
+ content =<<-EOF
136
+ class PostsCell < Cell::Rails
137
+ def list; end
138
+ end
139
+ EOF
140
+ runner.prepare('app/cells/posts_cell.rb', content)
141
+ runner.review('app/cells/posts_cell.rb', content)
142
+ runner.on_complete
143
+ runner.should have(1).errors
144
+ runner.errors[0].to_s.should == "app/cells/posts_cell.rb:2 - remove unused methods (PostsCell#list)"
145
+ end
146
+
147
+ it "should not remove unused methods if render_cell" do
148
+ content =<<-EOF
149
+ class PostsCell < Cell::Rails
150
+ def list; end
151
+ def display; end
152
+ end
153
+ EOF
154
+ runner.prepare('app/cells/posts_cell.rb', content)
155
+ runner.review('app/cells/posts_cell.rb', content)
156
+ content =<<-EOF
157
+ <%= render_cell :posts, :list %>
158
+ <%= render_cell(:posts, :display) %>
159
+ EOF
160
+ runner.review('app/views/posts/index.html.erb', content)
161
+ runner.on_complete
162
+ runner.should have(0).errors
163
+ end
164
+
165
+ it "should not remove unused methods if render with state" do
166
+ content =<<-EOF
167
+ class PostsCell < Cell::Rails
168
+ def list
169
+ render :state => :show
170
+ render(:state => :display)
171
+ end
172
+
173
+ def show; end
174
+ def display; end
175
+ end
176
+ EOF
177
+ runner.prepare('app/cells/posts_cell.rb', content)
178
+ runner.review('app/cells/posts_cell.rb', content)
179
+ content =<<-EOF
180
+ <%= render_cell :posts, :list %>
181
+ EOF
182
+ runner.review('app/views/posts/index.html.erb', content)
183
+ runner.on_complete
184
+ runner.should have(0).errors
185
+ end
119
186
  end
120
187
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe RailsBestPractices::Reviews::RemoveUnusedMethodsInModelsReview do
4
4
  let(:runner) { RailsBestPractices::Core::Runner.new(
5
5
  :prepares => RailsBestPractices::Prepares::ModelPrepare.new,
6
- :reviews => RailsBestPractices::Reviews::RemoveUnusedMethodsInModelsReview.new({'except_methods' => ['set_cache']})
6
+ :reviews => RailsBestPractices::Reviews::RemoveUnusedMethodsInModelsReview.new({'except_methods' => ["*#set_cache"]})
7
7
  ) }
8
8
 
9
9
  context "private" do
@@ -1,17 +1,26 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
1
+ require 'rubygems'
2
+ require 'spork'
3
3
 
4
- require 'rspec/expectations'
5
- require 'rails_best_practices'
4
+ Spork.prefork do
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
7
 
7
- RSpec.configure do |config|
8
- config.after do
9
- RailsBestPractices::Prepares.clear
8
+ require 'rspec'
9
+
10
+ RSpec.configure do |config|
11
+ config.after do
12
+ RailsBestPractices::Prepares.clear
13
+ end
14
+ config.filter_run :focus => true
15
+ config.run_all_when_everything_filtered = true
16
+ end
17
+
18
+ def parse_content(content)
19
+ Sexp.from_array(Ripper::SexpBuilder.new(content).parse)[1]
10
20
  end
11
- config.filter_run :focus => true
12
- config.run_all_when_everything_filtered = true
13
21
  end
14
22
 
15
- def parse_content(content)
16
- Sexp.from_array(Ripper::SexpBuilder.new(content).parse)[1]
23
+ Spork.each_run do
24
+ require 'rails_best_practices'
17
25
  end
26
+
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: 1.4.0
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-20 00:00:00.000000000Z
12
+ date: 2011-11-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sexp_processor
16
- requirement: &2152381700 !ruby/object:Gem::Requirement
16
+ requirement: &70247886541600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152381700
24
+ version_requirements: *70247886541600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: progressbar
27
- requirement: &2152380940 !ruby/object:Gem::Requirement
27
+ requirement: &70247886540700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152380940
35
+ version_requirements: *70247886540700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: colored
38
- requirement: &2152380200 !ruby/object:Gem::Requirement
38
+ requirement: &70247886540000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152380200
46
+ version_requirements: *70247886540000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: erubis
49
- requirement: &2152379500 !ruby/object:Gem::Requirement
49
+ requirement: &70247886539360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2152379500
57
+ version_requirements: *70247886539360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: i18n
60
- requirement: &2152378620 !ruby/object:Gem::Requirement
60
+ requirement: &70247886538640 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2152378620
68
+ version_requirements: *70247886538640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &2152373900 !ruby/object:Gem::Requirement
71
+ requirement: &70247886537980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2152373900
79
+ version_requirements: *70247886537980
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &2152373120 !ruby/object:Gem::Requirement
82
+ requirement: &70247886537200 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2152373120
90
+ version_requirements: *70247886537200
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &2152372280 !ruby/object:Gem::Requirement
93
+ requirement: &70247886536480 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2152372280
101
+ version_requirements: *70247886536480
102
102
  - !ruby/object:Gem::Dependency
103
- name: watchr
104
- requirement: &2152371480 !ruby/object:Gem::Requirement
103
+ name: haml
104
+ requirement: &70247886535760 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2152371480
112
+ version_requirements: *70247886535760
113
113
  - !ruby/object:Gem::Dependency
114
- name: haml
115
- requirement: &2152370380 !ruby/object:Gem::Requirement
114
+ name: bundler
115
+ requirement: &70247886534860 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,43 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2152370380
123
+ version_requirements: *70247886534860
124
124
  - !ruby/object:Gem::Dependency
125
- name: bundler
126
- requirement: &2152369500 !ruby/object:Gem::Requirement
125
+ name: spork
126
+ requirement: &70247886533880 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - =
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.0.rc9
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *70247886533880
135
+ - !ruby/object:Gem::Dependency
136
+ name: guard
137
+ requirement: &70247886532280 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *70247886532280
146
+ - !ruby/object:Gem::Dependency
147
+ name: guard-spork
148
+ requirement: &70247886531300 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: *70247886531300
157
+ - !ruby/object:Gem::Dependency
158
+ name: guard-rspec
159
+ requirement: &70247886530520 !ruby/object:Gem::Requirement
127
160
  none: false
128
161
  requirements:
129
162
  - - ! '>='
@@ -131,7 +164,7 @@ dependencies:
131
164
  version: '0'
132
165
  type: :development
133
166
  prerelease: false
134
- version_requirements: *2152369500
167
+ version_requirements: *70247886530520
135
168
  description: a code metric tool for rails codes, written in Ruby.
136
169
  email:
137
170
  - flyerhzm@gmail.com
@@ -145,10 +178,10 @@ files:
145
178
  - .rspec.example
146
179
  - .rvmrc.example
147
180
  - .travis.yml
148
- - .watchr
149
181
  - .watchr.example
150
182
  - Gemfile
151
183
  - Gemfile.lock
184
+ - Guardfile
152
185
  - MIT_LICENSE
153
186
  - README.md
154
187
  - Rakefile
@@ -173,6 +206,7 @@ files:
173
206
  - lib/rails_best_practices/core/routes.rb
174
207
  - lib/rails_best_practices/core/runner.rb
175
208
  - lib/rails_best_practices/core_ext/enumerable.rb
209
+ - lib/rails_best_practices/core_ext/erubis.rb
176
210
  - lib/rails_best_practices/core_ext/sexp.rb
177
211
  - lib/rails_best_practices/lexicals.rb
178
212
  - lib/rails_best_practices/lexicals/remove_tab_check.rb
@@ -233,6 +267,7 @@ files:
233
267
  - spec/rails_best_practices/core/routes_spec.rb
234
268
  - spec/rails_best_practices/core/runner_spec.rb
235
269
  - spec/rails_best_practices/core_ext/enumerable_spec.rb
270
+ - spec/rails_best_practices/core_ext/erubis_spec.rb
236
271
  - spec/rails_best_practices/core_ext/sexp_spec.rb
237
272
  - spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
238
273
  - spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
@@ -289,7 +324,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
289
324
  version: '0'
290
325
  segments:
291
326
  - 0
292
- hash: 1634590398891543727
327
+ hash: -3104358296029422528
293
328
  required_rubygems_version: !ruby/object:Gem::Requirement
294
329
  none: false
295
330
  requirements:
@@ -318,6 +353,7 @@ test_files:
318
353
  - spec/rails_best_practices/core/routes_spec.rb
319
354
  - spec/rails_best_practices/core/runner_spec.rb
320
355
  - spec/rails_best_practices/core_ext/enumerable_spec.rb
356
+ - spec/rails_best_practices/core_ext/erubis_spec.rb
321
357
  - spec/rails_best_practices/core_ext/sexp_spec.rb
322
358
  - spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
323
359
  - spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb