rails_best_practices 1.13.8 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/assets/result.html.erb +1 -1
  4. data/lib/rails_best_practices.rb +3 -25
  5. data/lib/rails_best_practices/analyzer.rb +2 -4
  6. data/lib/rails_best_practices/core.rb +2 -17
  7. data/lib/rails_best_practices/core/runner.rb +1 -1
  8. data/lib/rails_best_practices/lexicals.rb +1 -3
  9. data/lib/rails_best_practices/lexicals/long_line_check.rb +0 -2
  10. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +0 -2
  11. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +0 -2
  12. data/lib/rails_best_practices/prepares.rb +1 -9
  13. data/lib/rails_best_practices/prepares/config_prepare.rb +0 -2
  14. data/lib/rails_best_practices/prepares/controller_prepare.rb +0 -2
  15. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +0 -2
  16. data/lib/rails_best_practices/prepares/helper_prepare.rb +0 -2
  17. data/lib/rails_best_practices/prepares/initializer_prepare.rb +0 -2
  18. data/lib/rails_best_practices/prepares/mailer_prepare.rb +0 -2
  19. data/lib/rails_best_practices/prepares/model_prepare.rb +0 -2
  20. data/lib/rails_best_practices/prepares/route_prepare.rb +0 -2
  21. data/lib/rails_best_practices/prepares/schema_prepare.rb +0 -2
  22. data/lib/rails_best_practices/reviews.rb +1 -37
  23. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +0 -2
  24. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +0 -2
  25. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +0 -2
  26. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +25 -0
  27. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +0 -2
  28. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +0 -2
  29. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +0 -2
  30. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +0 -2
  31. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +0 -2
  32. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +0 -2
  33. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +0 -2
  34. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +0 -2
  35. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +0 -2
  36. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +0 -2
  37. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +0 -2
  38. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +0 -2
  39. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +0 -2
  40. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +0 -2
  41. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +0 -2
  42. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +0 -2
  43. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +0 -2
  44. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +0 -2
  45. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +0 -2
  46. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +0 -2
  47. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +0 -2
  48. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +0 -2
  49. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +0 -2
  50. data/lib/rails_best_practices/reviews/review.rb +0 -3
  51. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +0 -2
  52. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +0 -2
  53. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +0 -2
  54. data/lib/rails_best_practices/reviews/use_model_association_review.rb +0 -2
  55. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +0 -3
  56. data/lib/rails_best_practices/reviews/use_observer_review.rb +0 -2
  57. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +0 -2
  58. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +0 -2
  59. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +0 -2
  60. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +0 -2
  61. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +0 -2
  62. data/lib/rails_best_practices/version.rb +1 -1
  63. data/rails_best_practices.gemspec +4 -3
  64. data/rails_best_practices.yml +1 -0
  65. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +41 -0
  66. metadata +23 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bd66b9f885d3de24877f8f671c8caa7ec05a0de
4
- data.tar.gz: 4c82581c64139d752d9205689a5c0c805735d7fe
3
+ metadata.gz: f156688bf7014687ef1fbe360333886dabc39369
4
+ data.tar.gz: 18c27a29f89c40d5c4fc621719685f5b281cc480
5
5
  SHA512:
6
- metadata.gz: cc478b2544c16dd600bd97c126567638429bf16d3781e15123128e2e7381303019a795c15af8a05821d52d4619beae550c98b18bb6ae1b3c2013d8c126efa800
7
- data.tar.gz: 0ea6abf20e3c61a99c42c4ebd311bc4b31f5eaa5055d07cfce79c7fdda8cd8ed866c8d34414837b9c050cf948c9cfbf8c19d981a7ae0e55b135a339b8129d476
6
+ metadata.gz: e59f2708ddd9c4e71d2e3d9be3544ddd05411d9ca038387a33bcc3c48ebf1a059d945421137b151ddaad9a4c67b91d17944e0f7caae70a5fed3cd21cfc6a9657
7
+ data.tar.gz: 51edce3a83696df402cebe5e20e32b1108c8dd2d594d05f54d47215585e7364b1cd929967e7fb6bf7ea6296b5904e7720426c23d843e7b251b7053a5fe059f95
data/README.md CHANGED
@@ -124,6 +124,7 @@ Now you can customize this configuration file, the default configuration is as f
124
124
  AddModelVirtualAttributeCheck: { }
125
125
  AlwaysAddDbIndexCheck: { }
126
126
  #CheckSaveReturnValueCheck: { }
127
+ DefaultScopeIsEvilCheck: { }
127
128
  DryBundlerInCapistranoCheck: { }
128
129
  #HashSyntaxCheck: { }
129
130
  IsolateSeedDataCheck: { }
@@ -115,7 +115,7 @@
115
115
  <% elsif @textmate %>
116
116
  <a href='txmt://open/?url=file://<%= File.expand_path(error.filename) %>&amp;line=<%= error.line_number %>'><%= error.short_filename %></a>
117
117
  <% elsif @sublime %>
118
- <a href='"subl://open?url=file://"<%= File.expand_path(error.filename) %>&amp;line=<%= error.line_number %>'><%= error.short_filename %></a>
118
+ <a href='subl://open?url=file://<%= File.expand_path(error.filename) %>&amp;line=<%= error.line_number %>'><%= error.short_filename %></a>
119
119
  <% elsif @mvim %>
120
120
  <a href='mvim://open/?url=file://<%= File.expand_path(error.filename) %>&amp;line=<%= error.line_number %>'><%= error.short_filename %></a>
121
121
  <% else %>
@@ -1,33 +1,11 @@
1
1
  # encoding: utf-8
2
-
3
- #--
4
- # Copyright (c) 2010 Richard Huang (flyerhzm@gmail.com)
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining
7
- # a copy of this software and associated documentation files (the
8
- # "Software"), to deal in the Software without restriction, including
9
- # without limitation the rights to use, copy, modify, merge, publish,
10
- # distribute, sublicense, and/or sell copies of the Software, and to
11
- # permit persons to whom the Software is furnished to do so, subject to
12
- # the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be
15
- # included in all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
- #++
25
2
  require 'code_analyzer'
3
+ require 'require_all'
4
+ require 'rails_best_practices/core'
5
+ require 'rails_best_practices/analyzer'
26
6
  require 'rails_best_practices/lexicals'
27
7
  require 'rails_best_practices/prepares'
28
8
  require 'rails_best_practices/reviews'
29
- require 'rails_best_practices/core'
30
- require 'rails_best_practices/analyzer'
31
9
 
32
10
  module RailsBestPractices
33
11
  end
@@ -1,10 +1,8 @@
1
1
  # encoding: utf-8
2
+ require 'ap'
3
+ require 'colored'
2
4
  require 'fileutils'
3
-
4
5
  require 'ruby-progressbar'
5
- require 'colored'
6
- require 'ap'
7
-
8
6
 
9
7
  module RailsBestPractices
10
8
  # RailsBestPractices Analyzer helps you to analyze your rails code, according to best practices on http://rails-bestpractices.
@@ -1,18 +1,3 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
- require 'rails_best_practices/core/runner'
4
- require 'rails_best_practices/core/error'
5
- require 'rails_best_practices/core/klasses'
6
- require 'rails_best_practices/core/modules'
7
- require 'rails_best_practices/core/models'
8
- require 'rails_best_practices/core/model_associations'
9
- require 'rails_best_practices/core/model_attributes'
10
- require 'rails_best_practices/core/mailers'
11
- require 'rails_best_practices/core/methods'
12
- require 'rails_best_practices/core/controllers'
13
- require 'rails_best_practices/core/helpers'
14
- require 'rails_best_practices/core/routes'
15
- require 'rails_best_practices/core/configs'
16
- require 'rails_best_practices/core/gems'
17
-
18
- require 'rails_best_practices/core_ext/erubis'
2
+ require_rel 'core'
3
+ require_rel 'core_ext'
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
2
  require 'yaml'
3
- require 'active_support/inflector'
4
3
  require 'active_support/core_ext/object/blank'
5
4
  begin
6
5
  require 'active_support/core_ext/object/try'
7
6
  rescue LoadError
8
7
  require 'active_support/core_ext/try'
9
8
  end
9
+ require 'active_support/inflector'
10
10
 
11
11
  module RailsBestPractices
12
12
  module Core
@@ -1,4 +1,2 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/lexicals/remove_trailing_whitespace_check'
3
- require 'rails_best_practices/lexicals/remove_tab_check'
4
- require 'rails_best_practices/lexicals/long_line_check'
2
+ require_rel 'lexicals'
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Lexicals
6
4
  # Keep lines fewer than 80 characters.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Lexicals
6
4
  # Make sure there are no tabs in files.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Lexicals
6
4
  # Make sure there are no trailing whitespace in codes.
@@ -1,13 +1,5 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/prepares/model_prepare'
3
- require 'rails_best_practices/prepares/mailer_prepare'
4
- require 'rails_best_practices/prepares/schema_prepare'
5
- require 'rails_best_practices/prepares/controller_prepare'
6
- require 'rails_best_practices/prepares/route_prepare'
7
- require 'rails_best_practices/prepares/helper_prepare'
8
- require 'rails_best_practices/prepares/config_prepare'
9
- require 'rails_best_practices/prepares/gemfile_prepare'
10
- require 'rails_best_practices/prepares/initializer_prepare'
2
+ require_rel 'prepares'
11
3
 
12
4
  module RailsBestPractices
13
5
  module Prepares
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember all configs
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember controllers and controller methods
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember all gems in Gemfile
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember helper methods.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Check all initializers
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember the mailer names.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember models and model associations.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remembber routes.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
-
4
2
  module RailsBestPractices
5
3
  module Prepares
6
4
  # Remember the model attributes.
@@ -1,38 +1,2 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/move_finder_to_named_scope_review'
3
- require 'rails_best_practices/reviews/use_model_association_review'
4
- require 'rails_best_practices/reviews/use_scope_access_review'
5
- require 'rails_best_practices/reviews/add_model_virtual_attribute_review'
6
- require 'rails_best_practices/reviews/replace_complex_creation_with_factory_method_review'
7
- require 'rails_best_practices/reviews/move_model_logic_into_model_review'
8
- require 'rails_best_practices/reviews/overuse_route_customizations_review'
9
- require 'rails_best_practices/reviews/needless_deep_nesting_review'
10
- require 'rails_best_practices/reviews/not_use_default_route_review'
11
- require 'rails_best_practices/reviews/keep_finders_on_their_own_model_review'
12
- require 'rails_best_practices/reviews/law_of_demeter_review'
13
- require 'rails_best_practices/reviews/use_observer_review'
14
- require 'rails_best_practices/reviews/isolate_seed_data_review'
15
- require 'rails_best_practices/reviews/always_add_db_index_review'
16
- require 'rails_best_practices/reviews/use_before_filter_review'
17
- require 'rails_best_practices/reviews/move_code_into_controller_review'
18
- require 'rails_best_practices/reviews/move_code_into_model_review'
19
- require 'rails_best_practices/reviews/move_code_into_helper_review'
20
- require 'rails_best_practices/reviews/replace_instance_variable_with_local_variable_review'
21
- require 'rails_best_practices/reviews/dry_bundler_in_capistrano_review'
22
- require 'rails_best_practices/reviews/use_say_with_time_in_migrations_review'
23
- require 'rails_best_practices/reviews/use_query_attribute_review'
24
- require 'rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review'
25
- require 'rails_best_practices/reviews/simplify_render_in_views_review'
26
- require 'rails_best_practices/reviews/simplify_render_in_controllers_review'
27
- require 'rails_best_practices/reviews/remove_empty_helpers_review'
28
- require 'rails_best_practices/reviews/restrict_auto_generated_routes_review'
29
- require 'rails_best_practices/reviews/remove_unused_methods_in_models_review'
30
- require 'rails_best_practices/reviews/remove_unused_methods_in_controllers_review'
31
- require 'rails_best_practices/reviews/remove_unused_methods_in_helpers_review'
32
- require 'rails_best_practices/reviews/not_use_time_ago_in_words_review'
33
- require 'rails_best_practices/reviews/protect_mass_assignment_review'
34
- require 'rails_best_practices/reviews/use_parentheses_in_method_def_review'
35
- require 'rails_best_practices/reviews/hash_syntax_review'
36
- require 'rails_best_practices/reviews/not_rescue_exception_review'
37
- require 'rails_best_practices/reviews/check_save_return_value_review'
38
- require 'rails_best_practices/reviews/use_turbo_sprockets_rails3_review'
2
+ require_rel 'reviews'
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Make sure to add a model virual attribute to simplify model creation.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review db/schema.rb file to make sure every reference key has a database index.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review all code to make sure we either check the return value of "save"
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ module RailsBestPractices
3
+ module Reviews
4
+ # Review model files to make sure not use default_scope
5
+ #
6
+ # See the best practice details here http://rails-bestpractices.com/posts/806-default_scope-is-evil
7
+ #
8
+ # Implementation:
9
+ #
10
+ # Review process:
11
+ # check all command node to see if its message is default_scope
12
+ class DefaultScopeIsEvilReview < Review
13
+ interesting_nodes :command
14
+ interesting_files MODEL_FILES
15
+ url "http://rails-bestpractices.com/posts/806-default_scope-is-evil"
16
+
17
+ # check all command nodes' message
18
+ add_callback :start_command do |node|
19
+ if "default_scope" == node.message.to_s
20
+ add_error "default_scope is evil"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review config/deploy.rb file to make sure using the bundler's capistrano recipe.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Check ruby 1.8 style hash and suggest to change hash syntax to 1.9.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Make sure not to insert data in migration, move them to seed file.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review model files to ake sure finders are on their own model.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review to make sure not to avoid the law of demeter.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a view file to make sure there is no finder, finder should be moved to controller.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a view file to make sure there is no complex options_for_select message call.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a view file to make sure there is no complex logic call for model.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a controller file to make sure there are no complex finder.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a controller file to make sure that complex model logic should not exist in controller, should be moved into a model.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review config/routes.rb file to make sure not to use too deep nesting routes.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review all code to make sure we don't rescue Exception
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review config/routes file to make sure not use default route that rails generated.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review view and helper files to make sure not use time_ago_in_words or distance_of_time_in_words_to_now.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review config/routes.rb file to make sure there are no overuse route customizations.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review model files to make sure to use attr_accessible, attr_protected or strong_parameters to protect mass assignment.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a helper file to make sure it is not an empty moduel.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Find out unused methods in controllers.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Find out unused methods in helpers.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Find out unused methods in models.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a controller file to make sure that complex model creation should not exist in
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a partail view file to make sure there is no instance variable.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a route file to make sure all auto-generated routes have corresponding actions in controller.
@@ -1,7 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/check'
3
- require 'rails_best_practices/core/error'
4
-
5
2
  module RailsBestPractices
6
3
  module Reviews
7
4
  # A Review class that takes charge of reviewing one rails best practice.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a controller file to make sure using simplified syntax for render.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a view file to make sure using simplified syntax for render.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a controller file to make sure to use before_filter to remove duplicated first code
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # review a controller file to make sure to use model association instead of foreign key id assignment.
@@ -1,7 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/core/runner'
3
- require 'rails_best_practices/reviews/review'
4
-
5
2
  module RailsBestPractices
6
3
  module Reviews
7
4
  # Make sure to use multipart/alternative as content_type of email.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Make sure to use observer (sorry we only check the mailer deliver now).
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Check if method definition has parentheses around parameters.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Make sure to use query attribute instead of nil?, blank? and present?.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a migration file to make sure to use say or say_with_time for customized data changes
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Review a controller to make sure to use scope access instead of manually checking current_user and redirect.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/reviews/review'
3
-
4
2
  module RailsBestPractices
5
3
  module Reviews
6
4
  # Prepare Gemfile and review Capfile file to make sure using turbo-sprocket-rails3
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.13.8"
3
+ VERSION = "1.14.0"
4
4
  end
@@ -14,13 +14,14 @@ Gem::Specification.new do |s|
14
14
  s.required_ruby_version = ">= 1.9.0"
15
15
  s.required_rubygems_version = ">= 1.3.6"
16
16
 
17
+ s.add_dependency("activesupport")
18
+ s.add_dependency("awesome_print")
17
19
  s.add_dependency("code_analyzer")
18
- s.add_dependency("ruby-progressbar")
19
20
  s.add_dependency("colored")
20
21
  s.add_dependency("erubis")
21
22
  s.add_dependency("i18n")
22
- s.add_dependency("activesupport")
23
- s.add_dependency("awesome_print")
23
+ s.add_dependency("require_all")
24
+ s.add_dependency("ruby-progressbar")
24
25
 
25
26
  s.add_development_dependency("rake")
26
27
  s.add_development_dependency("rspec")
@@ -1,6 +1,7 @@
1
1
  AddModelVirtualAttributeCheck: { }
2
2
  AlwaysAddDbIndexCheck: { }
3
3
  #CheckSaveReturnValueCheck: { }
4
+ DefaultScopeIsEvilCheck: { }
4
5
  DryBundlerInCapistranoCheck: { }
5
6
  #HashSyntaxCheck: { }
6
7
  IsolateSeedDataCheck: { }
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe DefaultScopeIsEvilReview do
6
+ let(:runner) { Core::Runner.new(reviews: DefaultScopeIsEvilReview.new) }
7
+
8
+ it "should detect default_scope with -> syntax" do
9
+ content = <<-EOF
10
+ class User < ActiveRecord::Base
11
+ default_scope -> { order('created_at desc') }
12
+ end
13
+ EOF
14
+ runner.review('app/models/user.rb', content)
15
+ runner.should have(1).errors
16
+ runner.errors[0].to_s.should == "app/models/user.rb:2 - default_scope is evil"
17
+ end
18
+
19
+ it "should detect default_scope with old syntax" do
20
+ content = <<-EOF
21
+ class User < ActiveRecord::Base
22
+ default_scope order('created_at desc')
23
+ end
24
+ EOF
25
+ runner.review('app/models/user.rb', content)
26
+ runner.should have(1).errors
27
+ runner.errors[0].to_s.should == "app/models/user.rb:2 - default_scope is evil"
28
+ end
29
+
30
+ it "should not detect default_scope" do
31
+ content = <<-EOF
32
+ class User < ActiveRecord::Base
33
+ scope :default, -> { order('created_at desc') }
34
+ end
35
+ EOF
36
+ runner.review('app/models/user.rb', content)
37
+ runner.should have(0).errors
38
+ end
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.8
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: code_analyzer
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-progressbar
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: code_analyzer
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - '>='
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: activesupport
98
+ name: require_all
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - '>='
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: awesome_print
112
+ name: ruby-progressbar
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - '>='
@@ -238,6 +252,7 @@ files:
238
252
  - lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb
239
253
  - lib/rails_best_practices/reviews/always_add_db_index_review.rb
240
254
  - lib/rails_best_practices/reviews/check_save_return_value_review.rb
255
+ - lib/rails_best_practices/reviews/default_scope_is_evil_review.rb
241
256
  - lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb
242
257
  - lib/rails_best_practices/reviews/hash_syntax_review.rb
243
258
  - lib/rails_best_practices/reviews/isolate_seed_data_review.rb
@@ -310,6 +325,7 @@ files:
310
325
  - spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb
311
326
  - spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb
312
327
  - spec/rails_best_practices/reviews/check_save_return_value_spec.rb
328
+ - spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
313
329
  - spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb
314
330
  - spec/rails_best_practices/reviews/hash_syntax_review_spec.rb
315
331
  - spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb
@@ -420,6 +436,7 @@ test_files:
420
436
  - spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb
421
437
  - spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb
422
438
  - spec/rails_best_practices/reviews/check_save_return_value_spec.rb
439
+ - spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
423
440
  - spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb
424
441
  - spec/rails_best_practices/reviews/hash_syntax_review_spec.rb
425
442
  - spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb