rails_best_practices 1.20.0 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +30 -26
  4. data/Guardfile +2 -0
  5. data/Rakefile +2 -0
  6. data/lib/rails_best_practices.rb +1 -2
  7. data/lib/rails_best_practices/analyzer.rb +56 -46
  8. data/lib/rails_best_practices/core/check.rb +39 -32
  9. data/lib/rails_best_practices/core/checks_loader.rb +8 -6
  10. data/lib/rails_best_practices/core/configs.rb +1 -2
  11. data/lib/rails_best_practices/core/controllers.rb +1 -2
  12. data/lib/rails_best_practices/core/error.rb +1 -1
  13. data/lib/rails_best_practices/core/helpers.rb +1 -2
  14. data/lib/rails_best_practices/core/mailers.rb +1 -2
  15. data/lib/rails_best_practices/core/methods.rb +21 -16
  16. data/lib/rails_best_practices/core/model_associations.rb +9 -4
  17. data/lib/rails_best_practices/core/models.rb +1 -2
  18. data/lib/rails_best_practices/core/modules.rb +1 -1
  19. data/lib/rails_best_practices/core/routes.rb +2 -2
  20. data/lib/rails_best_practices/core/runner.rb +29 -33
  21. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  22. data/lib/rails_best_practices/option_parser.rb +17 -6
  23. data/lib/rails_best_practices/prepares.rb +1 -1
  24. data/lib/rails_best_practices/prepares/controller_prepare.rb +15 -3
  25. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
  26. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  27. data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -2
  28. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -0
  29. data/lib/rails_best_practices/prepares/model_prepare.rb +52 -12
  30. data/lib/rails_best_practices/prepares/route_prepare.rb +16 -10
  31. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +15 -13
  32. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +34 -29
  33. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +14 -5
  34. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +19 -8
  35. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +5 -5
  36. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +4 -4
  37. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +7 -8
  38. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +6 -6
  39. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +6 -7
  41. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +7 -8
  42. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +12 -10
  43. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +5 -5
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +5 -2
  46. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +6 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -4
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +29 -9
  49. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +3 -3
  50. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +17 -15
  51. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -2
  52. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -3
  53. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -1
  54. data/lib/rails_best_practices/reviews/use_model_association_review.rb +5 -5
  55. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +9 -8
  56. data/lib/rails_best_practices/reviews/use_observer_review.rb +9 -9
  57. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +26 -26
  58. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +8 -7
  59. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +17 -15
  60. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  61. data/lib/rails_best_practices/version.rb +1 -1
  62. data/rails_best_practices.gemspec +35 -36
  63. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  64. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  65. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  66. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  67. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  68. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  69. data/spec/rails_best_practices/core/error_spec.rb +21 -21
  70. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  71. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  72. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  73. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  74. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  75. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  76. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  77. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  78. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  79. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  80. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  82. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  83. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +11 -10
  84. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  85. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  86. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  87. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  88. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +2 -2
  89. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  90. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  91. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  92. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  93. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +138 -77
  94. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  95. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  96. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  97. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  98. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  99. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  100. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  101. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  103. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  104. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +21 -14
  105. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  106. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  107. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +26 -16
  108. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  109. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  110. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  111. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  112. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  113. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  114. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  115. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -19
  116. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +44 -31
  118. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +17 -12
  119. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +46 -44
  120. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  121. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -10
  122. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  123. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  124. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  125. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  126. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  127. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +21 -17
  128. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  129. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +9 -7
  130. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  131. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  132. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  133. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +10 -8
  134. metadata +7 -7
@@ -4,13 +4,13 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Check do
7
- let(:check) { Check.new }
7
+ let(:check) { described_class.new }
8
8
 
9
9
  context 'debug' do
10
- it 'should be debug mode' do
11
- Check.debug
12
- expect(Check).to be_debug
13
- Check.class_eval { @debug = false }
10
+ it 'is debug mode' do
11
+ described_class.debug
12
+ expect(described_class).to be_debug
13
+ described_class.class_eval { @debug = false }
14
14
  end
15
15
  end
16
16
  end
@@ -4,17 +4,17 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe ChecksLoader do
7
- let(:checks_loader) { ChecksLoader.new(RailsBestPractices::Analyzer::DEFAULT_CONFIG) }
7
+ let(:checks_loader) { described_class.new(RailsBestPractices::Analyzer::DEFAULT_CONFIG) }
8
8
 
9
9
  describe 'load_lexicals' do
10
- it 'should load lexical checks from the default configuration' do
10
+ it 'loads lexical checks from the default configuration' do
11
11
  lexicals = checks_loader.load_lexicals
12
12
  expect(lexicals.map(&:class)).to include(RailsBestPractices::Lexicals::RemoveTrailingWhitespaceCheck)
13
13
  end
14
14
  end
15
15
 
16
16
  describe 'load_reviews' do
17
- it 'should load the reviews from the default the configuration' do
17
+ it 'loads the reviews from the default the configuration' do
18
18
  reviews = checks_loader.load_reviews
19
19
  expect(reviews.map(&:class)).to include(RailsBestPractices::Reviews::AlwaysAddDbIndexReview)
20
20
  end
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Configs do
7
- it { should be_a_kind_of Hash }
7
+ it { is_expected.to be_a_kind_of Hash }
8
8
  end
9
9
  end
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Controllers do
7
- it { should be_a_kind_of Klasses }
7
+ it { is_expected.to be_a_kind_of Klasses }
8
8
  end
9
9
  end
@@ -4,32 +4,32 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Error do
7
- it 'should return error with filename, line number and message' do
8
- expect(Error.new(
9
- filename: 'app/models/user.rb',
10
- line_number: '100',
11
- message: 'not good',
12
- type: 'BogusReview'
13
- ).to_s).to eq('app/models/user.rb:100 - not good')
7
+ it 'returns error with filename, line number and message' do
8
+ expect(
9
+ described_class.new(
10
+ filename: 'app/models/user.rb', line_number: '100', message: 'not good', type: 'BogusReview'
11
+ ).to_s
12
+ ).to eq('app/models/user.rb:100 - not good')
14
13
  end
15
14
 
16
- it 'should return short filename' do
15
+ it 'returns short filename' do
17
16
  Runner.base_path = '../rails-bestpractices.com'
18
- expect(Error.new(
19
- filename: '../rails-bestpractices.com/app/models/user.rb',
20
- line_number: '100',
21
- message: 'not good',
22
- type: 'BogusReview'
23
- ).short_filename).to eq('app/models/user.rb')
17
+ expect(
18
+ described_class.new(
19
+ filename: '../rails-bestpractices.com/app/models/user.rb',
20
+ line_number: '100',
21
+ message: 'not good',
22
+ type: 'BogusReview'
23
+ ).short_filename
24
+ ).to eq('app/models/user.rb')
24
25
  end
25
26
 
26
- it 'should return first line number' do
27
- expect(Error.new(
28
- filename: 'app/models/user.rb',
29
- line_number: '50,70,100',
30
- message: 'not good',
31
- type: 'BogusReview'
32
- ).first_line_number).to eq('50')
27
+ it 'returns first line number' do
28
+ expect(
29
+ described_class.new(
30
+ filename: 'app/models/user.rb', line_number: '50,70,100', message: 'not good', type: 'BogusReview'
31
+ ).first_line_number
32
+ ).to eq('50')
33
33
  end
34
34
  end
35
35
  end
@@ -10,7 +10,7 @@ module RailsBestPractices::Core
10
10
  let(:except_method) { '*#*' }
11
11
 
12
12
  it 'matches' do
13
- expect(Check::Exceptable.matches(method, except_method)).to eql true
13
+ expect(described_class.matches(method, except_method)).to eql true
14
14
  end
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ module RailsBestPractices::Core
18
18
  let(:except_method) { '*#approve' }
19
19
 
20
20
  it 'matches' do
21
- expect(Check::Exceptable.matches(method, except_method)).to eql true
21
+ expect(described_class.matches(method, except_method)).to eql true
22
22
  end
23
23
  end
24
24
 
@@ -26,7 +26,7 @@ module RailsBestPractices::Core
26
26
  let(:except_method) { '*#disapprove' }
27
27
 
28
28
  it 'matches' do
29
- expect(Check::Exceptable.matches(method, except_method)).to eql false
29
+ expect(described_class.matches(method, except_method)).to eql false
30
30
  end
31
31
  end
32
32
 
@@ -34,7 +34,7 @@ module RailsBestPractices::Core
34
34
  let(:except_method) { 'BlogPost#*' }
35
35
 
36
36
  it 'matches' do
37
- expect(Check::Exceptable.matches(method, except_method)).to eql true
37
+ expect(described_class.matches(method, except_method)).to eql true
38
38
  end
39
39
  end
40
40
 
@@ -42,7 +42,7 @@ module RailsBestPractices::Core
42
42
  let(:except_method) { 'User#*' }
43
43
 
44
44
  it 'matches' do
45
- expect(Check::Exceptable.matches(method, except_method)).to eql false
45
+ expect(described_class.matches(method, except_method)).to eql false
46
46
  end
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ module RailsBestPractices::Core
50
50
  let(:except_method) { 'BlogPost#approve' }
51
51
 
52
52
  it 'matches' do
53
- expect(Check::Exceptable.matches(method, except_method)).to eql true
53
+ expect(described_class.matches(method, except_method)).to eql true
54
54
  end
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ module RailsBestPractices::Core
58
58
  let(:except_method) { 'User#disapprove' }
59
59
 
60
60
  it 'matches' do
61
- expect(Check::Exceptable.matches(method, except_method)).to eql false
61
+ expect(described_class.matches(method, except_method)).to eql false
62
62
  end
63
63
  end
64
64
  end
@@ -4,15 +4,15 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Gems do
7
- it { should be_a_kind_of Array }
7
+ it { is_expected.to be_a_kind_of Array }
8
8
 
9
- let(:gems) { Gems.new }
9
+ let(:gems) { described_class.new }
10
10
  before do
11
11
  gems << Gem.new('rails', '4.0.0')
12
12
  gems << Gem.new('mysql2', '0.2.0')
13
13
  end
14
14
 
15
- context '#has_gem?' do
15
+ describe '#has_gem?' do
16
16
  it 'has rails gem' do
17
17
  expect(gems).to be_has_gem 'rails'
18
18
  end
@@ -22,7 +22,7 @@ module RailsBestPractices::Core
22
22
  end
23
23
  end
24
24
 
25
- context '#gem_version' do
25
+ describe '#gem_version' do
26
26
  it 'gets rails version' do
27
27
  expect(gems.gem_version('rails')).to eq '4.0.0'
28
28
  end
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Helpers do
7
- it { should be_a_kind_of Modules }
7
+ it { is_expected.to be_a_kind_of Modules }
8
8
  end
9
9
  end
@@ -4,10 +4,10 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Klasses do
7
- it { should be_a_kind_of Array }
7
+ it { is_expected.to be_a_kind_of Array }
8
8
 
9
9
  context 'Klass' do
10
- context '#class_name' do
10
+ describe '#class_name' do
11
11
  it 'gets class name without module' do
12
12
  klass = Klass.new('BlogPost', 'Post', [])
13
13
  expect(klass.class_name).to eq('BlogPost')
@@ -19,7 +19,7 @@ module RailsBestPractices::Core
19
19
  end
20
20
  end
21
21
 
22
- context '#extend_class_name' do
22
+ describe '#extend_class_name' do
23
23
  it 'gets extend class name without module' do
24
24
  klass = Klass.new('BlogPost', 'Post', [])
25
25
  expect(klass.extend_class_name).to eq('Post')
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Mailers do
7
- it { should be_a_kind_of Klasses }
7
+ it { is_expected.to be_a_kind_of Klasses }
8
8
  end
9
9
  end
@@ -4,9 +4,9 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Methods do
7
- let(:methods) { Methods.new }
7
+ let(:methods) { described_class.new }
8
8
 
9
- before :each do
9
+ before do
10
10
  methods.add_method('Post', 'create')
11
11
  methods.add_method('Post', 'destroy')
12
12
  methods.add_method('Post', 'save_or_update', {}, 'protected')
@@ -14,7 +14,7 @@ module RailsBestPractices::Core
14
14
  methods.add_method('Comment', 'create')
15
15
  end
16
16
 
17
- it 'should get_methods' do
17
+ it 'get_methodses' do
18
18
  expect(methods.get_methods('Post').map(&:method_name)).to eq(%w[create destroy save_or_update find_by_sql])
19
19
  expect(methods.get_methods('Post', 'public').map(&:method_name)).to eq(%w[create destroy])
20
20
  expect(methods.get_methods('Post', 'protected').map(&:method_name)).to eq(['save_or_update'])
@@ -22,7 +22,7 @@ module RailsBestPractices::Core
22
22
  expect(methods.get_methods('Comment').map(&:method_name)).to eq(['create'])
23
23
  end
24
24
 
25
- it 'should has_method?' do
25
+ it 'has_method?s' do
26
26
  expect(methods).to be_has_method('Post', 'create', 'public')
27
27
  expect(methods).to be_has_method('Post', 'destroy', 'public')
28
28
  expect(methods).not_to be_has_method('Post', 'save_or_update', 'public')
@@ -32,12 +32,12 @@ module RailsBestPractices::Core
32
32
  expect(methods).not_to be_has_method('Comment', 'destroy')
33
33
  end
34
34
 
35
- it 'should get_method' do
35
+ it 'get_methods' do
36
36
  expect(methods.get_method('Post', 'create', 'public')).not_to be_nil
37
37
  expect(methods.get_method('Post', 'create', 'protected')).to be_nil
38
38
  end
39
39
 
40
- it 'should get_all_unused_methods' do
40
+ it 'get_all_unused_methodses' do
41
41
  methods.get_method('Comment', 'create').mark_used
42
42
  expect(methods.get_all_unused_methods('public').map(&:method_name)).to eq(%w[create destroy])
43
43
  expect(methods.get_all_unused_methods('protected').map(&:method_name)).to eq(['save_or_update'])
@@ -4,20 +4,24 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe ModelAssociations do
7
- let(:model_associations) { ModelAssociations.new }
7
+ let(:model_associations) { described_class.new }
8
8
 
9
- before :each do
9
+ before do
10
10
  model_associations.add_association('Project', 'project_manager', 'belongs_to')
11
11
  model_associations.add_association('Project', 'people', 'has_many', 'Person')
12
12
  end
13
13
 
14
- it 'should get model associations' do
15
- expect(model_associations.get_association('Project', 'project_manager')).to eq('meta' => 'belongs_to', 'class_name' => 'ProjectManager')
16
- expect(model_associations.get_association('Project', 'people')).to eq('meta' => 'has_many', 'class_name' => 'Person')
14
+ it 'gets model associations' do
15
+ expect(model_associations.get_association('Project', 'project_manager')).to eq(
16
+ 'meta' => 'belongs_to', 'class_name' => 'ProjectManager'
17
+ )
18
+ expect(model_associations.get_association('Project', 'people')).to eq(
19
+ 'meta' => 'has_many', 'class_name' => 'Person'
20
+ )
17
21
  expect(model_associations.get_association('Project', 'unknown')).to be_nil
18
22
  end
19
23
 
20
- it 'should check is model associatiosn' do
24
+ it 'checks is model associatiosn' do
21
25
  expect(model_associations.is_association?('Project', 'project_manager')).to eq true
22
26
  expect(model_associations.is_association?('Project', 'people')).to eq true
23
27
  expect(model_associations.is_association?('Project', 'unknown')).to eq false
@@ -4,20 +4,20 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe ModelAttributes do
7
- let(:model_attributes) { ModelAttributes.new }
7
+ let(:model_attributes) { described_class.new }
8
8
 
9
- before :each do
9
+ before do
10
10
  model_attributes.add_attribute('Post', 'title', :string)
11
11
  model_attributes.add_attribute('Post', 'user_id', :integer)
12
12
  end
13
13
 
14
- it 'should get model attributes' do
14
+ it 'gets model attributes' do
15
15
  expect(model_attributes.get_attribute_type('Post', 'title')).to eq(:string)
16
16
  expect(model_attributes.get_attribute_type('Post', 'user_id')).to eq(:integer)
17
17
  expect(model_attributes.get_attribute_type('Post', 'unknonw')).to be_nil
18
18
  end
19
19
 
20
- it 'should check is model attributes' do
20
+ it 'checks is model attributes' do
21
21
  expect(model_attributes.is_attribute?('Post', 'title')).to be true
22
22
  expect(model_attributes.is_attribute?('Post', 'user_id')).to be true
23
23
  expect(model_attributes.is_attribute?('Post', 'unknonw')).to be false
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Models do
7
- it { should be_a_kind_of Klasses }
7
+ it { is_expected.to be_a_kind_of Klasses }
8
8
  end
9
9
  end
@@ -4,25 +4,25 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Modules do
7
- it { should be_a_kind_of Array }
7
+ it { is_expected.to be_a_kind_of Array }
8
8
 
9
9
  context 'Modules' do
10
10
  before do
11
11
  @mod = Mod.new('PostsHelper', [])
12
12
  end
13
- subject { Modules.new.tap { |modules| modules << @mod } }
14
- it 'should add descendant to the corresponding module' do
13
+ subject { described_class.new.tap { |modules| modules << @mod } }
14
+ it 'adds descendant to the corresponding module' do
15
15
  expect(@mod).to receive(:add_descendant).with('PostsController')
16
16
  subject.add_module_descendant('PostsHelper', 'PostsController')
17
17
  end
18
18
  end
19
19
 
20
20
  context 'Mod' do
21
- subject {
21
+ subject do
22
22
  Mod.new('UsersHelper', ['Admin']).tap do |mod|
23
23
  mod.add_descendant('Admin::UsersController')
24
24
  end
25
- }
25
+ end
26
26
  it { expect(subject.to_s).to eq('Admin::UsersHelper') }
27
27
  it { expect(subject.descendants).to eq(['Admin::UsersController']) }
28
28
  end
@@ -4,25 +4,25 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Routes do
7
- let(:routes) { Routes.new }
7
+ let(:routes) { described_class.new }
8
8
 
9
- it 'should add route' do
9
+ it 'adds route' do
10
10
  routes.add_route(%w[admin test], 'posts', 'new')
11
11
  expect(routes.map(&:to_s)).to eq(['Admin::Test::PostsController#new'])
12
12
  end
13
13
 
14
14
  context 'route' do
15
- it 'should add namesapces, controller name and action name' do
15
+ it 'adds namesapces, controller name and action name' do
16
16
  route = Route.new(%w[admin test], 'posts', 'new')
17
17
  expect(route.to_s).to eq('Admin::Test::PostsController#new')
18
18
  end
19
19
 
20
- it 'should add controller name with namespace' do
20
+ it 'adds controller name with namespace' do
21
21
  route = Route.new(['admin'], 'test/posts', 'new')
22
22
  expect(route.to_s).to eq('Admin::Test::PostsController#new')
23
23
  end
24
24
 
25
- it 'should add routes without controller' do
25
+ it 'adds routes without controller' do
26
26
  route = Route.new(['posts'], nil, 'new')
27
27
  expect(route.to_s).to eq('PostsController#new')
28
28
  end
@@ -6,20 +6,22 @@ module RailsBestPractices::Core
6
6
  describe Runner do
7
7
  describe 'load_plugin_reviews' do
8
8
  shared_examples_for 'load_plugin_reviews' do
9
- it 'should load plugins in lib/rails_best_practices/plugins/reviews' do
10
- runner = Runner.new
11
- expect(runner.instance_variable_get('@reviews').map(&:class)).to include(RailsBestPractices::Plugins::Reviews::NotUseRailsRootReview)
9
+ it 'loads plugins in lib/rails_best_practices/plugins/reviews' do
10
+ runner = described_class.new
11
+ expect(runner.instance_variable_get('@reviews').map(&:class)).to include(
12
+ RailsBestPractices::Plugins::Reviews::NotUseRailsRootReview
13
+ )
12
14
  end
13
15
  end
14
16
 
15
17
  context 'given a path that ends with a slash' do
16
- before { Runner.base_path = 'spec/fixtures/' }
17
- it_should_behave_like 'load_plugin_reviews'
18
+ before { described_class.base_path = 'spec/fixtures/' }
19
+ it_behaves_like 'load_plugin_reviews'
18
20
  end
19
21
 
20
22
  context 'given a path that does not end with a slash' do
21
- before { Runner.base_path = 'spec/fixtures' }
22
- it_should_behave_like 'load_plugin_reviews'
23
+ before { described_class.base_path = 'spec/fixtures' }
24
+ it_behaves_like 'load_plugin_reviews'
23
25
  end
24
26
  end
25
27
  end