rails_best_practices 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/MIT_LICENSE +1 -1
  2. data/README.md +8 -7
  3. data/assets/result.html.haml +11 -3
  4. data/autotest/discover.rb +1 -0
  5. data/install_supported_rubies.sh +8 -0
  6. data/lib/rails_best_practices.rb +5 -3
  7. data/lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb +3 -0
  8. data/lib/rails_best_practices/checks/always_add_db_index_check.rb +3 -0
  9. data/lib/rails_best_practices/checks/check.rb +1 -1
  10. data/lib/rails_best_practices/checks/dry_bundler_in_capistrano_check.rb +3 -0
  11. data/lib/rails_best_practices/checks/isolate_seed_data_check.rb +3 -0
  12. data/lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb +4 -0
  13. data/lib/rails_best_practices/checks/law_of_demeter_check.rb +4 -0
  14. data/lib/rails_best_practices/checks/move_code_into_controller_check.rb +4 -0
  15. data/lib/rails_best_practices/checks/move_code_into_helper_check.rb +3 -0
  16. data/lib/rails_best_practices/checks/move_code_into_model_check.rb +3 -0
  17. data/lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb +4 -0
  18. data/lib/rails_best_practices/checks/move_model_logic_into_model_check.rb +3 -0
  19. data/lib/rails_best_practices/checks/needless_deep_nesting_check.rb +3 -0
  20. data/lib/rails_best_practices/checks/not_use_default_route_check.rb +3 -0
  21. data/lib/rails_best_practices/checks/overuse_route_customizations_check.rb +4 -0
  22. data/lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb +3 -0
  23. data/lib/rails_best_practices/checks/replace_instance_variable_with_local_variable_check.rb +3 -0
  24. data/lib/rails_best_practices/checks/use_before_filter_check.rb +12 -2
  25. data/lib/rails_best_practices/checks/use_model_association_check.rb +3 -0
  26. data/lib/rails_best_practices/checks/use_observer_check.rb +3 -0
  27. data/lib/rails_best_practices/checks/use_query_attribute_check.rb +4 -0
  28. data/lib/rails_best_practices/checks/use_say_with_time_in_migrations_check.rb +3 -0
  29. data/lib/rails_best_practices/checks/use_scope_access_check.rb +3 -0
  30. data/lib/rails_best_practices/command.rb +17 -11
  31. data/lib/rails_best_practices/core/error.rb +3 -2
  32. data/lib/rails_best_practices/core/runner.rb +7 -3
  33. data/lib/rails_best_practices/version.rb +1 -1
  34. data/rails_best_practices.gemspec +16 -0
  35. data/rake_rubies.sh +9 -0
  36. data/spec/rails_best_practices/checks/use_before_filter_check_spec.rb +20 -0
  37. data/spec/rails_best_practices_spec.rb +2 -2
  38. metadata +22 -6
  39. data/rubies_test.sh +0 -10
data/MIT_LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com)
1
+ Copyright (c) 2009 - 2011 Richard Huang (flyerhzm@gmail.com)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,11 +3,6 @@ rails_best_practices
3
3
 
4
4
  rails_best_practices is a code metric tool to check the quality of rails codes.
5
5
 
6
- Donate
7
- ------
8
-
9
- <a href='http://www.pledgie.com/campaigns/12057'><img alt='Click here to lend your support to: rails-bestpractices.com and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/12057.png?skin_name=chrome' border='0' /></a>
10
-
11
6
  Usage
12
7
  -----
13
8
 
@@ -26,6 +21,7 @@ By default rails_best_practices will do parse codes in vendor, spec, test and fe
26
21
  -d, --debug Debug mode
27
22
  -f, --format FORMAT output format
28
23
  --without-color only output plain text without color
24
+ --with-textmate open file by textmate in html format
29
25
  --vendor include vendor files
30
26
  --spec include spec files
31
27
  --test include test files
@@ -53,6 +49,11 @@ Wiki: <http://github.com/flyerhzm/rails_best_practices/wiki>
53
49
 
54
50
  Issue Tracker: <http://github.com/flyerhzm/rails_best_practices/issues>
55
51
 
52
+ Donating
53
+ --------
54
+
55
+ <a href='http://www.pledgie.com/campaigns/12057'>Support rails_best_practices at Pledgie</a>
56
+
56
57
  Install
57
58
  -------
58
59
 
@@ -74,7 +75,7 @@ First run
74
75
 
75
76
  rails_best_practices -g
76
77
 
77
- to generate <code>rails_best_practices.yml</code> file.
78
+ to generate `rails_best_practices.yml` file.
78
79
 
79
80
  Now you can customize this configuration file, the default configuration is as follows:
80
81
 
@@ -164,4 +165,4 @@ Follow us on twitter: <http://twitter.com/railsbp>
164
165
  Send us email: <team@rails-bestpractices.com>
165
166
 
166
167
 
167
- Copyright © 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
168
+ Copyright © 2009 - 2011 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -35,7 +35,10 @@
35
35
  }
36
36
  %body
37
37
  %h1 rails_best_practices output
38
- %h2 Please go to <a href="http://rails-bestpractices.com">http://rails-bestpractices.com</a> to see more useful Rails Best Practices.
38
+ %h2
39
+ Please go to
40
+ %a{:href=>"http://rails-bestpractices.com", :target=>"_blank"} http://rails-bestpractices.com
41
+ to see more useful Rails Best Practices.
39
42
  %h2
40
43
  - if errors.empty?
41
44
  No error found. Cool!
@@ -48,6 +51,11 @@
48
51
  %th Error Message
49
52
  - errors.each do |error|
50
53
  %tr
51
- %td.filename= error.filename
54
+ %td.filename
55
+ - if textmate
56
+ %a{:href=>"txmt://open/?url=file://#{File.expand_path(error.filename)}&line=#{error.line_number}"}= error.filename
57
+ - else
58
+ = error.filename
52
59
  %td.line-number= error.line_number
53
- %td.message= error.message
60
+ %td.message
61
+ %a{:href=>"#{error.url}", :target=>"_blank"}= error.message
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ rubies=( 1.8.7 1.9.2 ree )
3
+ for x in ${rubies[*]}
4
+ do
5
+ rvm install $x || exit $?
6
+ rvm $x && rvm gemset use global && gem install bundler || exit $?
7
+ bundle install || exit $?
8
+ done
@@ -28,6 +28,7 @@ require 'colored'
28
28
  require 'haml'
29
29
  require 'rails_best_practices/checks'
30
30
  require 'rails_best_practices/core'
31
+ require 'fileutils'
31
32
 
32
33
  # RailsBestPractices helps you to analyze your rails code, according to best practices on http://rails-bestpractices.
33
34
  # if it finds any violatioins to best practices, it will give you some readable suggestions.
@@ -70,10 +71,11 @@ module RailsBestPractices
70
71
  Core::Runner.base_path = @path
71
72
  @runner = Core::Runner.new
72
73
  @runner.debug = true if @options['debug']
74
+ @runner.color = !options['without-color']
73
75
 
74
76
  if @runner.checks.find { |check| check.is_a? Checks::AlwaysAddDbIndexCheck } &&
75
77
  !review_files.find { |file| file.index "db\/schema.rb" }
76
- puts "AlwaysAddDbIndexCheck is disabled as there is no db/schema.rb file in your rails project.".blue
78
+ plain_output("AlwaysAddDbIndexCheck is disabled as there is no db/schema.rb file in your rails project.", 'blue')
77
79
  end
78
80
 
79
81
  @bar = ProgressBar.new('Analyzing', prepare_files.size + review_files.size)
@@ -139,7 +141,7 @@ module RailsBestPractices
139
141
  # @param [Array] dirs what directories to expand
140
142
  # @return [Array] all files expanded
141
143
  def expand_dirs_to_files *dirs
142
- extensions = ['rb', 'erb', 'haml', 'builder']
144
+ extensions = ['rb', 'erb', 'rhtml', 'haml', 'builder']
143
145
 
144
146
  dirs.flatten.map { |entry|
145
147
  next unless File.exist? entry
@@ -206,7 +208,7 @@ module RailsBestPractices
206
208
  template = File.read(File.join(File.dirname(__FILE__), "..", "assets", "result.html.haml"))
207
209
 
208
210
  File.open("rails_best_practices_output.html", "w+") do |file|
209
- file.puts Haml::Engine.new(template).render(Object.new, :errors => @runner.errors)
211
+ file.puts Haml::Engine.new(template).render(Object.new, :errors => @runner.errors, :textmate => @options["with-textmate"])
210
212
  end
211
213
  end
212
214
  end
@@ -27,6 +27,9 @@ module RailsBestPractices
27
27
  #
28
28
  # then the model needs to add a virtual attribute.
29
29
  class AddModelVirtualAttributeCheck < Check
30
+ def url
31
+ "http://rails-bestpractices.com/posts/4-add-model-virtual-attribute"
32
+ end
30
33
 
31
34
  def interesting_review_nodes
32
35
  [:defn]
@@ -27,6 +27,9 @@ module RailsBestPractices
27
27
  # if there are any foreign keys not existed in index columns,
28
28
  # then the foreign keys should add db index.
29
29
  class AlwaysAddDbIndexCheck < Check
30
+ def url
31
+ "http://rails-bestpractices.com/posts/21-always-add-db-index"
32
+ end
30
33
 
31
34
  def interesting_review_nodes
32
35
  [:call, :iter]
@@ -137,7 +137,7 @@ module RailsBestPractices
137
137
  # file is the filename of source code
138
138
  # line is the line number of the source code which is reviewing
139
139
  def add_error(error, file = @node.file, line = @node.line)
140
- @errors << RailsBestPractices::Core::Error.new("#{file}", "#{line}", error)
140
+ @errors << RailsBestPractices::Core::Error.new("#{file}", "#{line}", error, url)
141
141
  end
142
142
 
143
143
  # remember use count for the local or instance variable in the call or attrasgn node.
@@ -18,6 +18,9 @@ module RailsBestPractices
18
18
  # if the message of call node is :namespace and the arguments of the call node is :bundler,
19
19
  # then it should use bundler's capistrano recipe.
20
20
  class DryBundlerInCapistranoCheck < Check
21
+ def url
22
+ "http://rails-bestpractices.com/posts/51-dry-bundler-in-capistrano"
23
+ end
21
24
 
22
25
  def interesting_review_nodes
23
26
  [:call]
@@ -24,6 +24,9 @@ module RailsBestPractices
24
24
  # and the subject is included in new variables,
25
25
  # then it should be isolated to db seed.
26
26
  class IsolateSeedDataCheck < Check
27
+ def url
28
+ "http://rails-bestpractices.com/posts/20-isolating-seed-data"
29
+ end
27
30
 
28
31
  def interesting_review_nodes
29
32
  [:call, :lasgn, :iasgn]
@@ -23,6 +23,10 @@ module RailsBestPractices
23
23
 
24
24
  FINDERS = [:find, :all, :first, :last]
25
25
 
26
+ def url
27
+ "http://rails-bestpractices.com/posts/13-keep-finders-on-their-own-model"
28
+ end
29
+
26
30
  def interesting_review_nodes
27
31
  [:call]
28
32
  end
@@ -22,6 +22,10 @@ module RailsBestPractices
22
22
 
23
23
  prepare_model_associations
24
24
 
25
+ def url
26
+ "http://rails-bestpractices.com/posts/15-the-law-of-demeter"
27
+ end
28
+
25
29
  def interesting_review_nodes
26
30
  [:call]
27
31
  end
@@ -18,6 +18,10 @@ module RailsBestPractices
18
18
 
19
19
  FINDERS = [:find, :all, :first, :last]
20
20
 
21
+ def url
22
+ "http://rails-bestpractices.com/posts/24-move-code-into-controller"
23
+ end
24
+
21
25
  def interesting_review_nodes
22
26
  [:call]
23
27
  end
@@ -22,6 +22,9 @@ module RailsBestPractices
22
22
  # and the size of the array is greater than array_count defined,
23
23
  # then the options_for_select method should be moved into helper.
24
24
  class MoveCodeIntoHelperCheck < Check
25
+ def url
26
+ "http://rails-bestpractices.com/posts/26-move-code-into-helper"
27
+ end
25
28
 
26
29
  def interesting_review_nodes
27
30
  [:call]
@@ -17,6 +17,9 @@ module RailsBestPractices
17
17
  # and the subject is a local variable or instance variable,
18
18
  # then they should be moved into model.
19
19
  class MoveCodeIntoModelCheck < Check
20
+ def url
21
+ "http://rails-bestpractices.com/posts/25-move-code-into-model"
22
+ end
20
23
 
21
24
  def interesting_review_nodes
22
25
  [:if]
@@ -21,6 +21,10 @@ module RailsBestPractices
21
21
 
22
22
  FINDER = [:find, :all, :first, :last]
23
23
 
24
+ def url
25
+ "http://rails-bestpractices.com/posts/1-move-finder-to-named_scope"
26
+ end
27
+
24
28
  def interesting_review_nodes
25
29
  [:call]
26
30
  end
@@ -18,6 +18,9 @@ module RailsBestPractices
18
18
  # and the subject is a local variable or an instance variable,
19
19
  # then they are complex model logic, and they should be moved into model.
20
20
  class MoveModelLogicIntoModelCheck < Check
21
+ def url
22
+ "http://rails-bestpractices.com/posts/7-move-model-logic-into-the-model"
23
+ end
21
24
 
22
25
  def interesting_review_nodes
23
26
  [:defn]
@@ -30,6 +30,9 @@ module RailsBestPractices
30
30
  # and the @counter is greater than @nested_count defined,
31
31
  # then it is a needless deep nesting.
32
32
  class NeedlessDeepNestingCheck < Check
33
+ def url
34
+ "http://rails-bestpractices.com/posts/11-needless-deep-nesting"
35
+ end
33
36
 
34
37
  def interesting_review_nodes
35
38
  [:call, :iter]
@@ -22,6 +22,9 @@ module RailsBestPractices
22
22
  #
23
23
  # match ':controller(/:action(/:id(.:format)))'
24
24
  class NotUseDefaultRouteCheck < Check
25
+ def url
26
+ "http://rails-bestpractices.com/posts/12-not-use-default-route-if-you-use-restful-design"
27
+ end
25
28
 
26
29
  def interesting_review_nodes
27
30
  [:call]
@@ -34,6 +34,10 @@ module RailsBestPractices
34
34
 
35
35
  VERBS = [:get, :post, :update, :delete]
36
36
 
37
+ def url
38
+ "http://rails-bestpractices.com/posts/10-overuse-route-customizations"
39
+ end
40
+
37
41
  def interesting_review_nodes
38
42
  [:call, :iter]
39
43
  end
@@ -19,6 +19,9 @@ module RailsBestPractices
19
19
  # and after them there is a call node with message :save or :save!,
20
20
  # then these attribute assignments are complex creation, should be replaced with factory method.
21
21
  class ReplaceComplexCreationWithFactoryMethodCheck < Check
22
+ def url
23
+ "http://rails-bestpractices.com/posts/6-replace-complex-creation-with-factory-method"
24
+ end
22
25
 
23
26
  def interesting_review_nodes
24
27
  [:defn]
@@ -16,6 +16,9 @@ module RailsBestPractices
16
16
  # check all instance variable in partial view files,
17
17
  # if exist, then they should be replaced with local variable
18
18
  class ReplaceInstanceVariableWithLocalVariableCheck < Check
19
+ def url
20
+ "http://rails-bestpractices.com/posts/27-replace-instance-variable-with-local-variable"
21
+ end
19
22
 
20
23
  def interesting_review_nodes
21
24
  [:ivar]
@@ -17,6 +17,12 @@ module RailsBestPractices
17
17
  # if they are duplicated, then they should be moved to before_filter.
18
18
  class UseBeforeFilterCheck < Check
19
19
 
20
+ PROTECTED_PRIVATE_CALLS = [[:call, nil, :protected, [:arglist]], [:call, nil, :private, [:arglist]]]
21
+
22
+ def url
23
+ "http://rails-bestpractices.com/posts/22-use-before_filter"
24
+ end
25
+
20
26
  def interesting_review_nodes
21
27
  [:class]
22
28
  end
@@ -27,7 +33,7 @@ module RailsBestPractices
27
33
 
28
34
  # check class define node to see if there are method define nodes whose first code line are duplicated in review process.
29
35
  #
30
- # it will every defn nodes in the class node,
36
+ # it will check every defn nodes in the class node until protected or private identification,
31
37
  # if there are defn nodes who have the same first code line, like
32
38
  #
33
39
  # s(:class, :PostsController, s(:const, :ApplicationController),
@@ -70,7 +76,11 @@ module RailsBestPractices
70
76
  # then these duplicated first code lines should be moved to before_filter.
71
77
  def review_start_class(class_node)
72
78
  @first_sentences = {}
73
- class_node.grep_nodes({:node_type => :defn}) { |defn_node| remember_first_sentence(defn_node) }
79
+
80
+ class_node.body.children.each do |child_node|
81
+ break if PROTECTED_PRIVATE_CALLS.include? child_node
82
+ remember_first_sentence(child_node) if :defn == child_node.node_type
83
+ end
74
84
  @first_sentences.each do |first_sentence, defn_nodes|
75
85
  if defn_nodes.size > 1
76
86
  add_error "use before_filter for #{defn_nodes.collect(&:method_name).join(',')}", class_node.file, defn_nodes.collect(&:line).join(',')
@@ -19,6 +19,9 @@ module RailsBestPractices
19
19
  # and the subjects of attribute assignment node and call node are the same,
20
20
  # then model association should be used instead of xxx_id assignment.
21
21
  class UseModelAssociationCheck < Check
22
+ def url
23
+ "http://rails-bestpractices.com/posts/2-use-model-association"
24
+ end
22
25
 
23
26
  def interesting_review_nodes
24
27
  [:defn]
@@ -24,6 +24,9 @@ module RailsBestPractices
24
24
  # and there is a mailer deliver call,
25
25
  # then the method should be replaced by using observer.
26
26
  class UseObserverCheck < Check
27
+ def url
28
+ "http://rails-bestpractices.com/posts/19-use-observer"
29
+ end
27
30
 
28
31
  def interesting_prepare_nodes
29
32
  [:class]
@@ -26,6 +26,10 @@ module RailsBestPractices
26
26
 
27
27
  prepare_model_associations
28
28
 
29
+ def url
30
+ "http://rails-bestpractices.com/posts/56-use-query-attribute"
31
+ end
32
+
29
33
  def interesting_review_nodes
30
34
  [:if]
31
35
  end
@@ -22,6 +22,9 @@ module RailsBestPractices
22
22
  DEFAULT_MIGRATION_METHODS = [:add_column, :add_index, :add_timestamps, :change_column, :change_column_default, :change_table, :create_table, :drop_table, :remove_column, :remove_index, :remove_timestamps, :rename_column, :rename_index, :rename_table]
23
23
  WITH_SAY_METHODS = DEFAULT_MIGRATION_METHODS + [:say, :say_with_time]
24
24
 
25
+ def url
26
+ "http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log"
27
+ end
25
28
 
26
29
  def interesting_review_nodes
27
30
  [:defs]
@@ -19,6 +19,9 @@ module RailsBestPractices
19
19
  # and there is redirect_to method call in if block body,
20
20
  # then it should be replaced by using scope access.
21
21
  class UseScopeAccessCheck < Check
22
+ def url
23
+ "http://rails-bestpractices.com/posts/3-use-scope-access"
24
+ end
22
25
 
23
26
  def interesting_review_nodes
24
27
  [:if]
@@ -2,17 +2,19 @@
2
2
  require 'optparse'
3
3
 
4
4
  # Usage: rails_best_practices [options] path
5
- # -d, --debug Debug mode
6
- # -f, --format FORMAT output format
7
- # --vendor include vendor files
8
- # --spec include spec files
9
- # --test include test files
10
- # --features include features files
11
- # -x, --exclude PATTERNS Don't analyze files matching a pattern
12
- # (comma-separated regexp list)
13
- # -g, --generate Generate configuration yaml
14
- # -v, --version Show this version
15
- # -h, --help Show this message
5
+ # -d, --debug Debug mode
6
+ # -f, --format FORMAT output format
7
+ # --without-color only output plain text without color
8
+ # --with-textmate open file by textmate in html format
9
+ # --vendor include vendor files
10
+ # --spec include spec files
11
+ # --test include test files
12
+ # --features include features files
13
+ # -x, --exclude PATTERNS Don't analyze files matching a pattern
14
+ # (comma-separated regexp list)
15
+ # -g, --generate Generate configuration yaml
16
+ # -v, --version Show this version
17
+ # -h, --help Show this message
16
18
  options = {}
17
19
  OptionParser.new do |opts|
18
20
  opts.banner = "Usage: rails_best_practices [options] path"
@@ -29,6 +31,10 @@ OptionParser.new do |opts|
29
31
  options["without-color"] = true
30
32
  end
31
33
 
34
+ opts.on("--with-textmate", "open file by textmate in html format") do
35
+ options["with-textmate"] = true
36
+ end
37
+
32
38
  ['vendor', 'spec', 'test', 'features'].each do |pattern|
33
39
  opts.on("--#{pattern}", "include #{pattern} files") do
34
40
  options[pattern] = true
@@ -5,12 +5,13 @@ module RailsBestPractices
5
5
  #
6
6
  # it indicates the filenname, line number and error message for the violation.
7
7
  class Error
8
- attr_reader :filename, :line_number, :message
8
+ attr_reader :filename, :line_number, :message, :url
9
9
 
10
- def initialize(filename, line_number, message)
10
+ def initialize(filename, line_number, message, url = nil)
11
11
  @filename = filename
12
12
  @line_number = line_number
13
13
  @message = message
14
+ @url = url
14
15
  end
15
16
 
16
17
  def to_s
@@ -15,7 +15,7 @@ module RailsBestPractices
15
15
  # 2. review process, it does real check, if the source code violates some best practices, the violations will be notified.
16
16
  class Runner
17
17
  attr_reader :checks
18
- attr_accessor :debug
18
+ attr_accessor :debug, :color
19
19
 
20
20
  # set the base path.
21
21
  #
@@ -78,7 +78,11 @@ module RailsBestPractices
78
78
  begin
79
79
  RubyParser.new.parse(content, filename)
80
80
  rescue Exception => e
81
- puts "#{filename} looks like it's not a valid Ruby file. Skipping...".red if @debug
81
+ if @debug
82
+ warning = "#{filename} looks like it's not a valid Ruby file. Skipping..."
83
+ warning = warning.red if self.color
84
+ puts warning
85
+ end
82
86
  nil
83
87
  end
84
88
  end
@@ -88,7 +92,7 @@ module RailsBestPractices
88
92
  # filename is the filename of the erb or haml code.
89
93
  # content is the source code of erb or haml file.
90
94
  def parse_erb_or_haml(filename, content)
91
- if filename =~ /.*\.erb$/
95
+ if filename =~ /.*\.erb|.*\.rhtml$/
92
96
  content = Erubis::Eruby.new(content).src
93
97
  elsif filename =~ /.*\.haml$/
94
98
  begin
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "0.6.5"
3
+ VERSION = "0.6.6"
4
4
  end
5
5
 
@@ -29,4 +29,20 @@ Gem::Specification.new do |s|
29
29
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
30
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
31
31
  s.require_paths = ["lib"]
32
+
33
+ s.post_install_message = <<-POST_INSTALL_MESSAGE
34
+ #{"*" * 80}
35
+
36
+ rails_best_practices is a code metric tool to check the quality of rails codes.
37
+
38
+ I highly recommend you go through the Rails Best Practices website first.
39
+
40
+ http://rails-bestpractices.com
41
+
42
+ Enjoy!
43
+
44
+ Richard Huang (flyerhzm@gmail.com)
45
+
46
+ #{"*" * 80}
47
+ POST_INSTALL_MESSAGE
32
48
  end
data/rake_rubies.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ rubies=( 1.8.7 1.9.2 ree )
3
+ gemset="rails_best_practices"
4
+
5
+ for x in ${rubies[*]}
6
+ do
7
+ rvm use --create $x@$gemset && bundle install || exit $?
8
+ done
9
+ rvm ree@$gemset,1.8.7@$gemset,1.9.2@$gemset rake spec:progress
@@ -82,4 +82,24 @@ describe RailsBestPractices::Checks::UseBeforeFilterCheck do
82
82
  errors = @runner.errors
83
83
  errors.should be_empty
84
84
  end
85
+
86
+ it "should not use before_filter for protected/private methods" do
87
+ content =<<-EOF
88
+ class PostsController < ApplicationController
89
+ protected
90
+ def load_comments
91
+ load_post
92
+ @comments = @post.comments
93
+ end
94
+
95
+ def load_user
96
+ load_post
97
+ @user = @post.user
98
+ end
99
+ end
100
+ EOF
101
+ @runner.review('app/controllers/posts_controller.rb', content)
102
+ errors = @runner.errors
103
+ errors.should be_empty
104
+ end
85
105
  end
@@ -26,7 +26,7 @@ describe RailsBestPractices do
26
26
  end
27
27
  end
28
28
 
29
- describe "output_errors" do
29
+ describe "output_terminal_errors" do
30
30
  check1 = RailsBestPractices::Checks::LawOfDemeterCheck.new
31
31
  check2 = RailsBestPractices::Checks::UseQueryAttributeCheck.new
32
32
  runner = RailsBestPractices::Core::Runner.new(check1, check2)
@@ -36,7 +36,7 @@ describe RailsBestPractices do
36
36
 
37
37
  $origin_stdout = $stdout
38
38
  $stdout = StringIO.new
39
- RailsBestPractices.output_errors
39
+ RailsBestPractices.output_terminal_errors
40
40
  result = $stdout.string
41
41
  $stdout = $origin_stdout
42
42
  result.should == ["app/models/user.rb:10 - law of demeter".red, "app/models/post.rb:100 - use query attribute".red, "\nPlease go to http://rails-bestpractices.com to see more useful Rails Best Practices.".green, "\nFound 2 errors.".red].join("\n") + "\n"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 5
10
- version: 0.6.5
9
+ - 6
10
+ version: 0.6.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-04 00:00:00 +08:00
18
+ date: 2011-01-24 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -192,7 +192,9 @@ files:
192
192
  - README.md
193
193
  - Rakefile
194
194
  - assets/result.html.haml
195
+ - autotest/discover.rb
195
196
  - bin/rails_best_practices
197
+ - install_supported_rubies.sh
196
198
  - lib/rails_best_practices.rb
197
199
  - lib/rails_best_practices/checks.rb
198
200
  - lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb
@@ -229,7 +231,7 @@ files:
229
231
  - lib/rails_best_practices/version.rb
230
232
  - rails_best_practices.gemspec
231
233
  - rails_best_practices.yml
232
- - rubies_test.sh
234
+ - rake_rubies.sh
233
235
  - spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
234
236
  - spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
235
237
  - spec/rails_best_practices/checks/check_spec.rb
@@ -263,7 +265,21 @@ has_rdoc: true
263
265
  homepage: http://rails-bestpractices.com
264
266
  licenses: []
265
267
 
266
- post_install_message:
268
+ post_install_message: |
269
+ ********************************************************************************
270
+
271
+ rails_best_practices is a code metric tool to check the quality of rails codes.
272
+
273
+ I highly recommend you go through the Rails Best Practices website first.
274
+
275
+ http://rails-bestpractices.com
276
+
277
+ Enjoy!
278
+
279
+ Richard Huang (flyerhzm@gmail.com)
280
+
281
+ ********************************************************************************
282
+
267
283
  rdoc_options: []
268
284
 
269
285
  require_paths:
data/rubies_test.sh DELETED
@@ -1,10 +0,0 @@
1
- #!/bin/bash
2
- rvm ruby-1.8.7@rails_best_practices ruby -S bundle install || exit $?
3
- rvm ruby-1.9.2@rails_best_practices ruby -S bundle install || exit $?
4
- rvm ree@rails_best_practices ruby -S bundle install || exit $?
5
- rvm 1.8.7@rails_best_practices
6
- rake spec:progress
7
- rvm 1.9.2@rails_best_practices
8
- rake spec:progress
9
- rvm ree@rails_best_practices
10
- rake spec:progress