rails_best_practices 0.3.17 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.17
1
+ 0.3.18
@@ -11,6 +11,8 @@ module RailsBestPractices
11
11
  VIEW_FILES = /views\/.*(erb|haml)/
12
12
  PARTIAL_VIEW_FILES = /views\/.*\/_.*(erb|haml)/
13
13
 
14
+ attr_reader :errors
15
+
14
16
  def initialize
15
17
  @errors = []
16
18
  end
@@ -57,10 +59,6 @@ module RailsBestPractices
57
59
  line ||= @node.line
58
60
  @errors << RailsBestPractices::Core::Error.new("#{file}", "#{line}", error)
59
61
  end
60
-
61
- def errors
62
- @errors
63
- end
64
62
  end
65
63
  end
66
64
  end
@@ -21,7 +21,7 @@ module RailsBestPractices
21
21
  end
22
22
 
23
23
  def evaluate_start(node)
24
- if s(:lvar, :map) == node.subject and :resources == node.message
24
+ if :resources == node.message
25
25
  add_error "overuse route customizations (customize_count > #{@customize_count})" if member_and_collection_count(node) > @customize_count
26
26
  end
27
27
  end
@@ -1,9 +1,9 @@
1
1
  module RailsBestPractices
2
2
  module Core
3
3
  class CheckingVisitor
4
- def initialize(*checks)
4
+ def initialize(checks)
5
5
  @checks ||= {}
6
- checks.first.each do |check|
6
+ checks.each do |check|
7
7
  nodes = check.interesting_nodes
8
8
  nodes.each do |node|
9
9
  @checks[node] ||= []
@@ -10,11 +10,7 @@ module RailsBestPractices
10
10
  CUSTOM_CONFIG = File.join('config', 'rails_best_practices.yml')
11
11
 
12
12
  def initialize(*checks)
13
- if File.exists?(CUSTOM_CONFIG)
14
- @config = CUSTOM_CONFIG
15
- else
16
- @config = DEFAULT_CONFIG
17
- end
13
+ @config = File.exists?(CUSTOM_CONFIG) ? CUSTOM_CONFIG : DEFAULT_CONFIG
18
14
  @checks = checks unless checks.empty?
19
15
  @checks ||= load_checks
20
16
  @checker ||= CheckingVisitor.new(@checks)
@@ -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.3.17"
8
+ s.version = "0.3.18"
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{2010-01-25}
12
+ s.date = %q{2010-03-15}
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}
@@ -88,31 +88,31 @@ Gem::Specification.new do |s|
88
88
  s.homepage = %q{http://github.com/flyerhzm/rails_best_practices}
89
89
  s.rdoc_options = ["--charset=UTF-8"]
90
90
  s.require_paths = ["lib"]
91
- s.rubygems_version = %q{1.3.5}
91
+ s.rubygems_version = %q{1.3.6}
92
92
  s.summary = %q{check rails files according to ihower's presentation 'rails best practices'}
93
93
  s.test_files = [
94
- "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
95
- "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
96
- "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
97
- "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
98
- "spec/rails_best_practices/checks/use_observer_check_spec.rb",
99
- "spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
100
- "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
94
+ "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
101
95
  "spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
102
- "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
103
- "spec/rails_best_practices/checks/use_before_filter_check_spec.rb",
96
+ "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
97
+ "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
104
98
  "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
105
- "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
106
- "spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
107
- "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
99
+ "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
100
+ "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
101
+ "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
102
+ "spec/rails_best_practices/checks/move_code_into_model_check_spec.rb",
108
103
  "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
109
- "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
110
- "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
104
+ "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
105
+ "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
106
+ "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
107
+ "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
108
+ "spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
109
+ "spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
111
110
  "spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb",
111
+ "spec/rails_best_practices/checks/use_before_filter_check_spec.rb",
112
112
  "spec/rails_best_practices/checks/use_model_association_check_spec.rb",
113
- "spec/rails_best_practices/checks/move_code_into_model_check_spec.rb",
114
- "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
115
- "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
113
+ "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
114
+ "spec/rails_best_practices/checks/use_observer_check_spec.rb",
115
+ "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
116
116
  "spec/spec_helper.rb"
117
117
  ]
118
118
 
@@ -34,6 +34,23 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
34
34
  errors.should_not be_empty
35
35
  errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
36
36
  end
37
+
38
+ it "should overuse route customizations with collection 2" do
39
+ content = <<-EOF
40
+ ActionController::Routing::Routes.draw do |map|
41
+ map.resources :categories do |category|
42
+ category.resources :posts, :member => { :create_comment => :post,
43
+ :update_comment => :post,
44
+ :delete_comment => :post },
45
+ :collection => { :comments => :get }
46
+ end
47
+ end
48
+ EOF
49
+ @runner.check('config/routes.rb', content)
50
+ errors = @runner.errors
51
+ errors.should_not be_empty
52
+ errors[0].to_s.should == "config/routes.rb:3 - overuse route customizations (customize_count > 3)"
53
+ end
37
54
 
38
55
  it "should not overuse route customizations without customization" do
39
56
  content = <<-EOF
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.17
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 18
9
+ version: 0.3.18
5
10
  platform: ruby
6
11
  authors:
7
12
  - Richard Huang
@@ -9,29 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-25 00:00:00 +08:00
17
+ date: 2010-03-15 00:00:00 +08:00
13
18
  default_executable: rails_best_practices
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: ruby_parser
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 4
23
31
  version: 2.0.4
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: ruby2ruby
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 4
33
45
  version: 1.2.4
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  description: check rails files according to ihower's presentation 'rails best practices'
36
49
  email: flyerhzm@gmail.com
37
50
  executables:
@@ -120,42 +133,44 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
133
  requirements:
121
134
  - - ">="
122
135
  - !ruby/object:Gem::Version
136
+ segments:
137
+ - 0
123
138
  version: "0"
124
- version:
125
139
  required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  requirements:
127
141
  - - ">="
128
142
  - !ruby/object:Gem::Version
143
+ segments:
144
+ - 0
129
145
  version: "0"
130
- version:
131
146
  requirements: []
132
147
 
133
148
  rubyforge_project:
134
- rubygems_version: 1.3.5
149
+ rubygems_version: 1.3.6
135
150
  signing_key:
136
151
  specification_version: 3
137
152
  summary: check rails files according to ihower's presentation 'rails best practices'
138
153
  test_files:
154
+ - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
155
+ - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
139
156
  - spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb
140
- - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
141
- - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
157
+ - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
158
+ - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
159
+ - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
142
160
  - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
143
- - spec/rails_best_practices/checks/use_observer_check_spec.rb
144
- - spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
161
+ - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
162
+ - spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
163
+ - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
164
+ - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
165
+ - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
145
166
  - spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
146
- - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
147
- - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
148
- - spec/rails_best_practices/checks/use_before_filter_check_spec.rb
149
- - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
150
- - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
151
- - spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
152
167
  - spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
153
- - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
154
- - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
155
- - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
168
+ - spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
169
+ - spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
156
170
  - spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb
171
+ - spec/rails_best_practices/checks/use_before_filter_check_spec.rb
157
172
  - spec/rails_best_practices/checks/use_model_association_check_spec.rb
158
- - spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
159
- - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
160
- - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
173
+ - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
174
+ - spec/rails_best_practices/checks/use_observer_check_spec.rb
175
+ - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
161
176
  - spec/spec_helper.rb