rails_best_practices 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. data/.travis.yml +4 -1
  2. data/Gemfile +0 -3
  3. data/Gemfile.lock +10 -9
  4. data/README.md +2 -0
  5. data/lib/rails_best_practices/analyzer.rb +40 -21
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +12 -0
  8. data/lib/rails_best_practices/core/configs.rb +7 -0
  9. data/lib/rails_best_practices/core/error.rb +2 -1
  10. data/lib/rails_best_practices/core/routes.rb +11 -5
  11. data/lib/rails_best_practices/core/runner.rb +6 -2
  12. data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
  13. data/lib/rails_best_practices/prepares.rb +5 -0
  14. data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
  15. data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
  16. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
  17. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
  18. data/lib/rails_best_practices/version.rb +1 -1
  19. data/rails_best_practices.gemspec +1 -0
  20. data/spec/rails_best_practices/analyzer_spec.rb +52 -32
  21. data/spec/rails_best_practices/core/check_spec.rb +64 -45
  22. data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
  23. data/spec/rails_best_practices/core/configs_spec.rb +7 -0
  24. data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
  25. data/spec/rails_best_practices/core/error_spec.rb +28 -22
  26. data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
  27. data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
  28. data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
  29. data/spec/rails_best_practices/core/methods_spec.rb +37 -35
  30. data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
  31. data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
  32. data/spec/rails_best_practices/core/models_spec.rb +4 -2
  33. data/spec/rails_best_practices/core/modules_spec.rb +21 -19
  34. data/spec/rails_best_practices/core/nil_spec.rb +23 -21
  35. data/spec/rails_best_practices/core/routes_spec.rb +21 -14
  36. data/spec/rails_best_practices/core/runner_spec.rb +17 -15
  37. data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
  38. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
  39. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
  40. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
  41. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
  42. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
  43. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
  44. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
  45. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
  46. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
  47. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
  48. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
  49. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
  50. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
  51. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
  52. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
  53. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
  54. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
  55. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
  56. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
  57. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
  58. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
  59. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
  60. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
  61. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
  62. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
  63. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
  64. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
  65. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
  66. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
  67. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
  68. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
  69. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
  70. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
  71. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
  72. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
  73. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
  74. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
  75. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
  76. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
  77. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
  78. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
  79. data/spec/spec_helper.rb +11 -20
  80. metadata +42 -26
  81. data/.watchr.example +0 -65
@@ -19,16 +19,24 @@ module RailsBestPractices
19
19
  "http://rails-bestpractices.com/posts/148-protect-mass-assignment"
20
20
  end
21
21
 
22
- # check class node, grep all command nodes, if none of them is with message attr_accessible or attr_protected,
22
+ # check class node, grep all command nodes,
23
+ # if config.active_record.whitelist_attributes is not set true,
24
+ # and if none of them is with message attr_accessible or attr_protected,
25
+ # and if not use devise or authlogic,
23
26
  # then it should add attr_accessible or attr_protected to protect mass assignment.
24
27
  def start_class(node)
25
- if !rails_builtin?(node) && !devise?(node) && !authlogic?(node)
28
+ if !whitelist_attributes_config? && !rails_builtin?(node) && !devise?(node) && !authlogic?(node)
26
29
  add_error "protect mass assignment"
27
30
  end
28
31
  end
29
32
 
30
33
  private
34
+ def whitelist_attributes_config?
35
+ Prepares.configs["config.active_record.whitelist_attributes"] == "true"
36
+ end
37
+
31
38
  def rails_builtin?(node)
39
+ node.grep_node(:sexp_type => [:vcall, :var_ref], :to_s => "attr_accessible").present? ||
32
40
  node.grep_node(:sexp_type => :command, :message => %w(attr_accessible attr_protected)).present?
33
41
  end
34
42
 
@@ -37,7 +45,7 @@ module RailsBestPractices
37
45
  end
38
46
 
39
47
  def authlogic?(node)
40
- node.grep_node(:sexp_type => :vcall, :to_s => "acts_as_authentic").present? ||
48
+ node.grep_node(:sexp_type => [:vcall, :var_ref], :to_s => "acts_as_authentic").present? ||
41
49
  node.grep_node(:sexp_type => :fcall, :message => "acts_as_authentic").present?
42
50
  end
43
51
  end
@@ -94,9 +94,13 @@ module RailsBestPractices
94
94
 
95
95
  def internal_except_methods
96
96
  %w(
97
- initialize validate validate_each to_xml to_json assign_attributes after_find after_initialize
98
- before_save before_create before_update before_destroy after_save after_create after_update after_destroy
99
- to_param method_missing
97
+ initialize
98
+ validate validate_each validate_on_create validate_on_update
99
+ human_attribute_name
100
+ assign_attributes
101
+ to_xml to_json to_param
102
+ before_save before_create before_update before_destroy after_save after_create after_update after_destroy after_find after_initialize
103
+ method_missing
100
104
  ).map { |method_name| "*\##{method_name}" }
101
105
  end
102
106
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.9.0"
3
+ VERSION = "1.9.1"
4
4
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency("erubis")
20
20
  s.add_dependency("i18n")
21
21
  s.add_dependency("activesupport")
22
+ s.add_dependency("awesome_print")
22
23
 
23
24
  s.add_development_dependency("rake")
24
25
  s.add_development_dependency("rspec")
@@ -1,45 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Analyzer do
4
- subject { RailsBestPractices::Analyzer.new(".") }
3
+ module RailsBestPractices
4
+ describe Analyzer do
5
+ subject { Analyzer.new(".") }
5
6
 
6
- describe "expand_dirs_to_files" do
7
- it "should expand all files in spec directory" do
8
- dir = File.dirname(__FILE__)
9
- subject.expand_dirs_to_files(dir).should be_include(dir + '/analyzer_spec.rb')
7
+ describe "expand_dirs_to_files" do
8
+ it "should expand all files in spec directory" do
9
+ dir = File.dirname(__FILE__)
10
+ subject.expand_dirs_to_files(dir).should be_include(dir + '/analyzer_spec.rb')
11
+ end
10
12
  end
11
- end
12
13
 
13
- describe "file_sort" do
14
- it "should get models first, mailers, helpers and then others" do
15
- files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
16
- subject.file_sort(files).should == ["app/models/user.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/controllers/users_controller.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
14
+ describe "file_sort" do
15
+ it "should get models first, mailers, helpers and then others" do
16
+ files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
17
+ subject.file_sort(files).should == ["app/models/user.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/controllers/users_controller.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
18
+ end
17
19
  end
18
- end
19
20
 
20
- describe "file_ignore" do
21
- it "should ignore lib" do
22
- files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
23
- subject.file_ignore(files, 'lib/').should == ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim"]
21
+ describe "file_ignore" do
22
+ it "should ignore lib" do
23
+ files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
24
+ subject.file_ignore(files, 'lib/').should == ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim"]
25
+ end
24
26
  end
25
- end
26
27
 
27
- describe "output_terminal_errors" do
28
- it "should output errors in terminal" do
29
- check1 = RailsBestPractices::Reviews::LawOfDemeterReview.new
30
- check2 = RailsBestPractices::Reviews::UseQueryAttributeReview.new
31
- runner = RailsBestPractices::Core::Runner.new(:reviews => [check1, check2])
32
- check1.add_error "law of demeter", "app/models/user.rb", 10
33
- check2.add_error "use query attribute", "app/models/post.rb", 100
34
- subject.runner = runner
35
- subject.instance_variable_set("@options", {"without-color" => false})
28
+ describe "output_terminal_errors" do
29
+ it "should output errors in terminal" do
30
+ check1 = Reviews::LawOfDemeterReview.new
31
+ check2 = Reviews::UseQueryAttributeReview.new
32
+ runner = Core::Runner.new(:reviews => [check1, check2])
33
+ check1.add_error "law of demeter", "app/models/user.rb", 10
34
+ check2.add_error "use query attribute", "app/models/post.rb", 100
35
+ subject.runner = runner
36
+ subject.instance_variable_set("@options", {"without-color" => false})
37
+
38
+ $origin_stdout = $stdout
39
+ $stdout = StringIO.new
40
+ subject.output_terminal_errors
41
+ result = $stdout.string
42
+ $stdout = $origin_stdout
43
+ result.should == ["app/models/user.rb:10 - law of demeter".red, "app/models/post.rb:100 - use query attribute".red, "\nPlease go to http://rails-bestpractices.com to see more useful Rails Best Practices.".green, "\nFound 2 warnings.".red].join("\n") + "\n"
44
+ end
45
+ end
36
46
 
37
- $origin_stdout = $stdout
38
- $stdout = StringIO.new
39
- subject.output_terminal_errors
40
- result = $stdout.string
41
- $stdout = $origin_stdout
42
- result.should == ["app/models/user.rb:10 - law of demeter".red, "app/models/post.rb:100 - use query attribute".red, "\nPlease go to http://rails-bestpractices.com to see more useful Rails Best Practices.".green, "\nFound 2 warnings.".red].join("\n") + "\n"
47
+ describe "errors_filter_block" do
48
+ it "should call errors_filter_block after analyze" do
49
+ analyzer = Analyzer.new("path", "silent" => true)
50
+ analyzer.errors_filter_block = lambda { |errors| errors.each { |error| error.highlight = true } }
51
+ analyzer.stub(:expand_dirs_to_files).and_return([])
52
+ analyzer.stub(:file_sort).and_return([])
53
+ analyzer.stub(:file_ignore).and_return([])
54
+ analyzer.stub(:process)
55
+ runner = stub
56
+ runner.stub(:color=)
57
+ errors = [Core::Error.new, Core::Error.new]
58
+ Core::Runner.stub(:new).and_return(runner)
59
+ runner.stub(:errors).and_return(errors)
60
+ analyzer.analyze
61
+ analyzer.send(:errors).should be_all(&:highlight)
62
+ end
43
63
  end
44
64
  end
45
65
  end
@@ -1,63 +1,82 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Core::Check do
4
- let(:check) { RailsBestPractices::Core::Check.new }
3
+ module RailsBestPractices::Core
4
+ describe Check do
5
+ let(:check) { Check.new }
5
6
 
6
- it "should get empty interesting nodes" do
7
- check.interesting_nodes.should == []
8
- end
9
-
10
- it "should match none of interesting files" do
11
- check.interesting_files.should == []
12
- end
13
-
14
- context "node_start" do
15
- it "should call start_if" do
16
- node = stub(:sexp_type => :if)
17
- check.should_receive(:send).with("start_if", node)
18
- check.node_start(node)
7
+ it "should get empty interesting nodes" do
8
+ check.interesting_nodes.should == []
19
9
  end
20
10
 
21
- it "should call start_call" do
22
- node = stub(:sexp_type => :call)
23
- check.should_receive(:send).with("start_call", node)
24
- check.node_start(node)
11
+ it "should match none of interesting files" do
12
+ check.interesting_files.should == []
25
13
  end
26
- end
27
14
 
28
- context "node_end" do
29
- it "should call end_if" do
30
- node = stub(:sexp_type => :if)
31
- check.should_receive(:send).with("end_if", node)
32
- check.node_end(node)
15
+ context "node_start" do
16
+ it "should call start_if" do
17
+ node = stub(:sexp_type => :if)
18
+ check.should_receive(:send).with("start_if", node)
19
+ check.node_start(node)
20
+ end
21
+
22
+ it "should call start_call" do
23
+ node = stub(:sexp_type => :call)
24
+ check.should_receive(:send).with("start_call", node)
25
+ check.node_start(node)
26
+ end
27
+
28
+ it "should print node if debug mode" do
29
+ node = stub(:sexp_type => :call)
30
+ Check.class_eval { debug }
31
+ check.should_receive(:send).with("start_call", node)
32
+ check.should_receive(:ap).with(node)
33
+ check.node_start(node)
34
+ Check.class_eval { @debug = false }
35
+ end
33
36
  end
34
37
 
35
- it "should call end_call" do
36
- node = stub(:sexp_type => :call)
37
- check.should_receive(:send).with("end_call", node)
38
- check.node_end(node)
38
+ context "node_end" do
39
+ it "should call end_if" do
40
+ node = stub(:sexp_type => :if)
41
+ check.should_receive(:send).with("end_if", node)
42
+ check.node_end(node)
43
+ end
44
+
45
+ it "should call end_call" do
46
+ node = stub(:sexp_type => :call)
47
+ check.should_receive(:send).with("end_call", node)
48
+ check.node_end(node)
49
+ end
39
50
  end
40
- end
41
51
 
42
- context "callback" do
43
- it "should add callback to start_call" do
44
- execute = false
45
- check.class.add_callback "start_call" do
46
- execute = true
52
+ context "callback" do
53
+ it "should add callback to start_call" do
54
+ execute = false
55
+ check.class.add_callback "start_call" do
56
+ execute = true
57
+ end
58
+ node = stub(:sexp_type => :call)
59
+ check.node_start(node)
60
+ execute.should be_true
61
+ end
62
+
63
+ it "should ad callbacks to end_call" do
64
+ execute = false
65
+ check.class.add_callback "end_call" do
66
+ execute = true
67
+ end
68
+ node = stub(:sexp_type => :call)
69
+ check.node_end(node)
70
+ execute.should be_true
47
71
  end
48
- node = stub(:sexp_type => :call)
49
- check.node_start(node)
50
- execute.should be_true
51
72
  end
52
73
 
53
- it "should ad callbacks to end_call" do
54
- execute = false
55
- check.class.add_callback "end_call" do
56
- execute = true
74
+ context "debug" do
75
+ it "should be debug mode" do
76
+ Check.debug
77
+ Check.should be_debug
78
+ Check.class_eval { @debug = false }
57
79
  end
58
- node = stub(:sexp_type => :call)
59
- check.node_end(node)
60
- execute.should be_true
61
80
  end
62
81
  end
63
82
  end
@@ -1,78 +1,79 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- class TestLexical1
5
- end
6
- class TestLexical2
7
- end
8
- class TestPrepare1 < RailsBestPractices::Core::Check
9
- interesting_nodes :call
10
- interesting_files MODEL_FILES
11
- end
12
-
13
- class TestPrepare2 < RailsBestPractices::Core::Check
14
- interesting_nodes :class
15
- interesting_files MAILER_FILES
16
- end
17
-
18
- class TestReview1 < RailsBestPractices::Core::Check
19
- interesting_nodes :defn
20
- interesting_files CONTROLLER_FILES
21
- end
4
+ module RailsBestPractices::Core
22
5
 
23
- class TestReview2 < RailsBestPractices::Core::Check
24
- interesting_nodes :call
25
- interesting_files VIEW_FILES
26
- end
27
-
28
- describe RailsBestPractices::Core::CheckingVisitor do
29
- let(:lexical1) { TestLexical1.new }
30
- let(:lexical2) { TestLexical2.new }
31
- let(:prepare1) { TestPrepare1.new }
32
- let(:prepare2) { TestPrepare2.new }
33
- let(:review1) { TestReview1.new }
34
- let(:review2) { TestReview2.new }
35
- let(:visitor) {
36
- RailsBestPractices::Core::CheckingVisitor.new(
37
- :lexicals => [lexical1, lexical2],
38
- :prepares => [prepare1, prepare2],
39
- :reviews => [review1, review2]
40
- )
41
- }
42
-
43
- it "should lexical check" do
44
- filename = "app/models/user.rb"
45
- content = "class User; end"
46
- lexical1.should_receive(:check).with(filename, content)
47
- lexical2.should_receive(:check).with(filename, content)
48
- visitor.lexical(filename, content)
6
+ class TestLexical1; end
7
+ class TestLexical2; end
8
+ class TestPrepare1 < Check
9
+ interesting_nodes :call
10
+ interesting_files MODEL_FILES
49
11
  end
50
12
 
51
- it "should prepare model associations" do
52
- node = stub(:sexp_type => :call, :children => [], :file => "app/models/user.rb")
53
- prepare1.should_receive(:node_start).with(node)
54
- prepare1.should_receive(:node_end).with(node)
55
- visitor.prepare(node)
13
+ class TestPrepare2 < Check
14
+ interesting_nodes :class
15
+ interesting_files MAILER_FILES
56
16
  end
57
17
 
58
- it "should prepare mailer names" do
59
- node = stub(:sexp_type => :class, :children => [], :file => "app/mailers/user_mailer.rb")
60
- prepare2.should_receive(:node_start).with(node)
61
- prepare2.should_receive(:node_end).with(node)
62
- visitor.prepare(node)
18
+ class TestReview1 < Check
19
+ interesting_nodes :defn
20
+ interesting_files CONTROLLER_FILES
63
21
  end
64
22
 
65
- it "should review controller method definitions" do
66
- node = stub(:sexp_type => :defn, :children => [], :file => "app/controllers/users_controller.rb")
67
- review1.should_receive(:node_start).with(node)
68
- review1.should_receive(:node_end).with(node)
69
- visitor.review(node)
23
+ class TestReview2 < Check
24
+ interesting_nodes :call
25
+ interesting_files VIEW_FILES
70
26
  end
71
27
 
72
- it "should review view calls" do
73
- node = stub(:sexp_type => :call, :children => [], :file => "app/views/users/new.html.erb")
74
- review2.should_receive(:node_start).with(node)
75
- review2.should_receive(:node_end).with(node)
76
- visitor.review(node)
28
+ describe CheckingVisitor do
29
+ let(:lexical1) { TestLexical1.new }
30
+ let(:lexical2) { TestLexical2.new }
31
+ let(:prepare1) { TestPrepare1.new }
32
+ let(:prepare2) { TestPrepare2.new }
33
+ let(:review1) { TestReview1.new }
34
+ let(:review2) { TestReview2.new }
35
+ let(:visitor) {
36
+ CheckingVisitor.new(
37
+ :lexicals => [lexical1, lexical2],
38
+ :prepares => [prepare1, prepare2],
39
+ :reviews => [review1, review2]
40
+ )
41
+ }
42
+
43
+ it "should lexical check" do
44
+ filename = "app/models/user.rb"
45
+ content = "class User; end"
46
+ lexical1.should_receive(:check).with(filename, content)
47
+ lexical2.should_receive(:check).with(filename, content)
48
+ visitor.lexical(filename, content)
49
+ end
50
+
51
+ it "should prepare model associations" do
52
+ node = stub(:sexp_type => :call, :children => [], :file => "app/models/user.rb")
53
+ prepare1.should_receive(:node_start).with(node)
54
+ prepare1.should_receive(:node_end).with(node)
55
+ visitor.prepare(node)
56
+ end
57
+
58
+ it "should prepare mailer names" do
59
+ node = stub(:sexp_type => :class, :children => [], :file => "app/mailers/user_mailer.rb")
60
+ prepare2.should_receive(:node_start).with(node)
61
+ prepare2.should_receive(:node_end).with(node)
62
+ visitor.prepare(node)
63
+ end
64
+
65
+ it "should review controller method definitions" do
66
+ node = stub(:sexp_type => :defn, :children => [], :file => "app/controllers/users_controller.rb")
67
+ review1.should_receive(:node_start).with(node)
68
+ review1.should_receive(:node_end).with(node)
69
+ visitor.review(node)
70
+ end
71
+
72
+ it "should review view calls" do
73
+ node = stub(:sexp_type => :call, :children => [], :file => "app/views/users/new.html.erb")
74
+ review2.should_receive(:node_start).with(node)
75
+ review2.should_receive(:node_end).with(node)
76
+ visitor.review(node)
77
+ end
77
78
  end
78
79
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ module RailsBestPractices::Core
4
+ describe Configs do
5
+ it { should be_a_kind_of Hash }
6
+ end
7
+ end
@@ -1,5 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Core::Controllers do
4
- it { should be_a_kind_of RailsBestPractices::Core::Klasses }
3
+ module RailsBestPractices::Core
4
+ describe Controllers do
5
+ it { should be_a_kind_of Klasses }
6
+ end
5
7
  end