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
@@ -1,41 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::MoveCodeIntoControllerReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoControllerReview.new) }
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe MoveCodeIntoControllerReview do
6
+ let(:runner) { Core::Runner.new(:reviews => MoveCodeIntoControllerReview.new) }
5
7
 
6
- it "should move code into controller for method call" do
7
- content = <<-EOF
8
- <% Post.find(:all).each do |post| %>
9
- <%=h post.title %>
10
- <%=h post.content %>
11
- <% end %>
12
- EOF
13
- runner.review('app/views/posts/index.html.erb', content)
14
- runner.should have(1).errors
15
- runner.errors[0].to_s.should == "app/views/posts/index.html.erb:1 - move code into controller"
16
- end
8
+ it "should move code into controller for method call" do
9
+ content = <<-EOF
10
+ <% Post.find(:all).each do |post| %>
11
+ <%=h post.title %>
12
+ <%=h post.content %>
13
+ <% end %>
14
+ EOF
15
+ runner.review('app/views/posts/index.html.erb', content)
16
+ runner.should have(1).errors
17
+ runner.errors[0].to_s.should == "app/views/posts/index.html.erb:1 - move code into controller"
18
+ end
17
19
 
18
- it "should move code into controller for assign" do
19
- content = <<-EOF
20
- <% @posts = Post.all %>
21
- <% @posts.each do |post| %>
22
- <%=h post.title %>
23
- <%=h post.content %>
24
- <% end %>
25
- EOF
26
- runner.review('app/views/posts/index.html.erb', content)
27
- runner.should have(1).errors
28
- runner.errors[0].to_s.should == "app/views/posts/index.html.erb:1 - move code into controller"
29
- end
20
+ it "should move code into controller for assign" do
21
+ content = <<-EOF
22
+ <% @posts = Post.all %>
23
+ <% @posts.each do |post| %>
24
+ <%=h post.title %>
25
+ <%=h post.content %>
26
+ <% end %>
27
+ EOF
28
+ runner.review('app/views/posts/index.html.erb', content)
29
+ runner.should have(1).errors
30
+ runner.errors[0].to_s.should == "app/views/posts/index.html.erb:1 - move code into controller"
31
+ end
30
32
 
31
- it "should not move code into controller" do
32
- content = <<-EOF
33
- <% @posts.each do |post| %>
34
- <%=h post.title %>
35
- <%=h post.content %>
36
- <% end %>
37
- EOF
38
- runner.review('app/views/posts/index.html.erb', content)
39
- runner.should have(0).errors
33
+ it "should not move code into controller" do
34
+ content = <<-EOF
35
+ <% @posts.each do |post| %>
36
+ <%=h post.title %>
37
+ <%=h post.content %>
38
+ <% end %>
39
+ EOF
40
+ runner.review('app/views/posts/index.html.erb', content)
41
+ runner.should have(0).errors
42
+ end
43
+ end
40
44
  end
41
45
  end
@@ -1,24 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::MoveCodeIntoHelperReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoHelperReview.new('array_count' => 2)) }
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe MoveCodeIntoHelperReview do
6
+ let(:runner) { Core::Runner.new(:reviews => MoveCodeIntoHelperReview.new('array_count' => 2)) }
5
7
 
6
- it "should move code into helper" do
7
- content = <<-EOF
8
- <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
9
- [t(:published), "published"]],
10
- params[:default_state] ) %>
11
- EOF
12
- runner.review('app/views/posts/show.html.erb', content)
13
- runner.should have(1).errors
14
- runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)"
15
- end
8
+ it "should move code into helper" do
9
+ content = <<-EOF
10
+ <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
11
+ [t(:published), "published"]],
12
+ params[:default_state] ) %>
13
+ EOF
14
+ runner.review('app/views/posts/show.html.erb', content)
15
+ runner.should have(1).errors
16
+ runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)"
17
+ end
16
18
 
17
- it "should not move code into helper with simple arguments" do
18
- content = <<-EOF
19
- <%= select_tag :state, options_for_select( Post.STATES ) %>
20
- EOF
21
- runner.review('app/views/posts/show.html.erb', content)
22
- runner.should have(0).errors
19
+ it "should not move code into helper with simple arguments" do
20
+ content = <<-EOF
21
+ <%= select_tag :state, options_for_select( Post.STATES ) %>
22
+ EOF
23
+ runner.review('app/views/posts/show.html.erb', content)
24
+ runner.should have(0).errors
25
+ end
26
+ end
23
27
  end
24
28
  end
@@ -1,68 +1,72 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::MoveCodeIntoModelReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoModelReview.new) }
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe MoveCodeIntoModelReview do
6
+ let(:runner) { Core::Runner.new(:reviews => MoveCodeIntoModelReview.new) }
5
7
 
6
- it "should move code into model" do
7
- content =<<-EOF
8
- <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
9
- <%= link_to 'Edit this post', edit_post_url(@post) %>
10
- <% end %>
11
- EOF
12
- runner.review('app/views/posts/show.html.erb', content)
13
- runner.should have(1).errors
14
- runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
15
- end
8
+ it "should move code into model" do
9
+ content =<<-EOF
10
+ <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
11
+ <%= link_to 'Edit this post', edit_post_url(@post) %>
12
+ <% end %>
13
+ EOF
14
+ runner.review('app/views/posts/show.html.erb', content)
15
+ runner.should have(1).errors
16
+ runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
17
+ end
16
18
 
17
- it "should move code into model with haml" do
18
- content =<<-EOF
19
+ it "should move code into model with haml" do
20
+ content =<<-EOF
19
21
  - if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
20
22
  = link_to 'Edit this post', edit_post_url(@post)
21
- EOF
22
- runner.review('app/views/posts/show.html.haml', content)
23
- runner.should have(1).errors
24
- runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
25
- end
23
+ EOF
24
+ runner.review('app/views/posts/show.html.haml', content)
25
+ runner.should have(1).errors
26
+ runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
27
+ end
26
28
 
27
- it "should move code into model with slim" do
28
- content =<<-EOF
29
+ it "should move code into model with slim" do
30
+ content =<<-EOF
29
31
  - if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
30
32
  = link_to 'Edit this post', edit_post_url(@post)
31
- EOF
32
- runner.review('app/views/posts/show.html.slim', content)
33
- runner.should have(1).errors
34
- runner.errors[0].to_s.should == "app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)"
35
- end
33
+ EOF
34
+ runner.review('app/views/posts/show.html.slim', content)
35
+ runner.should have(1).errors
36
+ runner.errors[0].to_s.should == "app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)"
37
+ end
36
38
 
37
- it "should move code into model only review for current if conditional statement" do
38
- content =<<-EOF
39
- <% if @post.title %>
40
- <% if @post.user %>
41
- <% if @post.description %>
39
+ it "should move code into model only review for current if conditional statement" do
40
+ content =<<-EOF
41
+ <% if @post.title %>
42
+ <% if @post.user %>
43
+ <% if @post.description %>
44
+ <% end %>
45
+ <% end %>
42
46
  <% end %>
43
- <% end %>
44
- <% end %>
45
- EOF
46
- runner.review('app/views/posts/show.html.erb', content)
47
- runner.should have(0).errors
48
- end
47
+ EOF
48
+ runner.review('app/views/posts/show.html.erb', content)
49
+ runner.should have(0).errors
50
+ end
49
51
 
50
- it "should not move code into model" do
51
- content =<<-EOF
52
- <% if @post.editable_by?(current_user) %>
53
- <%= link_to 'Edit this post', edit_post_url(@post) %>
54
- <% end %>
55
- EOF
56
- runner.review('app/views/posts/show.html.erb', content)
57
- runner.should have(0).errors
58
- end
52
+ it "should not move code into model" do
53
+ content =<<-EOF
54
+ <% if @post.editable_by?(current_user) %>
55
+ <%= link_to 'Edit this post', edit_post_url(@post) %>
56
+ <% end %>
57
+ EOF
58
+ runner.review('app/views/posts/show.html.erb', content)
59
+ runner.should have(0).errors
60
+ end
59
61
 
60
- it "should not move code into model for multiple calls on same variable node" do
61
- content =<<-EOF
62
- <% if !job.company.blank? && job.company.title? %>
63
- <% end %>
64
- EOF
65
- runner.review('app/views/jobs/show.html.erb', content)
66
- runner.should have(0).errors
62
+ it "should not move code into model for multiple calls on same variable node" do
63
+ content =<<-EOF
64
+ <% if !job.company.blank? && job.company.title? %>
65
+ <% end %>
66
+ EOF
67
+ runner.review('app/views/jobs/show.html.erb', content)
68
+ runner.should have(0).errors
69
+ end
70
+ end
67
71
  end
68
72
  end
@@ -1,78 +1,77 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::MoveFinderToNamedScopeReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveFinderToNamedScopeReview.new) }
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe MoveFinderToNamedScopeReview do
6
+ let(:runner) { Core::Runner.new(:reviews => MoveFinderToNamedScopeReview.new) }
5
7
 
6
- it "should move finder to named_scope" do
7
- content = <<-EOF
8
- class PostsController < ActionController::Base
8
+ it "should move finder to named_scope" do
9
+ content = <<-EOF
10
+ class PostsController < ActionController::Base
11
+ def index
12
+ @public_posts = Post.find(:all, :conditions => { :state => 'public' },
13
+ :limit => 10,
14
+ :order => 'created_at desc')
9
15
 
10
- def index
11
- @public_posts = Post.find(:all, :conditions => { :state => 'public' },
12
- :limit => 10,
13
- :order => 'created_at desc')
14
-
15
- @draft_posts = Post.find(:all, :conditions => { :state => 'draft' },
16
- :limit => 10,
17
- :order => 'created_at desc')
16
+ @draft_posts = Post.find(:all, :conditions => { :state => 'draft' },
17
+ :limit => 10,
18
+ :order => 'created_at desc')
19
+ end
20
+ end
21
+ EOF
22
+ runner.review('app/controllers/posts_controller.rb', content)
23
+ runner.should have(2).errors
24
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:4 - move finder to named_scope"
25
+ runner.errors[1].to_s.should == "app/controllers/posts_controller.rb:8 - move finder to named_scope"
18
26
  end
19
- end
20
- EOF
21
- runner.review('app/controllers/posts_controller.rb', content)
22
- runner.should have(2).errors
23
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:4 - move finder to named_scope"
24
- runner.errors[1].to_s.should == "app/controllers/posts_controller.rb:8 - move finder to named_scope"
25
- end
26
27
 
27
- it "should not move simple finder" do
28
- content = <<-EOF
29
- class PostsController < ActionController::Base
30
-
31
- def index
32
- @all_posts = Post.find(:all)
33
- @another_all_posts = Post.all
34
- @first_post = Post.find(:first)
35
- @another_first_post = Post.first
36
- @last_post = Post.find(:last)
37
- @another_last_post = Post.last
28
+ it "should not move simple finder" do
29
+ content = <<-EOF
30
+ class PostsController < ActionController::Base
31
+ def index
32
+ @all_posts = Post.find(:all)
33
+ @another_all_posts = Post.all
34
+ @first_post = Post.find(:first)
35
+ @another_first_post = Post.first
36
+ @last_post = Post.find(:last)
37
+ @another_last_post = Post.last
38
+ end
39
+ end
40
+ EOF
41
+ runner.review('app/controllers/posts_controller.rb', content)
42
+ runner.should have(0).errors
38
43
  end
39
- end
40
- EOF
41
- runner.review('app/controllers/posts_controller.rb', content)
42
- runner.should have(0).errors
43
- end
44
44
 
45
- it "should not move namd_scope" do
46
- content = <<-EOF
47
- class PostsController < ActionController::Base
48
-
49
- def index
50
- @public_posts = Post.published
51
- @draft_posts = Post.draft
45
+ it "should not move namd_scope" do
46
+ content = <<-EOF
47
+ class PostsController < ActionController::Base
48
+ def index
49
+ @public_posts = Post.published
50
+ @draft_posts = Post.draft
51
+ end
52
+ end
53
+ EOF
54
+ runner.review('app/controllers/posts_controller.rb', content)
55
+ runner.should have(0).errors
52
56
  end
53
- end
54
- EOF
55
- runner.review('app/controllers/posts_controller.rb', content)
56
- runner.should have(0).errors
57
- end
58
57
 
59
- it "should not review model file" do
60
- content = <<-EOF
61
- class Post < ActiveRecord::Base
58
+ it "should not review model file" do
59
+ content = <<-EOF
60
+ class Post < ActiveRecord::Base
61
+ def published
62
+ Post.find(:all, :conditions => { :state => 'public' },
63
+ :limit => 10, :order => 'created_at desc')
64
+ end
62
65
 
63
- def published
64
- Post.find(:all, :conditions => { :state => 'public' },
65
- :limit => 10, :order => 'created_at desc')
66
+ def published
67
+ Post.find(:all, :conditions => { :state => 'draft' },
68
+ :limit => 10, :order => 'created_at desc')
69
+ end
70
+ end
71
+ EOF
72
+ runner.review('app/model/post.rb', content)
73
+ runner.should have(0).errors
66
74
  end
67
-
68
- def published
69
- Post.find(:all, :conditions => { :state => 'draft' },
70
- :limit => 10, :order => 'created_at desc')
71
- end
72
-
73
75
  end
74
- EOF
75
- runner.review('app/model/post.rb', content)
76
- runner.should have(0).errors
77
76
  end
78
77
  end
@@ -1,62 +1,63 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::MoveModelLogicIntoModelReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveModelLogicIntoModelReview.new) }
5
-
6
- it "should move model logic into model" do
7
- content = <<-EOF
8
- class PostsController < ApplicationController
9
-
10
- def publish
11
- @post = Post.find(params[:id])
12
- @post.update_attributes(:is_published, true)
13
- @post.approved_by = current_user
14
- if @post.created_at > Time.now - 7.days
15
- @post.popular = 100
16
- else
17
- @post.popular = 0
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe MoveModelLogicIntoModelReview do
6
+ let(:runner) { Core::Runner.new(:reviews => MoveModelLogicIntoModelReview.new) }
7
+
8
+ it "should move model logic into model" do
9
+ content = <<-EOF
10
+ class PostsController < ApplicationController
11
+ def publish
12
+ @post = Post.find(params[:id])
13
+ @post.update_attributes(:is_published, true)
14
+ @post.approved_by = current_user
15
+ if @post.created_at > Time.now - 7.days
16
+ @post.popular = 100
17
+ else
18
+ @post.popular = 0
19
+ end
20
+
21
+ redirect_to post_url(@post)
22
+ end
18
23
  end
19
-
20
- redirect_to post_url(@post)
24
+ EOF
25
+ runner.review('app/controllers/posts_controller.rb', content)
26
+ runner.should have(1).errors
27
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
21
28
  end
22
- end
23
- EOF
24
- runner.review('app/controllers/posts_controller.rb', content)
25
- runner.should have(1).errors
26
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
27
- end
28
-
29
- it "should not move model logic into model with simple model calling" do
30
- content = <<-EOF
31
- class PostsController < ApplicationController
32
29
 
33
- def publish
34
- @post = Post.find(params[:id])
35
- @post.update_attributes(:is_published, true)
36
- @post.approved_by = current_user
30
+ it "should not move model logic into model with simple model calling" do
31
+ content = <<-EOF
32
+ class PostsController < ApplicationController
33
+ def publish
34
+ @post = Post.find(params[:id])
35
+ @post.update_attributes(:is_published, true)
36
+ @post.approved_by = current_user
37
37
 
38
- redirect_to post_url(@post)
38
+ redirect_to post_url(@post)
39
+ end
40
+ end
41
+ EOF
42
+ runner.review('app/controllers/posts_controller.rb', content)
43
+ runner.should have(0).errors
39
44
  end
40
- end
41
- EOF
42
- runner.review('app/controllers/posts_controller.rb', content)
43
- runner.should have(0).errors
44
- end
45
45
 
46
- it "should not move model logic into model with self calling" do
47
- content = <<-EOF
48
- class PostsController < ApplicationController
49
-
50
- def publish
51
- self.step1
52
- self.step2
53
- self.step3
54
- self.step4
55
- self.step5
46
+ it "should not move model logic into model with self calling" do
47
+ content = <<-EOF
48
+ class PostsController < ApplicationController
49
+ def publish
50
+ self.step1
51
+ self.step2
52
+ self.step3
53
+ self.step4
54
+ self.step5
55
+ end
56
+ end
57
+ EOF
58
+ runner.review('app/controllers/posts_controller.rb', content)
59
+ runner.should have(0).errors
56
60
  end
57
61
  end
58
- EOF
59
- runner.review('app/controllers/posts_controller.rb', content)
60
- runner.should have(0).errors
61
62
  end
62
63
  end