rails_best_practices 1.19.3 → 1.19.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +0 -4
  5. data/Gemfile.lock +120 -0
  6. data/README.md +4 -1
  7. data/lib/rails_best_practices.rb +2 -0
  8. data/lib/rails_best_practices/analyzer.rb +5 -4
  9. data/lib/rails_best_practices/cli.rb +22 -0
  10. data/lib/rails_best_practices/command.rb +1 -131
  11. data/lib/rails_best_practices/core/check.rb +24 -23
  12. data/lib/rails_best_practices/core/checks_loader.rb +17 -18
  13. data/lib/rails_best_practices/core/methods.rb +9 -8
  14. data/lib/rails_best_practices/core/model_associations.rb +1 -1
  15. data/lib/rails_best_practices/core/runner.rb +38 -38
  16. data/lib/rails_best_practices/option_parser.rb +140 -0
  17. data/lib/rails_best_practices/prepares/controller_prepare.rb +8 -14
  18. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
  19. data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
  20. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -1
  21. data/lib/rails_best_practices/prepares/model_prepare.rb +13 -13
  22. data/lib/rails_best_practices/prepares/route_prepare.rb +16 -15
  23. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  24. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +25 -23
  25. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +73 -72
  26. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +2 -1
  27. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +4 -3
  28. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
  29. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
  30. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +11 -11
  31. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +8 -8
  32. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +5 -5
  33. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +20 -19
  34. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -3
  35. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +5 -5
  36. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +5 -5
  37. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +13 -13
  38. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
  39. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -2
  40. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
  41. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -3
  42. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +32 -32
  43. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
  44. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +14 -14
  45. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -6
  46. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +15 -15
  47. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +8 -8
  48. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +71 -70
  49. data/lib/rails_best_practices/reviews/review.rb +2 -1
  50. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -1
  51. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +11 -11
  52. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +12 -9
  53. data/lib/rails_best_practices/reviews/use_model_association_review.rb +10 -10
  54. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +14 -13
  55. data/lib/rails_best_practices/reviews/use_observer_review.rb +20 -20
  56. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
  57. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +44 -41
  58. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +7 -7
  59. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +14 -14
  60. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +1 -1
  61. data/lib/rails_best_practices/version.rb +1 -1
  62. data/rails_best_practices.gemspec +8 -8
  63. data/spec/rails_best_practices/analyzer_spec.rb +4 -4
  64. data/spec/rails_best_practices/core/error_spec.rb +6 -3
  65. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +21 -21
  66. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +15 -15
  67. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +17 -15
  68. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +4 -4
  69. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +8 -8
  70. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +6 -6
  71. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +4 -2
  72. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +6 -4
  73. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +8 -6
  74. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +16 -14
  75. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +4 -4
  76. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +14 -14
  77. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +1 -1
  78. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +51 -51
  79. metadata +5 -2
@@ -21,13 +21,13 @@ module RailsBestPractices
21
21
 
22
22
  protected
23
23
 
24
- def no_parentheses_around_parameters?(def_node)
25
- :parent != def_node[2][0]
26
- end
24
+ def no_parentheses_around_parameters?(def_node)
25
+ def_node[2][0] != :parent
26
+ end
27
27
 
28
- def has_parameters?(def_node)
29
- :params == def_node[2][0] && !def_node[2][1..-1].compact.empty?
30
- end
28
+ def has_parameters?(def_node)
29
+ def_node[2][0] == :params && !def_node[2][1..-1].compact.empty?
30
+ end
31
31
  end
32
32
  end
33
33
  end
@@ -35,12 +35,13 @@ module RailsBestPractices
35
35
  # then the call node can use query attribute instead.
36
36
  add_callback :start_if, :start_unless, :start_elsif, :start_ifop, :start_if_mod, :start_unless_mod do |node|
37
37
  all_conditions = if node.conditional_statement == node.conditional_statement.all_conditions
38
- [node.conditional_statement]
39
- else
40
- node.conditional_statement.all_conditions
38
+ [node.conditional_statement]
39
+ else
40
+ node.conditional_statement.all_conditions
41
41
  end
42
42
  all_conditions.each do |condition_node|
43
43
  next unless query_attribute_node = query_attribute_node(condition_node)
44
+
44
45
  receiver_node = query_attribute_node.receiver
45
46
  add_error "use query attribute (#{receiver_node.receiver}.#{receiver_node.message}?)",
46
47
  node.file,
@@ -52,23 +53,23 @@ module RailsBestPractices
52
53
 
53
54
  # recursively check conditional statement nodes to see if there is a call node that may be
54
55
  # possible query attribute.
55
- def query_attribute_node(conditional_statement_node)
56
- case conditional_statement_node.sexp_type
57
- when :and, :or
58
- node = query_attribute_node(conditional_statement_node[1]) ||
59
- query_attribute_node(conditional_statement_node[2])
60
- node.file = conditional_statement_code.file
61
- return node
62
- when :not
63
- node = query_attribute_node(conditional_statement_node[1])
64
- node.file = conditional_statement_node.file
65
- when :call
66
- return conditional_statement_node if possible_query_attribute?(conditional_statement_node)
67
- when :binary
68
- return conditional_statement_node if possible_query_attribute?(conditional_statement_node)
69
- end
70
- nil
56
+ def query_attribute_node(conditional_statement_node)
57
+ case conditional_statement_node.sexp_type
58
+ when :and, :or
59
+ node = query_attribute_node(conditional_statement_node[1]) ||
60
+ query_attribute_node(conditional_statement_node[2])
61
+ node.file = conditional_statement_code.file
62
+ return node
63
+ when :not
64
+ node = query_attribute_node(conditional_statement_node[1])
65
+ node.file = conditional_statement_node.file
66
+ when :call
67
+ return conditional_statement_node if possible_query_attribute?(conditional_statement_node)
68
+ when :binary
69
+ return conditional_statement_node if possible_query_attribute?(conditional_statement_node)
71
70
  end
71
+ nil
72
+ end
72
73
 
73
74
  # check if the node may use query attribute instead.
74
75
  #
@@ -81,36 +82,38 @@ module RailsBestPractices
81
82
  # it is compared with an empty string.
82
83
  #
83
84
  # the node that may use query attribute.
84
- def possible_query_attribute?(node)
85
- return false unless :call == node.receiver.sexp_type
86
- variable_node = variable(node)
87
- message_node = node.grep_node(receiver: variable_node.to_s).message
85
+ def possible_query_attribute?(node)
86
+ return false unless node.receiver.sexp_type == :call
88
87
 
89
- is_model?(variable_node) && model_attribute?(variable_node, message_node.to_s) &&
90
- (QUERY_METHODS.include?(node.message.to_s) || compare_with_empty_string?(node))
91
- end
88
+ variable_node = variable(node)
89
+ message_node = node.grep_node(receiver: variable_node.to_s).message
90
+
91
+ is_model?(variable_node) && model_attribute?(variable_node, message_node.to_s) &&
92
+ (QUERY_METHODS.include?(node.message.to_s) || compare_with_empty_string?(node))
93
+ end
92
94
 
93
95
  # check if the receiver is one of the models.
94
- def is_model?(variable_node)
95
- return false if variable_node.const?
96
- class_name = variable_node.to_s.sub(/^@/, '').classify
97
- models.include?(class_name)
98
- end
96
+ def is_model?(variable_node)
97
+ return false if variable_node.const?
98
+
99
+ class_name = variable_node.to_s.sub(/^@/, '').classify
100
+ models.include?(class_name)
101
+ end
99
102
 
100
103
  # check if the receiver and message is one of the model's attribute.
101
104
  # the receiver should match one of the class model name, and the message should match one of attribute name.
102
- def model_attribute?(variable_node, message)
103
- class_name = variable_node.to_s.sub(/^@/, '').classify
104
- attribute_type = model_attributes.get_attribute_type(class_name, message)
105
- attribute_type && !%w[integer float].include?(attribute_type)
106
- end
105
+ def model_attribute?(variable_node, message)
106
+ class_name = variable_node.to_s.sub(/^@/, '').classify
107
+ attribute_type = model_attributes.get_attribute_type(class_name, message)
108
+ attribute_type && !%w[integer float].include?(attribute_type)
109
+ end
107
110
 
108
111
  # check if the node is with node type :binary, node message :== and node argument is empty string.
109
- def compare_with_empty_string?(node)
110
- :binary == node.sexp_type &&
111
- ['==', '!='].include?(node.message.to_s) &&
112
- s(:string_literal, s(:string_content)) == node.argument
113
- end
112
+ def compare_with_empty_string?(node)
113
+ node.sexp_type == :binary &&
114
+ ['==', '!='].include?(node.message.to_s) &&
115
+ s(:string_literal, s(:string_content)) == node.argument
116
+ end
114
117
  end
115
118
  end
116
119
  end
@@ -31,14 +31,14 @@ module RailsBestPractices
31
31
  node.body.statements.each do |child_node|
32
32
  next if child_node.grep_nodes_count(sexp_type: %i[fcall command], message: WITH_SAY_METHODS) > 0
33
33
 
34
- receiver_node = if :method_add_block == child_node.sexp_type
35
- child_node[1]
36
- elsif :method_add_arg == child_node.sexp_type
37
- child_node[1]
38
- else
39
- child_node
34
+ receiver_node = if child_node.sexp_type == :method_add_block
35
+ child_node[1]
36
+ elsif child_node.sexp_type == :method_add_arg
37
+ child_node[1]
38
+ else
39
+ child_node
40
40
  end
41
- if :call == receiver_node.sexp_type
41
+ if receiver_node.sexp_type == :call
42
42
  add_error('use say with time in migrations', node.file, child_node.line_number)
43
43
  end
44
44
  end
@@ -35,23 +35,23 @@ module RailsBestPractices
35
35
  # if the conditional statement is compared with current_user or current_user.id,
36
36
  # and there is a redirect_to method call in the block body,
37
37
  # then it should be replaced by using scope access.
38
- def current_user_redirect?(node)
39
- all_conditions = if node.conditional_statement == node.conditional_statement.all_conditions
40
- [node.conditional_statement]
41
- else
42
- node.conditional_statement.all_conditions
43
- end
44
- results = all_conditions.map do |condition_node|
45
- ['==', '!='].include?(condition_node.message.to_s) &&
46
- (current_user?(condition_node.argument) || current_user?(condition_node.receiver))
47
- end
48
- results.any? { |result| result == true } && node.body.grep_node(message: 'redirect_to')
38
+ def current_user_redirect?(node)
39
+ all_conditions = if node.conditional_statement == node.conditional_statement.all_conditions
40
+ [node.conditional_statement]
41
+ else
42
+ node.conditional_statement.all_conditions
49
43
  end
44
+ results = all_conditions.map do |condition_node|
45
+ ['==', '!='].include?(condition_node.message.to_s) &&
46
+ (current_user?(condition_node.argument) || current_user?(condition_node.receiver))
47
+ end
48
+ results.any? { |result| result == true } && node.body.grep_node(message: 'redirect_to')
49
+ end
50
50
 
51
51
  # check a call node to see if it uses current_user, or current_user.id.
52
- def current_user?(node)
53
- 'current_user' == node.to_s || ('current_user' == node.receiver.to_s && 'id' == node.message.to_s)
54
- end
52
+ def current_user?(node)
53
+ node.to_s == 'current_user' || (node.receiver.to_s == 'current_user' && node.message.to_s == 'id')
54
+ end
55
55
  end
56
56
  end
57
57
  end
@@ -18,7 +18,7 @@ module RailsBestPractices
18
18
  # check command node to see if load 'deploy/assets'
19
19
  add_callback :start_command do |node|
20
20
  if Prepares.gems.gem_version('rails').to_i == 3
21
- if !Prepares.gems.has_gem?('turbo-sprockets-rails3') && 'load' == node.message.to_s && 'deploy/assets' == node.arguments.to_s
21
+ if !Prepares.gems.has_gem?('turbo-sprockets-rails3') && node.message.to_s == 'load' && node.arguments.to_s == 'deploy/assets'
22
22
  add_error 'speed up assets precompile with turbo-sprockets-rails3'
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBestPractices
4
- VERSION = '1.19.3'.freeze
4
+ VERSION = '1.19.4'
5
5
  end
@@ -37,19 +37,19 @@ Gem::Specification.new do |s|
37
37
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
38
38
  s.require_paths = %w[lib assets]
39
39
 
40
- s.post_install_message = <<-POST_INSTALL_MESSAGE
41
- #{'*' * 80}
40
+ s.post_install_message = <<~POST_INSTALL_MESSAGE
41
+ #{'*' * 80}
42
42
 
43
- rails_best_practices is a code metric tool to check the quality of rails codes.
43
+ rails_best_practices is a code metric tool to check the quality of rails codes.
44
44
 
45
- I highly recommend you browse the Rails Best Practices website first.
45
+ I highly recommend you browse the Rails Best Practices website first.
46
46
 
47
- http://rails-bestpractices.com
47
+ http://rails-bestpractices.com
48
48
 
49
- Enjoy!
49
+ Enjoy!
50
50
 
51
- Richard Huang (flyerhzm@gmail.com)
51
+ Richard Huang (flyerhzm@gmail.com)
52
52
 
53
- #{'*' * 80}
53
+ #{'*' * 80}
54
54
  POST_INSTALL_MESSAGE
55
55
  end
@@ -106,7 +106,8 @@ module RailsBestPractices
106
106
  "\e[31mapp/models/user.rb:10 - law of demeter\e[0m",
107
107
  "\e[31mapp/models/post.rb:100 - use query attribute\e[0m",
108
108
  "\e[32m\nPlease go to https://rails-bestpractices.com to see more useful Rails Best Practices.\e[0m",
109
- "\e[31m\nFound 2 warnings.\e[0m"].join("\n") + "\n")
109
+ "\e[31m\nFound 2 warnings.\e[0m"
110
+ ].join("\n") + "\n")
110
111
  end
111
112
  end
112
113
 
@@ -115,9 +116,8 @@ module RailsBestPractices
115
116
 
116
117
  subject do
117
118
  described_class.new('.',
118
- 'format' => 'json',
119
- 'output-file' => output_file
120
- )
119
+ 'format' => 'json',
120
+ 'output-file' => output_file)
121
121
  end
122
122
 
123
123
  let(:check1) { Reviews::LawOfDemeterReview.new }
@@ -9,7 +9,8 @@ module RailsBestPractices::Core
9
9
  filename: 'app/models/user.rb',
10
10
  line_number: '100',
11
11
  message: 'not good',
12
- type: 'BogusReview').to_s).to eq('app/models/user.rb:100 - not good')
12
+ type: 'BogusReview'
13
+ ).to_s).to eq('app/models/user.rb:100 - not good')
13
14
  end
14
15
 
15
16
  it 'should return short filename' do
@@ -18,7 +19,8 @@ module RailsBestPractices::Core
18
19
  filename: '../rails-bestpractices.com/app/models/user.rb',
19
20
  line_number: '100',
20
21
  message: 'not good',
21
- type: 'BogusReview').short_filename).to eq('app/models/user.rb')
22
+ type: 'BogusReview'
23
+ ).short_filename).to eq('app/models/user.rb')
22
24
  end
23
25
 
24
26
  it 'should return first line number' do
@@ -26,7 +28,8 @@ module RailsBestPractices::Core
26
28
  filename: 'app/models/user.rb',
27
29
  line_number: '50,70,100',
28
30
  message: 'not good',
29
- type: 'BogusReview').first_line_number).to eq('50')
31
+ type: 'BogusReview'
32
+ ).first_line_number).to eq('50')
30
33
  end
31
34
  end
32
35
  end
@@ -7,14 +7,14 @@ module RailsBestPractices
7
7
  describe LongLineCheck do
8
8
  it 'should find long lines' do
9
9
  runner = Core::Runner.new(lexicals: LongLineCheck.new)
10
- content = <<-EOF
11
- class User < ActiveRecord::Base
12
- # 81 Chars
13
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14
- # 80 Chars
15
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
16
- end
17
- EOF
10
+ content = <<~EOF
11
+ class User < ActiveRecord::Base
12
+ # 81 Chars
13
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14
+ # 80 Chars
15
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
16
+ end
17
+ EOF
18
18
  content = content.gsub("\n", "\t\n")
19
19
  runner.lexical('app/models/user.rb', content)
20
20
  expect(runner.errors.size).to eq(1)
@@ -22,14 +22,14 @@ EOF
22
22
  end
23
23
  it 'should find long lines with own max size' do
24
24
  runner = Core::Runner.new(lexicals: LongLineCheck.new('max_line_length' => 90))
25
- content = <<-EOF
26
- class User < ActiveRecord::Base
27
- # 91 Chars
28
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
29
- # 90 Chars
30
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
31
- end
32
- EOF
25
+ content = <<~EOF
26
+ class User < ActiveRecord::Base
27
+ # 91 Chars
28
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
29
+ # 90 Chars
30
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
31
+ end
32
+ EOF
33
33
  content = content.gsub("\n", "\t\n")
34
34
  runner.lexical('app/models/user.rb', content)
35
35
  expect(runner.errors.size).to eq(1)
@@ -45,11 +45,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
45
45
  end
46
46
  it 'should not check ignored files' do
47
47
  runner = Core::Runner.new(lexicals: LongLineCheck.new(max_line_length: 80, ignored_files: /user/))
48
- content = <<-EOF
49
- class User < ActiveRecord::Base
50
- # 81 Chars
51
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
52
- end
48
+ content = <<~EOF
49
+ class User < ActiveRecord::Base
50
+ # 81 Chars
51
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
52
+ end
53
53
  EOF
54
54
  content = content.gsub("\n", "\t\n")
55
55
  runner.lexical('app/models/user.rb', content)
@@ -9,22 +9,22 @@ module RailsBestPractices
9
9
 
10
10
  context 'gemfile' do
11
11
  it 'should parse gems' do
12
- content = <<-EOF
13
- GEM
14
- remote: https://rubygems.org/
15
- specs:
16
- rails (3.2.13)
17
- actionmailer (= 3.2.13)
18
- actionpack (= 3.2.13)
19
- activerecord (= 3.2.13)
20
- activeresource (= 3.2.13)
21
- activesupport (= 3.2.13)
22
- bundler (~> 1.0)
23
- railties (= 3.2.13)
24
- mysql2 (0.3.12b6)
12
+ content = <<~EOF
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ rails (3.2.13)
17
+ actionmailer (= 3.2.13)
18
+ actionpack (= 3.2.13)
19
+ activerecord (= 3.2.13)
20
+ activeresource (= 3.2.13)
21
+ activesupport (= 3.2.13)
22
+ bundler (~> 1.0)
23
+ railties (= 3.2.13)
24
+ mysql2 (0.3.12b6)
25
25
 
26
- PLATFORMS
27
- ruby
26
+ PLATFORMS
27
+ ruby
28
28
  EOF
29
29
  runner.prepare('Gemfile.lock', content)
30
30
  gems = Prepares.gems
@@ -105,10 +105,11 @@ module RailsBestPractices
105
105
  runner.prepare('config/routes.rb', content)
106
106
  routes = Prepares.routes
107
107
  expect(routes.map(&:to_s)).to eq([
108
- 'Admin::PostsController#edit',
109
- 'Admin::PostsController#update',
110
- 'Admin::PostsController#link_to_post',
111
- 'Admin::PostsController#extra_update'])
108
+ 'Admin::PostsController#edit',
109
+ 'Admin::PostsController#update',
110
+ 'Admin::PostsController#link_to_post',
111
+ 'Admin::PostsController#extra_update'
112
+ ])
112
113
  end
113
114
 
114
115
  it 'should add resources routes with members inline' do
@@ -124,11 +125,12 @@ module RailsBestPractices
124
125
  runner.prepare('config/routes.rb', content)
125
126
  routes = Prepares.routes
126
127
  expect(routes.map(&:to_s)).to eq([
127
- 'Admin::PostsController#edit',
128
- 'Admin::PostsController#update',
129
- 'Admin::PostsController#link_to_post',
130
- 'Admin::PostsController#extra_update',
131
- 'Admin::PostsController#retrieve'])
128
+ 'Admin::PostsController#edit',
129
+ 'Admin::PostsController#update',
130
+ 'Admin::PostsController#link_to_post',
131
+ 'Admin::PostsController#extra_update',
132
+ 'Admin::PostsController#retrieve'
133
+ ])
132
134
  end
133
135
 
134
136
  it 'should add connect route' do
@@ -338,12 +340,12 @@ module RailsBestPractices
338
340
  runner.prepare('config/routes.rb', content)
339
341
  routes = Prepares.routes
340
342
  expect(routes.map(&:to_s)).to eq([
341
- 'Admin::PostsController#index',
342
- 'Admin::DiscussionsController#index',
343
- 'CommentsController#index',
344
- 'UsersController#show',
345
- 'UsersController#preview'
346
- ])
343
+ 'Admin::PostsController#index',
344
+ 'Admin::DiscussionsController#index',
345
+ 'CommentsController#index',
346
+ 'UsersController#show',
347
+ 'UsersController#preview'
348
+ ])
347
349
  end
348
350
  end
349
351