rails_best_practices 0.2.14 → 0.2.15

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
@@ -57,6 +57,7 @@ IsolateSeedDataCheck: { }
57
57
  AlwaysAddDbIndexCheck: { }
58
58
  UseFilterCheck: { }
59
59
  MoveCodeIntoControllerCheck: { }
60
+ MoveCodeIntoHelperCheck: { }
60
61
  </code></pre>
61
62
 
62
63
  *************************************************
@@ -100,7 +101,7 @@ h2. Progress
100
101
  * Lesson 6. View
101
102
  ## [-Move code into controller-]
102
103
  ## Move code into model
103
- ## Move code into helper
104
+ ## [-Move code into helper-]
104
105
  ## Replace instance variable with local variable
105
106
  ## Use Form Builder
106
107
  ## Organize Helper files
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.14
1
+ 0.2.15
@@ -17,3 +17,4 @@ require 'rails_best_practices/checks/isolate_seed_data_check'
17
17
  require 'rails_best_practices/checks/always_add_db_index_check'
18
18
  require 'rails_best_practices/checks/use_filter_check'
19
19
  require 'rails_best_practices/checks/move_code_into_controller_check'
20
+ require 'rails_best_practices/checks/move_code_into_helper_check'
@@ -0,0 +1,29 @@
1
+ require 'rails_best_practices/checks/check'
2
+
3
+ module RailsBestPractices
4
+ module Checks
5
+ # Check a view file to make sure there is no complex options_for_select message call.
6
+ #
7
+ # Implementation: Check if arguments of options_for_select message call contain more than 2 method call, then move it into helper.
8
+ class MoveCodeIntoHelperCheck < Check
9
+
10
+ def interesting_nodes
11
+ [:call]
12
+ end
13
+
14
+ def interesting_files
15
+ VIEW_FILES
16
+ end
17
+
18
+ def evaluate_start(node)
19
+ add_error "move code into helper" if complex_select_options?(node)
20
+ end
21
+
22
+ private
23
+
24
+ def complex_select_options?(node)
25
+ :options_for_select == node.message and node.arguments.grep_nodes(:node_type => :call).size > 2
26
+ end
27
+ end
28
+ end
29
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_best_practices}
8
- s.version = "0.2.14"
8
+ s.version = "0.2.15"
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"]
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/rails_best_practices/checks/law_of_demeter_check.rb",
36
36
  "lib/rails_best_practices/checks/many_to_many_collection_check.rb",
37
37
  "lib/rails_best_practices/checks/move_code_into_controller_check.rb",
38
+ "lib/rails_best_practices/checks/move_code_into_helper_check.rb",
38
39
  "lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb",
39
40
  "lib/rails_best_practices/checks/move_model_logic_into_model_check.rb",
40
41
  "lib/rails_best_practices/checks/needless_deep_nesting_check.rb",
@@ -63,6 +64,7 @@ Gem::Specification.new do |s|
63
64
  "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
64
65
  "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
65
66
  "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
67
+ "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
66
68
  "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
67
69
  "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
68
70
  "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
@@ -91,6 +93,7 @@ Gem::Specification.new do |s|
91
93
  "spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
92
94
  "spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
93
95
  "spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb",
96
+ "spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb",
94
97
  "spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
95
98
  "spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
96
99
  "spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
@@ -17,3 +17,4 @@ IsolateSeedDataCheck: { }
17
17
  AlwaysAddDbIndexCheck: { }
18
18
  UseFilterCheck: { }
19
19
  MoveCodeIntoControllerCheck: { }
20
+ MoveCodeIntoHelperCheck: { }
@@ -28,7 +28,6 @@ describe RailsBestPractices::Checks::IsolateSeedDataCheck do
28
28
  errors = @runner.errors
29
29
  errors.should_not be_empty
30
30
  errors[0].to_s.should == "db/migrate/20090818130258_create_roles.rb:8 - isolate seed data"
31
- puts errors.inspect
32
31
  errors.size.should == 1
33
32
  end
34
33
 
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe RailsBestPractices::Checks::MoveCodeIntoHelperCheck do
4
+ before(:each) do
5
+ @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveCodeIntoHelperCheck.new)
6
+ end
7
+
8
+ it "should move code into helper" do
9
+ content = <<-EOF
10
+ <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
11
+ [t(:published), "published"]],
12
+ params[:default_state] ) %>
13
+
14
+ EOF
15
+ @runner.check('app/views/posts/show.html.erb', content)
16
+ errors = @runner.errors
17
+ errors.should_not be_empty
18
+ end
19
+
20
+ it "should not move code into helper with simple arguments" do
21
+ content = <<-EOF
22
+ <%= select_tag :state, options_for_select( Post.STATES ) %>
23
+ EOF
24
+ @runner.check('app/views/posts/show.html.erb', content)
25
+ errors = @runner.errors
26
+ errors.should be_empty
27
+ end
28
+ end
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.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
@@ -58,6 +58,7 @@ files:
58
58
  - lib/rails_best_practices/checks/law_of_demeter_check.rb
59
59
  - lib/rails_best_practices/checks/many_to_many_collection_check.rb
60
60
  - lib/rails_best_practices/checks/move_code_into_controller_check.rb
61
+ - lib/rails_best_practices/checks/move_code_into_helper_check.rb
61
62
  - lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
62
63
  - lib/rails_best_practices/checks/move_model_logic_into_model_check.rb
63
64
  - lib/rails_best_practices/checks/needless_deep_nesting_check.rb
@@ -86,6 +87,7 @@ files:
86
87
  - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
87
88
  - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
88
89
  - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
90
+ - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
89
91
  - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
90
92
  - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
91
93
  - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
@@ -136,6 +138,7 @@ test_files:
136
138
  - spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
137
139
  - spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
138
140
  - spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb
141
+ - spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb
139
142
  - spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
140
143
  - spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
141
144
  - spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb