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.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +30 -26
- data/Guardfile +2 -0
- data/Rakefile +2 -0
- data/lib/rails_best_practices.rb +1 -2
- data/lib/rails_best_practices/analyzer.rb +56 -46
- data/lib/rails_best_practices/core/check.rb +39 -32
- data/lib/rails_best_practices/core/checks_loader.rb +8 -6
- data/lib/rails_best_practices/core/configs.rb +1 -2
- data/lib/rails_best_practices/core/controllers.rb +1 -2
- data/lib/rails_best_practices/core/error.rb +1 -1
- data/lib/rails_best_practices/core/helpers.rb +1 -2
- data/lib/rails_best_practices/core/mailers.rb +1 -2
- data/lib/rails_best_practices/core/methods.rb +21 -16
- data/lib/rails_best_practices/core/model_associations.rb +9 -4
- data/lib/rails_best_practices/core/models.rb +1 -2
- data/lib/rails_best_practices/core/modules.rb +1 -1
- data/lib/rails_best_practices/core/routes.rb +2 -2
- data/lib/rails_best_practices/core/runner.rb +29 -33
- data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
- data/lib/rails_best_practices/option_parser.rb +17 -6
- data/lib/rails_best_practices/prepares.rb +1 -1
- data/lib/rails_best_practices/prepares/controller_prepare.rb +15 -3
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
- data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -2
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -0
- data/lib/rails_best_practices/prepares/model_prepare.rb +52 -12
- data/lib/rails_best_practices/prepares/route_prepare.rb +16 -10
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +15 -13
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +34 -29
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +14 -5
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +19 -8
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +5 -5
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +4 -4
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +7 -8
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +6 -6
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +6 -7
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +7 -8
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +12 -10
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +5 -5
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +5 -2
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +6 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -4
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +29 -9
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +3 -3
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +17 -15
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -2
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -3
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +5 -5
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +9 -8
- data/lib/rails_best_practices/reviews/use_observer_review.rb +9 -9
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +26 -26
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +8 -7
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +17 -15
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +35 -36
- data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
- data/spec/rails_best_practices/analyzer_spec.rb +73 -42
- data/spec/rails_best_practices/core/check_spec.rb +5 -5
- data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
- data/spec/rails_best_practices/core/configs_spec.rb +1 -1
- data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
- data/spec/rails_best_practices/core/error_spec.rb +21 -21
- data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
- data/spec/rails_best_practices/core/gems_spec.rb +4 -4
- data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
- data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
- data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
- data/spec/rails_best_practices/core/methods_spec.rb +6 -6
- data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
- data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
- data/spec/rails_best_practices/core/models_spec.rb +1 -1
- data/spec/rails_best_practices/core/modules_spec.rb +5 -5
- data/spec/rails_best_practices/core/routes_spec.rb +5 -5
- data/spec/rails_best_practices/core/runner_spec.rb +9 -7
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +11 -10
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +138 -77
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +21 -14
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +26 -16
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -19
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +44 -31
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +17 -12
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +46 -44
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -10
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +21 -17
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +10 -8
- 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) {
|
7
|
+
let(:check) { described_class.new }
|
8
8
|
|
9
9
|
context 'debug' do
|
10
|
-
it '
|
11
|
-
|
12
|
-
expect(
|
13
|
-
|
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) {
|
7
|
+
let(:checks_loader) { described_class.new(RailsBestPractices::Analyzer::DEFAULT_CONFIG) }
|
8
8
|
|
9
9
|
describe 'load_lexicals' do
|
10
|
-
it '
|
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 '
|
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,32 +4,32 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module RailsBestPractices::Core
|
6
6
|
describe Error do
|
7
|
-
it '
|
8
|
-
expect(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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 '
|
15
|
+
it 'returns short filename' do
|
17
16
|
Runner.base_path = '../rails-bestpractices.com'
|
18
|
-
expect(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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 '
|
27
|
-
expect(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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 {
|
7
|
+
it { is_expected.to be_a_kind_of Array }
|
8
8
|
|
9
|
-
let(:gems) {
|
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
|
-
|
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
|
-
|
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,10 +4,10 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module RailsBestPractices::Core
|
6
6
|
describe Klasses do
|
7
|
-
it {
|
7
|
+
it { is_expected.to be_a_kind_of Array }
|
8
8
|
|
9
9
|
context 'Klass' do
|
10
|
-
|
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
|
-
|
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,9 +4,9 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module RailsBestPractices::Core
|
6
6
|
describe Methods do
|
7
|
-
let(:methods) {
|
7
|
+
let(:methods) { described_class.new }
|
8
8
|
|
9
|
-
before
|
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 '
|
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 '
|
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 '
|
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 '
|
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) {
|
7
|
+
let(:model_associations) { described_class.new }
|
8
8
|
|
9
|
-
before
|
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 '
|
15
|
-
expect(model_associations.get_association('Project', 'project_manager')).to eq(
|
16
|
-
|
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 '
|
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) {
|
7
|
+
let(:model_attributes) { described_class.new }
|
8
8
|
|
9
|
-
before
|
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 '
|
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 '
|
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,25 +4,25 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module RailsBestPractices::Core
|
6
6
|
describe Modules do
|
7
|
-
it {
|
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 {
|
14
|
-
it '
|
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) {
|
7
|
+
let(:routes) { described_class.new }
|
8
8
|
|
9
|
-
it '
|
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 '
|
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 '
|
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 '
|
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 '
|
10
|
-
runner =
|
11
|
-
expect(runner.instance_variable_get('@reviews').map(&:class)).to include(
|
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 {
|
17
|
-
|
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 {
|
22
|
-
|
23
|
+
before { described_class.base_path = 'spec/fixtures' }
|
24
|
+
it_behaves_like 'load_plugin_reviews'
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|