rails_best_practices 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.md +2 -0
  4. data/assets/result.html.erb +25 -2
  5. data/lib/rails_best_practices.rb +20 -9
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +106 -25
  8. data/lib/rails_best_practices/core/controllers.rb +2 -1
  9. data/lib/rails_best_practices/core/error.rb +3 -2
  10. data/lib/rails_best_practices/core/klasses.rb +34 -0
  11. data/lib/rails_best_practices/core/mailers.rb +2 -1
  12. data/lib/rails_best_practices/core/methods.rb +113 -9
  13. data/lib/rails_best_practices/core/model_associations.rb +17 -0
  14. data/lib/rails_best_practices/core/model_attributes.rb +16 -0
  15. data/lib/rails_best_practices/core/models.rb +3 -2
  16. data/lib/rails_best_practices/core/nil.rb +9 -1
  17. data/lib/rails_best_practices/core/runner.rb +65 -26
  18. data/lib/rails_best_practices/core_ext/sexp.rb +57 -0
  19. data/lib/rails_best_practices/prepares.rb +12 -1
  20. data/lib/rails_best_practices/prepares/controller_prepare.rb +13 -8
  21. data/lib/rails_best_practices/prepares/mailer_prepare.rb +3 -3
  22. data/lib/rails_best_practices/prepares/model_prepare.rb +44 -16
  23. data/lib/rails_best_practices/reviews.rb +1 -0
  24. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +5 -2
  25. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +77 -0
  26. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +2 -2
  27. data/lib/rails_best_practices/reviews/review.rb +1 -1
  28. data/lib/rails_best_practices/version.rb +1 -1
  29. data/rails_best_practices.yml +1 -0
  30. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +11 -0
  31. data/spec/rails_best_practices/core/check_spec.rb +22 -0
  32. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  33. data/spec/rails_best_practices/core/error_spec.rb +1 -1
  34. data/spec/rails_best_practices/core/klasses_spec.rb +12 -0
  35. data/spec/rails_best_practices/core/mailers_spec.rb +5 -0
  36. data/spec/rails_best_practices/core/methods_spec.rb +26 -4
  37. data/spec/rails_best_practices/core/models_spec.rb +2 -2
  38. data/spec/rails_best_practices/core/runner_spec.rb +13 -0
  39. data/spec/rails_best_practices/core_ext/sexp_spec.rb +26 -2
  40. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +72 -60
  41. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +1 -1
  42. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +150 -59
  43. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +20 -3
  44. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +14 -0
  45. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +387 -0
  46. metadata +15 -3
@@ -26,3 +26,4 @@ require 'rails_best_practices/reviews/simplify_render_in_views_review'
26
26
  require 'rails_best_practices/reviews/simplify_render_in_controllers_review'
27
27
  require 'rails_best_practices/reviews/remove_empty_helpers_review'
28
28
  require 'rails_best_practices/reviews/restrict_auto_generated_routes_review'
29
+ require 'rails_best_practices/reviews/remove_unused_methods_in_models_review'
@@ -40,6 +40,7 @@ module RailsBestPractices
40
40
  super()
41
41
  @counter = 0
42
42
  @nested_count = options['nested_count'] || 2
43
+ @shallow_nodes = []
43
44
  end
44
45
 
45
46
  # check all method_add_block node.
@@ -68,16 +69,18 @@ module RailsBestPractices
68
69
  # then check if @counter is greater than or equal to @nested_count,
69
70
  # if so, it is the needless deep nesting.
70
71
  def recursively_check(node)
72
+ shallow = @shallow_nodes.include? node
71
73
  if [:command_call, :command].include?(node[1].sexp_type) && ["resources", "resource"].include?(node[1].message.to_s)
72
74
  hash_node = node[1].arguments.grep_node(:sexp_type => :bare_assoc_hash)
73
- return if hash_node && "true" == hash_node.hash_value("shallow").to_s
75
+ shallow = (hash_node && "true" == hash_node.hash_value("shallow").to_s) unless shallow
74
76
  @counter += 1
75
77
  node.block.statements.each do |stmt_node|
78
+ @shallow_nodes << stmt_node if shallow
76
79
  recursively_check(stmt_node)
77
80
  end
78
81
  @counter -= 1
79
82
  elsif [:command_call, :command].include?(node.sexp_type) && ["resources", "resource"].include?(node.message.to_s)
80
- add_error "needless deep nesting (nested_count > #{@nested_count})", @file, node.line if @counter >= @nested_count
83
+ add_error "needless deep nesting (nested_count > #{@nested_count})", @file, node.line if @counter >= @nested_count && !@shallow_nodes.include?(node)
81
84
  end
82
85
  end
83
86
  end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require 'rails_best_practices/reviews/review'
3
+
4
+ module RailsBestPractices
5
+ module Reviews
6
+ class RemoveUnusedMethodsInModelsReview < Review
7
+ include Klassable
8
+ include Completeable
9
+
10
+ EXCEPT_METHODS = %w(initialize validate to_xml to_json)
11
+
12
+ def interesting_nodes
13
+ [:module, :class, :call, :fcall, :command, :method_add_arg, :var_ref]
14
+ end
15
+
16
+ def initialize(options={})
17
+ super()
18
+ @model_methods = Prepares.model_methods
19
+ @except_methods = EXCEPT_METHODS + options['except_methods']
20
+ end
21
+
22
+ def start_call(node)
23
+ mark_used(node.message)
24
+ end
25
+
26
+ def start_fcall(node)
27
+ mark_used(node.message)
28
+ end
29
+
30
+ def start_var_ref(node)
31
+ mark_used(node)
32
+ end
33
+
34
+ def start_command(node)
35
+ unless %w(named_scope scope).include? node.message.to_s
36
+ mark_used(node.message)
37
+ node.arguments.all.each { |argument| mark_used(argument) }
38
+ end
39
+ end
40
+
41
+ def start_method_add_arg(node)
42
+ if "try" == node.message.to_s
43
+ method_name = node.arguments.all[0].to_s
44
+ call_method(method_name)
45
+ end
46
+ end
47
+
48
+ def on_complete
49
+ @model_methods.get_all_unused_methods.each do |method|
50
+ if !@except_methods.include?(method.method_name) && method.method_name !~ /=$/
51
+ add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+ def mark_used(method_node)
58
+ if :bare_assoc_hash == method_node.sexp_type
59
+ method_node.hash_values.each { |value_node| mark_used(value_node) }
60
+ elsif :array == method_node.sexp_type
61
+ method_node.array_values.each { |value_node| mark_used(value_node) }
62
+ else
63
+ method_name = method_node.to_s
64
+ end
65
+ call_method(method_name)
66
+ end
67
+
68
+ def call_method(method_name)
69
+ if @model_methods.has_method?(current_class_name, method_name)
70
+ @model_methods.get_method(current_class_name, method_name).mark_used
71
+ end
72
+ @model_methods.mark_extend_class_method_used(current_class_name, method_name)
73
+ @model_methods.possible_public_used(method_name)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -68,7 +68,7 @@ module RailsBestPractices
68
68
  return unless Prepares.controllers.include? controller_name
69
69
  resources_methods = resources_methods(node)
70
70
  unless resources_methods.all? { |meth| Prepares.controller_methods.has_method?(controller_name, meth) }
71
- only_methods = (resources_methods & Prepares.controller_methods.get_methods(controller_name)).map { |meth| ":#{meth}" }.join(", ")
71
+ only_methods = (resources_methods & Prepares.controller_methods.get_methods(controller_name).map(&:method_name)).map { |meth| ":#{meth}" }.join(", ")
72
72
  add_error "restrict auto-generated routes (:only => [#{only_methods}])"
73
73
  end
74
74
  end
@@ -79,7 +79,7 @@ module RailsBestPractices
79
79
  return unless Prepares.controllers.include? controller_name
80
80
  resource_methods = resource_methods(node)
81
81
  unless resource_methods.all? { |meth| Prepares.controller_methods.has_method?(controller_name, meth) }
82
- only_methods = (resource_methods & Prepares.controller_methods.get_methods(controller_name)).map { |meth| ":#{meth}" }.join(", ")
82
+ only_methods = (resource_methods & Prepares.controller_methods.get_methods(controller_name).map(&:method_name)).map { |meth| ":#{meth}" }.join(", ")
83
83
  add_error "restrict auto-generated routes (:only => [#{only_methods}])"
84
84
  end
85
85
  end
@@ -16,7 +16,7 @@ module RailsBestPractices
16
16
  # then save it to as key in @variable_use_count hash, and add the call count (hash value).
17
17
  def remember_variable_use_count(node)
18
18
  variable_node = variable(node)
19
- if variable_node
19
+ if variable_node && "self" != variable_node.to_s
20
20
  variable_use_count[variable_node.to_s] ||= 0
21
21
  variable_use_count[variable_node.to_s] += 1
22
22
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
 
@@ -27,3 +27,4 @@ SimplifyRenderInControllersCheck: { }
27
27
  RemoveEmptyHelpersCheck: { }
28
28
  RemoveTabCheck: { }
29
29
  RestrictAutoGeneratedRoutesCheck: { }
30
+ # RemoveUnusedMethodsInModelsCheck: { except_methods: [] }
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require 'rails_best_practices/reviews/review'
3
+
4
+ module RailsBestPractices
5
+ module Plugins
6
+ module Reviews
7
+ class NotUseRailsRootReview < RailsBestPractices::Reviews::Review
8
+ end
9
+ end
10
+ end
11
+ end
@@ -38,4 +38,26 @@ describe RailsBestPractices::Core::Check do
38
38
  check.node_end(node)
39
39
  end
40
40
  end
41
+
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
47
+ end
48
+ node = stub(:sexp_type => :call)
49
+ check.node_start(node)
50
+ execute.should be_true
51
+ end
52
+
53
+ it "should ad callbacks to end_call" do
54
+ execute = false
55
+ check.class.add_callback "end_call" do
56
+ execute = true
57
+ end
58
+ node = stub(:sexp_type => :call)
59
+ check.node_end(node)
60
+ execute.should be_true
61
+ end
62
+ end
41
63
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RailsBestPractices::Core::Controllers do
4
- it { should be_a_kind_of Array }
4
+ it { should be_a_kind_of RailsBestPractices::Core::Klasses }
5
5
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe RailsBestPractices::Core::Error do
4
4
  it "should return error with filename, line number and message" do
5
- RailsBestPractices::Core::Error.new("app/models/user.rb", 100, "not good").to_s.should == "app/models/user.rb:100 - not good"
5
+ RailsBestPractices::Core::Error.new("app/models/user.rb", 100, "not good", "BogusReview").to_s.should == "app/models/user.rb:100 - not good"
6
6
  end
7
7
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsBestPractices::Core::Klasses do
4
+ it { should be_a_kind_of Array }
5
+
6
+ context "Klass" do
7
+ it "should get to_s" do
8
+ klass = RailsBestPractices::Core::Klass.new("BlogPost", "Post", ["Admin"])
9
+ klass.to_s.should == "Admin::BlogPost"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsBestPractices::Core::Mailers do
4
+ it { should be_a_kind_of RailsBestPractices::Core::Klasses }
5
+ end
@@ -6,17 +6,39 @@ describe RailsBestPractices::Core::Methods do
6
6
  before :each do
7
7
  methods.add_method("Post", "create")
8
8
  methods.add_method("Post", "destroy")
9
+ methods.add_method("Post", "save_or_update", {}, "protected")
10
+ methods.add_method("Post", "find_by_sql", {}, "private")
9
11
  methods.add_method("Comment", "create")
10
12
  end
11
13
 
12
14
  it "should get_methods" do
13
- methods.get_methods("Post").to_a.should == ["create", "destroy"]
14
- methods.get_methods("Comment").to_a.should == ["create"]
15
+ methods.get_methods("Post").map(&:method_name).should == ["create", "destroy", "save_or_update", "find_by_sql"]
16
+ methods.get_methods("Post", "public").map(&:method_name).should == ["create", "destroy"]
17
+ methods.get_methods("Post", "protected").map(&:method_name).should == ["save_or_update"]
18
+ methods.get_methods("Post", "private").map(&:method_name).should == ["find_by_sql"]
19
+ methods.get_methods("Comment").map(&:method_name).should == ["create"]
15
20
  end
16
21
 
17
22
  it "should has_method?" do
18
- methods.should be_has_method("Post", "create")
19
- methods.should be_has_method("Post", "destroy")
23
+ methods.should be_has_method("Post", "create", "public")
24
+ methods.should be_has_method("Post", "destroy", "public")
25
+ methods.should_not be_has_method("Post", "save_or_update", "public")
26
+ methods.should be_has_method("Post", "save_or_update", "protected")
27
+ methods.should_not be_has_method("Post", "find_by_sql", "public")
28
+ methods.should be_has_method("Post", "find_by_sql", "private")
20
29
  methods.should_not be_has_method("Comment", "destroy")
21
30
  end
31
+
32
+ it "should get_method" do
33
+ methods.get_method("Post", "create", "public").should_not be_nil
34
+ methods.get_method("Post", "create", "protected").should be_nil
35
+ end
36
+
37
+ it "should get_all_unused_methods" do
38
+ methods.get_method("Comment", "create").mark_used
39
+ methods.get_all_unused_methods("public").map(&:method_name).should == ["create", "destroy"]
40
+ methods.get_all_unused_methods("protected").map(&:method_name).should == ["save_or_update"]
41
+ methods.get_all_unused_methods("private").map(&:method_name).should == ["find_by_sql"]
42
+ methods.get_all_unused_methods.map(&:method_name).should == ["create", "destroy", "save_or_update", "find_by_sql"]
43
+ end
22
44
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RailsBestPractices::Core::Models do
4
- it { should be_a_kind_of Array }
5
- end
4
+ it { should be_a_kind_of RailsBestPractices::Core::Klasses }
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsBestPractices::Core::Runner do
4
+
5
+ before { RailsBestPractices::Core::Runner.base_path = 'spec/fixtures/' }
6
+
7
+ describe "load_plugin_reviews" do
8
+ it "should load plugins in lib/rails_best_practices/plugins/reviews" do
9
+ runner = RailsBestPractices::Core::Runner.new
10
+ runner.instance_variable_get('@reviews').map(&:class).should include(RailsBestPractices::Plugins::Reviews::NotUseRailsRootReview)
11
+ end
12
+ end
13
+ end
@@ -365,17 +365,29 @@ describe Sexp do
365
365
  end
366
366
 
367
367
  describe "hash_keys" do
368
- it "should get value for hash node" do
368
+ it "should get hash_keys for hash node" do
369
369
  node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(:sexp_type => :hash)
370
370
  node.hash_keys.should == ["first_name", "last_name"]
371
371
  end
372
372
 
373
- it "should get value for bare_assoc_hash" do
373
+ it "should get hash_keys for bare_assoc_hash" do
374
374
  node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(:sexp_type => :bare_assoc_hash)
375
375
  node.hash_keys.should == ["first_name", "last_name"]
376
376
  end
377
377
  end
378
378
 
379
+ describe "hash_values" do
380
+ it "should get hash_values for hash node" do
381
+ node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(:sexp_type => :hash)
382
+ node.hash_values.map(&:to_s).should == ["Richard", "Huang"]
383
+ end
384
+
385
+ it "should get hash_values for bare_assoc_hash" do
386
+ node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(:sexp_type => :bare_assoc_hash)
387
+ node.hash_values.map(&:to_s).should == ["Richard", "Huang"]
388
+ end
389
+ end
390
+
379
391
  describe "array_size" do
380
392
  it "should get array size" do
381
393
  node = parse_content("['first_name', 'last_name']").grep_node(:sexp_type => :array)
@@ -388,6 +400,18 @@ describe Sexp do
388
400
  end
389
401
  end
390
402
 
403
+ describe "array_values" do
404
+ it "should get array values" do
405
+ node = parse_content("['first_name', 'last_name']").grep_node(:sexp_type => :array)
406
+ node.array_values.map(&:to_s).should == ["first_name", "last_name"]
407
+ end
408
+
409
+ it "should get empty array values" do
410
+ node = parse_content("[]").grep_node(:sexp_type => :array)
411
+ node.array_values.should == []
412
+ end
413
+ end
414
+
391
415
  describe "to_object" do
392
416
  it "should to array" do
393
417
  node = parse_content("['first_name', 'last_name']").grep_node(:sexp_type => :array)
@@ -7,86 +7,98 @@ describe RailsBestPractices::Prepares::ControllerPrepare do
7
7
  runner.whiny = true
8
8
  end
9
9
 
10
- it "should parse controller methods" do
11
- content =<<-EOF
12
- class PostsController < ApplicationController
13
- def index
14
- end
15
-
16
- def show
17
- end
18
- end
19
- EOF
20
- runner.prepare('app/controllers/posts_controller.rb', content)
21
- methods = RailsBestPractices::Prepares.controller_methods
22
- methods.get_methods("PostsController").should == ["index", "show"]
23
- end
24
-
25
- it "should parse controller methods with module ::" do
26
- content =<<-EOF
27
- class Admin::Blog::PostsController < ApplicationController
28
- def index
29
- end
30
-
31
- def show
32
- end
33
- end
34
- EOF
35
- runner.prepare('app/controllers/admin/posts_controller.rb', content)
36
- methods = RailsBestPractices::Prepares.controller_methods
37
- methods.get_methods("Admin::Blog::PostsController").should == ["index", "show"]
38
- end
39
-
40
- it "should parse controller methods with module" do
41
- content =<<-EOF
42
- module Admin
43
- module Blog
44
- class PostsController < ApplicationController
45
- def index
46
- end
47
-
48
- def show
49
- end
50
- end
10
+ context "methods" do
11
+ it "should parse controller methods" do
12
+ content =<<-EOF
13
+ class PostsController < ApplicationController
14
+ def index; end
15
+ def show; end
51
16
  end
17
+ EOF
18
+ runner.prepare('app/controllers/posts_controller.rb', content)
19
+ methods = RailsBestPractices::Prepares.controller_methods
20
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show"]
52
21
  end
53
- EOF
54
- runner.prepare('app/controllers/admin/posts_controller.rb', content)
55
- methods = RailsBestPractices::Prepares.controller_methods
56
- methods.get_methods("Admin::Blog::PostsController").should == ["index", "show"]
57
- end
58
22
 
59
- describe "inherited_resources" do
60
- it "extend inherited_resources" do
23
+ it "should parse model methods with access control" do
61
24
  content =<<-EOF
62
- class PostsController < InheritedResources::Base
25
+ class PostsController < ApplicationController
26
+ def index; end
27
+ def show; end
28
+ protected
29
+ def resources; end
30
+ private
31
+ def resource; end
63
32
  end
64
33
  EOF
65
34
  runner.prepare('app/controllers/posts_controller.rb', content)
66
35
  methods = RailsBestPractices::Prepares.controller_methods
67
- methods.get_methods("PostsController").should == ["index", "show", "new", "create", "edit", "update", "destroy"]
36
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "resources", "resource"]
37
+ methods.get_methods("PostsController", "public").map(&:method_name).should == ["index", "show"]
38
+ methods.get_methods("PostsController", "protected").map(&:method_name).should == ["resources"]
39
+ methods.get_methods("PostsController", "private").map(&:method_name).should == ["resource"]
68
40
  end
69
41
 
70
- it "extend inherited_resources with actions" do
42
+ it "should parse controller methods with module ::" do
71
43
  content =<<-EOF
72
- class PostsController < InheritedResources::Base
73
- actions :index, :show
44
+ class Admin::Blog::PostsController < ApplicationController
45
+ def index; end
46
+ def show; end
74
47
  end
75
48
  EOF
76
- runner.prepare('app/controllers/posts_controller.rb', content)
49
+ runner.prepare('app/controllers/admin/posts_controller.rb', content)
77
50
  methods = RailsBestPractices::Prepares.controller_methods
78
- methods.get_methods("PostsController").should == ["index", "show"]
51
+ methods.get_methods("Admin::Blog::PostsController").map(&:method_name).should == ["index", "show"]
79
52
  end
80
53
 
81
- it "DSL inherit_resources" do
54
+ it "should parse controller methods with module" do
82
55
  content =<<-EOF
83
- class PostsController
84
- inherit_resources
56
+ module Admin
57
+ module Blog
58
+ class PostsController < ApplicationController
59
+ def index; end
60
+ def show; end
61
+ end
62
+ end
85
63
  end
86
64
  EOF
87
- runner.prepare('app/controllers/posts_controller.rb', content)
65
+ runner.prepare('app/controllers/admin/posts_controller.rb', content)
88
66
  methods = RailsBestPractices::Prepares.controller_methods
89
- methods.get_methods("PostsController").should == ["index", "show", "new", "create", "edit", "update", "destroy"]
67
+ methods.get_methods("Admin::Blog::PostsController").map(&:method_name).should == ["index", "show"]
68
+ end
69
+
70
+ context "inherited_resources" do
71
+ it "extend inherited_resources" do
72
+ content =<<-EOF
73
+ class PostsController < InheritedResources::Base
74
+ end
75
+ EOF
76
+ runner.prepare('app/controllers/posts_controller.rb', content)
77
+ methods = RailsBestPractices::Prepares.controller_methods
78
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
79
+ end
80
+
81
+ it "extend inherited_resources with actions" do
82
+ content =<<-EOF
83
+ class PostsController < InheritedResources::Base
84
+ actions :index, :show
85
+ end
86
+ EOF
87
+ runner.prepare('app/controllers/posts_controller.rb', content)
88
+ methods = RailsBestPractices::Prepares.controller_methods
89
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show"]
90
+ end
91
+
92
+ it "DSL inherit_resources" do
93
+ content =<<-EOF
94
+ class PostsController
95
+ inherit_resources
96
+ end
97
+ EOF
98
+ runner.prepare('app/controllers/posts_controller.rb', content)
99
+ methods = RailsBestPractices::Prepares.controller_methods
100
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
101
+ end
90
102
  end
91
103
  end
92
104
  end