rails_best_practices 0.3.11 → 0.3.12

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/README.textile CHANGED
@@ -82,7 +82,7 @@ IsolateSeedDataCheck: { }
82
82
  AlwaysAddDbIndexCheck: { }
83
83
  UseBeforeFilterCheck: { }
84
84
  MoveCodeIntoControllerCheck: { }
85
- MoveCodeIntoHelperCheck: { }
85
+ MoveCodeIntoHelperCheck: { array_count: 3 }
86
86
  ReplaceInstanceVariableWithLocalVariableCheck: { }
87
87
  </code></pre>
88
88
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.11
1
+ 0.3.12
data/identifier ADDED
File without changes
@@ -4,7 +4,7 @@ module RailsBestPractices
4
4
  module Checks
5
5
  # Check a view file to make sure there is no complex options_for_select message call.
6
6
  #
7
- # Implementation: Check if arguments of options_for_select message call contain more than 2 method call, then move it into helper.
7
+ # Implementation: Check if first argument of options_for_select is an array and contains more than two nodes, then it should be moved into helper.
8
8
  class MoveCodeIntoHelperCheck < Check
9
9
 
10
10
  def interesting_nodes
@@ -15,14 +15,19 @@ module RailsBestPractices
15
15
  VIEW_FILES
16
16
  end
17
17
 
18
+ def initialize(options = {})
19
+ super()
20
+ @array_count = options['array_count'] || 3
21
+ end
22
+
18
23
  def evaluate_start(node)
19
- add_error "move code into helper" if complex_select_options?(node)
24
+ add_error "move code into helper (array_count >= #{@array_count})" if complex_select_options?(node)
20
25
  end
21
26
 
22
27
  private
23
28
 
24
29
  def complex_select_options?(node)
25
- :options_for_select == node.message and node.arguments.grep_nodes(:node_type => :call).size > 2
30
+ :options_for_select == node.message and :array == node.arguments[1].node_type and node.arguments[1].size > @array_count
26
31
  end
27
32
  end
28
33
  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.3.11"
8
+ s.version = "0.3.12"
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-12-08}
12
+ s.date = %q{2009-12-09}
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}
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "bin/rails_best_practices",
28
+ "identifier",
28
29
  "lib/rails_best_practices.rb",
29
30
  "lib/rails_best_practices/checks.rb",
30
31
  "lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb",
@@ -88,27 +89,27 @@ Gem::Specification.new do |s|
88
89
  s.rubygems_version = %q{1.3.5}
89
90
  s.summary = %q{check rails files according to ihower's presentation 'rails best practices'}
90
91
  s.test_files = [
91
- "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
92
- "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
93
- "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
94
- "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
95
- "spec/rails_best_practices/checks/use_observer_check_spec.rb",
96
- "spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
97
- "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
92
+ "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
98
93
  "spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
99
- "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
100
- "spec/rails_best_practices/checks/use_before_filter_check_spec.rb",
94
+ "spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
95
+ "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
101
96
  "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
102
- "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
103
- "spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
104
- "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
97
+ "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
98
+ "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
99
+ "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
105
100
  "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
106
- "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
107
- "spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
101
+ "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
102
+ "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
103
+ "spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
104
+ "spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
105
+ "spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
106
+ "spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
108
107
  "spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb",
108
+ "spec/rails_best_practices/checks/use_before_filter_check_spec.rb",
109
109
  "spec/rails_best_practices/checks/use_model_association_check_spec.rb",
110
- "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
111
- "spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
110
+ "spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
111
+ "spec/rails_best_practices/checks/use_observer_check_spec.rb",
112
+ "spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
112
113
  "spec/spec_helper.rb"
113
114
  ]
114
115
 
@@ -17,5 +17,5 @@ IsolateSeedDataCheck: { }
17
17
  AlwaysAddDbIndexCheck: { }
18
18
  UseBeforeFilterCheck: { }
19
19
  MoveCodeIntoControllerCheck: { }
20
- MoveCodeIntoHelperCheck: { }
20
+ MoveCodeIntoHelperCheck: { array_count: 3 }
21
21
  ReplaceInstanceVariableWithLocalVariableCheck: { }
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  describe RailsBestPractices::Checks::MoveCodeIntoHelperCheck do
4
4
  before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveCodeIntoHelperCheck.new)
5
+ @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveCodeIntoHelperCheck.new('array_count' => 2))
6
6
  end
7
7
 
8
8
  it "should move code into helper" do
@@ -15,7 +15,7 @@ describe RailsBestPractices::Checks::MoveCodeIntoHelperCheck do
15
15
  @runner.check('app/views/posts/show.html.erb', content)
16
16
  errors = @runner.errors
17
17
  errors.should_not be_empty
18
- errors[0].to_s.should == "app/views/posts/show.html.erb:3 - move code into helper"
18
+ errors[0].to_s.should == "app/views/posts/show.html.erb:3 - move code into helper (array_count >= 2)"
19
19
  end
20
20
 
21
21
  it "should not move code into helper with simple arguments" do
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.3.11
4
+ version: 0.3.12
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-12-08 00:00:00 +08:00
12
+ date: 2009-12-09 00:00:00 +08:00
13
13
  default_executable: rails_best_practices
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,6 +48,7 @@ files:
48
48
  - Rakefile
49
49
  - VERSION
50
50
  - bin/rails_best_practices
51
+ - identifier
51
52
  - lib/rails_best_practices.rb
52
53
  - lib/rails_best_practices/checks.rb
53
54
  - lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb
@@ -133,25 +134,25 @@ signing_key:
133
134
  specification_version: 3
134
135
  summary: check rails files according to ihower's presentation 'rails best practices'
135
136
  test_files:
137
+ - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
138
+ - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
136
139
  - spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb
137
- - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
138
- - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
140
+ - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
141
+ - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
142
+ - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
139
143
  - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
140
- - spec/rails_best_practices/checks/use_observer_check_spec.rb
141
- - spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
144
+ - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
145
+ - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
146
+ - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
147
+ - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
142
148
  - spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
143
- - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
144
- - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
145
- - spec/rails_best_practices/checks/use_before_filter_check_spec.rb
146
- - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
147
- - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
148
- - spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
149
149
  - spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
150
- - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
151
- - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
152
- - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
150
+ - spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
151
+ - spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
153
152
  - spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb
153
+ - spec/rails_best_practices/checks/use_before_filter_check_spec.rb
154
154
  - spec/rails_best_practices/checks/use_model_association_check_spec.rb
155
- - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
156
- - spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
155
+ - spec/rails_best_practices/checks/use_model_callback_check_spec.rb
156
+ - spec/rails_best_practices/checks/use_observer_check_spec.rb
157
+ - spec/rails_best_practices/checks/use_scope_access_check_spec.rb
157
158
  - spec/spec_helper.rb