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
@@ -48,19 +48,35 @@ describe Sexp do
48
48
  it "should get the call nodes with subject current_user" do
49
49
  nodes = []
50
50
  @node.grep_nodes(:sexp_type => :call, :subject => "current_user") { |node| nodes << node }
51
- nodes.should == [s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
51
+ if RUBY_VERSION == "1.9.2"
52
+ nodes.should == [s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
53
+ else
54
+ nodes.should == [s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
55
+ end
52
56
  end
53
57
 
54
58
  it "should get the call nodes with different messages" do
55
59
  nodes = []
56
60
  @node.grep_nodes(:sexp_type => :call, :message => ["posts", "find"]) { |node| nodes << node }
57
- nodes.should == [s(:call, s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21))), :".", s(:@ident, "find", s(2, 27))), s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
61
+ if RUBY_VERSION == "1.9.2"
62
+ nodes.should == [s(:call, s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21))), :".", s(:@ident, "find", s(2, 27))), s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
63
+ else
64
+ nodes.should == [s(:call, s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21))), :".", s(:@ident, "find", s(2, 27))), s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
65
+ end
58
66
  end
59
67
 
60
- it "should get the vcall node with to_s" do
61
- nodes = []
62
- @node.grep_nodes(:sexp_type => :vcall, :to_s => "current_user") { |node| nodes << node }
63
- nodes.should == [s(:vcall, s(:@ident, "current_user", s(2, 8)))]
68
+ if RUBY_VERSION == "1.9.2"
69
+ it "should get the var_ref node with to_s" do
70
+ nodes = []
71
+ @node.grep_nodes(:sexp_type => :var_ref, :to_s => "current_user") { |node| nodes << node }
72
+ nodes.should == [s(:var_ref, s(:@ident, "current_user", s(2, 8)))]
73
+ end
74
+ else
75
+ it "should get the vcall node with to_s" do
76
+ nodes = []
77
+ @node.grep_nodes(:sexp_type => :vcall, :to_s => "current_user") { |node| nodes << node }
78
+ nodes.should == [s(:vcall, s(:@ident, "current_user", s(2, 8)))]
79
+ end
64
80
  end
65
81
  end
66
82
 
@@ -76,7 +92,11 @@ describe Sexp do
76
92
 
77
93
  it "should get first node with empty argument" do
78
94
  node = @node.grep_node(:sexp_type => :call, :subject => "current_user")
79
- node.should == s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
95
+ if RUBY_VERSION == "1.9.2"
96
+ node.should == s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
97
+ else
98
+ node.should == s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
99
+ end
80
100
  end
81
101
  end
82
102
 
@@ -525,6 +545,11 @@ describe Sexp do
525
545
  node = parse_content("{first_name: 'Richard'}").grep_node(:sexp_type => :@label)
526
546
  node.to_s.should == "first_name"
527
547
  end
548
+
549
+ it "should get to_s for call" do
550
+ node = parse_content("current_user.post").grep_node(:sexp_type => :call)
551
+ node.to_s.should == "current_user.post"
552
+ end
528
553
  end
529
554
 
530
555
  describe "const?" do
@@ -1,39 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Lexicals::RemoveTabCheck do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:lexicals => RailsBestPractices::Lexicals::RemoveTabCheck.new) }
3
+ module RailsBestPractices
4
+ module Lexicals
5
+ describe RemoveTabCheck do
6
+ let(:runner) { Core::Runner.new(:lexicals => RemoveTabCheck.new) }
5
7
 
6
- it "should remove tab" do
7
- content =<<-EOF
8
- class User < ActiveRecord::Base
9
- has_many :projects
10
- end
11
- EOF
12
- content.gsub!("\n", "\t\n")
13
- runner.lexical('app/models/user.rb', content)
14
- runner.should have(1).errors
15
- runner.errors[0].to_s.should == "app/models/user.rb:1 - remove tab, use spaces instead"
16
- end
8
+ it "should remove tab" do
9
+ content =<<-EOF
10
+ class User < ActiveRecord::Base
11
+ has_many :projects
12
+ end
13
+ EOF
14
+ content.gsub!("\n", "\t\n")
15
+ runner.lexical('app/models/user.rb', content)
16
+ runner.should have(1).errors
17
+ runner.errors[0].to_s.should == "app/models/user.rb:1 - remove tab, use spaces instead"
18
+ end
17
19
 
18
- it "should remove tab with third line" do
19
- content =<<-EOF
20
- class User < ActiveRecord::Base
21
- has_many :projects
22
- \t
23
- end
24
- EOF
25
- runner.lexical('app/models/user.rb', content)
26
- runner.should have(1).errors
27
- runner.errors[0].to_s.should == "app/models/user.rb:3 - remove tab, use spaces instead"
28
- end
20
+ it "should remove tab with third line" do
21
+ content =<<-EOF
22
+ class User < ActiveRecord::Base
23
+ has_many :projects
24
+ \t
25
+ end
26
+ EOF
27
+ runner.lexical('app/models/user.rb', content)
28
+ runner.should have(1).errors
29
+ runner.errors[0].to_s.should == "app/models/user.rb:3 - remove tab, use spaces instead"
30
+ end
29
31
 
30
- it "should not remove trailing whitespace" do
31
- content =<<-EOF
32
- class User < ActiveRecord::Base
33
- has_many :projects
32
+ it "should not remove trailing whitespace" do
33
+ content =<<-EOF
34
+ class User < ActiveRecord::Base
35
+ has_many :projects
36
+ end
37
+ EOF
38
+ runner.lexical('app/models/user.rb', content)
39
+ runner.should have(0).errors
40
+ end
34
41
  end
35
- EOF
36
- runner.lexical('app/models/user.rb', content)
37
- runner.should have(0).errors
38
42
  end
39
43
  end
@@ -1,39 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Lexicals::RemoveTrailingWhitespaceCheck do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:lexicals => RailsBestPractices::Lexicals::RemoveTrailingWhitespaceCheck.new) }
3
+ module RailsBestPractices
4
+ module Lexicals
5
+ describe RemoveTrailingWhitespaceCheck do
6
+ let(:runner) { Core::Runner.new(:lexicals => RemoveTrailingWhitespaceCheck.new) }
5
7
 
6
- it "should remove trailing whitespace" do
7
- content =<<-EOF
8
- class User < ActiveRecord::Base
9
- has_many :projects
10
- end
11
- EOF
12
- content.gsub!("\n", " \n")
13
- runner.lexical('app/models/user.rb', content)
14
- runner.should have(1).errors
15
- runner.errors[0].to_s.should == "app/models/user.rb:1 - remove trailing whitespace"
16
- end
8
+ it "should remove trailing whitespace" do
9
+ content =<<-EOF
10
+ class User < ActiveRecord::Base
11
+ has_many :projects
12
+ end
13
+ EOF
14
+ content.gsub!("\n", " \n")
15
+ runner.lexical('app/models/user.rb', content)
16
+ runner.should have(1).errors
17
+ runner.errors[0].to_s.should == "app/models/user.rb:1 - remove trailing whitespace"
18
+ end
17
19
 
18
- it "should remove whitespace with third line" do
19
- content =<<-EOF
20
- class User < ActiveRecord::Base
21
- has_many :projects
22
- end
23
- EOF
24
- content.gsub!("d\n", "d \n")
25
- runner.lexical('app/models/user.rb', content)
26
- runner.should have(1).errors
27
- runner.errors[0].to_s.should == "app/models/user.rb:3 - remove trailing whitespace"
28
- end
20
+ it "should remove whitespace with third line" do
21
+ content =<<-EOF
22
+ class User < ActiveRecord::Base
23
+ has_many :projects
24
+ end
25
+ EOF
26
+ content.gsub!("d\n", "d \n")
27
+ runner.lexical('app/models/user.rb', content)
28
+ runner.should have(1).errors
29
+ runner.errors[0].to_s.should == "app/models/user.rb:3 - remove trailing whitespace"
30
+ end
29
31
 
30
- it "should not remove trailing whitespace" do
31
- content =<<-EOF
32
- class User < ActiveRecord::Base
33
- has_many :projects
32
+ it "should not remove trailing whitespace" do
33
+ content =<<-EOF
34
+ class User < ActiveRecord::Base
35
+ has_many :projects
36
+ end
37
+ EOF
38
+ runner.lexical('app/models/user.rb', content)
39
+ runner.should have(0).errors
40
+ end
34
41
  end
35
- EOF
36
- runner.lexical('app/models/user.rb', content)
37
- runner.should have(0).errors
38
42
  end
39
43
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module RailsBestPractices
4
+ module Prepares
5
+ describe ConfigPrepare do
6
+ let(:runner) { Core::Runner.new(:prepares => ConfigPrepare.new) }
7
+
8
+ context "configs" do
9
+ it "should parse configs" do
10
+ content =<<-EOF
11
+ module RailsBestPracticesCom
12
+ class Application < Rails::Application
13
+ config.active_record.whitelist_attributes = true
14
+ end
15
+ end
16
+ EOF
17
+ runner.prepare('config/application.rb', content)
18
+ configs = Prepares.configs
19
+ configs["config.active_record.whitelist_attributes"].should == "true"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,146 +1,145 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Prepares::ControllerPrepare do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(
5
- :prepares => [RailsBestPractices::Prepares::ControllerPrepare.new, RailsBestPractices::Prepares::HelperPrepare.new]
6
- ) }
3
+ module RailsBestPractices
4
+ module Prepares
5
+ describe ControllerPrepare do
6
+ let(:runner) { Core::Runner.new(:prepares => [ControllerPrepare.new, HelperPrepare.new]) }
7
+ before(:each) { runner.whiny = true }
7
8
 
8
- before :each do
9
- runner.whiny = true
10
- end
11
-
12
- context "methods" do
13
- it "should parse controller methods" do
14
- content =<<-EOF
15
- class PostsController < ApplicationController
16
- def index; end
17
- def show; 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").map(&:method_name).should == ["index", "show"]
23
- end
24
-
25
- it "should parse model methods with access control" do
26
- content =<<-EOF
27
- class PostsController < ApplicationController
28
- def index; end
29
- def show; end
30
- protected
31
- def resources; end
32
- private
33
- def resource; end
34
- end
35
- EOF
36
- runner.prepare('app/controllers/posts_controller.rb', content)
37
- methods = RailsBestPractices::Prepares.controller_methods
38
- methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "resources", "resource"]
39
- methods.get_methods("PostsController", "public").map(&:method_name).should == ["index", "show"]
40
- methods.get_methods("PostsController", "protected").map(&:method_name).should == ["resources"]
41
- methods.get_methods("PostsController", "private").map(&:method_name).should == ["resource"]
42
- end
43
-
44
- it "should parse controller methods with module ::" do
45
- content =<<-EOF
46
- class Admin::Blog::PostsController < ApplicationController
47
- def index; end
48
- def show; end
49
- end
50
- EOF
51
- runner.prepare('app/controllers/admin/posts_controller.rb', content)
52
- methods = RailsBestPractices::Prepares.controller_methods
53
- methods.get_methods("Admin::Blog::PostsController").map(&:method_name).should == ["index", "show"]
54
- end
55
-
56
- it "should parse controller methods with module" do
57
- content =<<-EOF
58
- module Admin
59
- module Blog
9
+ context "methods" do
10
+ it "should parse controller methods" do
11
+ content =<<-EOF
60
12
  class PostsController < ApplicationController
61
13
  def index; end
62
14
  def show; end
63
15
  end
16
+ EOF
17
+ runner.prepare('app/controllers/posts_controller.rb', content)
18
+ methods = Prepares.controller_methods
19
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show"]
64
20
  end
65
- end
66
- EOF
67
- runner.prepare('app/controllers/admin/posts_controller.rb', content)
68
- methods = RailsBestPractices::Prepares.controller_methods
69
- methods.get_methods("Admin::Blog::PostsController").map(&:method_name).should == ["index", "show"]
70
- end
71
21
 
72
- context "inherited_resources" do
73
- it "extend inherited_resources" do
74
- content =<<-EOF
75
- class PostsController < InheritedResources::Base
22
+ it "should parse model methods with access control" do
23
+ content =<<-EOF
24
+ class PostsController < ApplicationController
25
+ def index; end
26
+ def show; end
27
+ protected
28
+ def resources; end
29
+ private
30
+ def resource; end
31
+ end
32
+ EOF
33
+ runner.prepare('app/controllers/posts_controller.rb', content)
34
+ methods = Prepares.controller_methods
35
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "resources", "resource"]
36
+ methods.get_methods("PostsController", "public").map(&:method_name).should == ["index", "show"]
37
+ methods.get_methods("PostsController", "protected").map(&:method_name).should == ["resources"]
38
+ methods.get_methods("PostsController", "private").map(&:method_name).should == ["resource"]
76
39
  end
77
- EOF
78
- runner.prepare('app/controllers/posts_controller.rb', content)
79
- methods = RailsBestPractices::Prepares.controller_methods
80
- methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
81
- end
82
40
 
83
- it "extend inherited_resources with actions" do
84
- content =<<-EOF
85
- class PostsController < InheritedResources::Base
86
- actions :index, :show
41
+ it "should parse controller methods with module ::" do
42
+ content =<<-EOF
43
+ class Admin::Blog::PostsController < ApplicationController
44
+ def index; end
45
+ def show; end
46
+ end
47
+ EOF
48
+ runner.prepare('app/controllers/admin/posts_controller.rb', content)
49
+ methods = Prepares.controller_methods
50
+ methods.get_methods("Admin::Blog::PostsController").map(&:method_name).should == ["index", "show"]
87
51
  end
88
- EOF
89
- runner.prepare('app/controllers/posts_controller.rb', content)
90
- methods = RailsBestPractices::Prepares.controller_methods
91
- methods.get_methods("PostsController").map(&:method_name).should == ["index", "show"]
92
- end
93
52
 
94
- it "extend inherited_resources with all actions" do
95
- content =<<-EOF
96
- class PostsController < InheritedResources::Base
97
- actions :all, except: [:show]
53
+ it "should parse controller methods with module" do
54
+ content =<<-EOF
55
+ module Admin
56
+ module Blog
57
+ class PostsController < ApplicationController
58
+ def index; end
59
+ def show; end
60
+ end
61
+ end
62
+ end
63
+ EOF
64
+ runner.prepare('app/controllers/admin/posts_controller.rb', content)
65
+ methods = Prepares.controller_methods
66
+ methods.get_methods("Admin::Blog::PostsController").map(&:method_name).should == ["index", "show"]
98
67
  end
99
- EOF
100
- runner.prepare('app/controllers/posts_controller.rb', content)
101
- methods = RailsBestPractices::Prepares.controller_methods
102
- methods.get_methods("PostsController").map(&:method_name).should == ["index", "new", "create", "edit", "update", "destroy"]
103
- end
104
68
 
105
- it "extend inherited_resources with all actions with no arguments" do
106
- content =<<-EOF
107
- class PostsController < InheritedResources::Base
108
- actions :all
109
- end
110
- EOF
111
- runner.prepare('app/controllers/posts_controller.rb', content)
112
- methods = RailsBestPractices::Prepares.controller_methods
113
- methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
114
- end
69
+ context "inherited_resources" do
70
+ it "extend inherited_resources" do
71
+ content =<<-EOF
72
+ class PostsController < InheritedResources::Base
73
+ end
74
+ EOF
75
+ runner.prepare('app/controllers/posts_controller.rb', content)
76
+ methods = Prepares.controller_methods
77
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
78
+ end
79
+
80
+ it "extend inherited_resources with actions" do
81
+ content =<<-EOF
82
+ class PostsController < InheritedResources::Base
83
+ actions :index, :show
84
+ end
85
+ EOF
86
+ runner.prepare('app/controllers/posts_controller.rb', content)
87
+ methods = Prepares.controller_methods
88
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show"]
89
+ end
90
+
91
+ it "extend inherited_resources with all actions" do
92
+ content =<<-EOF
93
+ class PostsController < InheritedResources::Base
94
+ actions :all, except: [:show]
95
+ end
96
+ EOF
97
+ runner.prepare('app/controllers/posts_controller.rb', content)
98
+ methods = Prepares.controller_methods
99
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "new", "create", "edit", "update", "destroy"]
100
+ end
101
+
102
+ it "extend inherited_resources with all actions with no arguments" do
103
+ content =<<-EOF
104
+ class PostsController < InheritedResources::Base
105
+ actions :all
106
+ end
107
+ EOF
108
+ runner.prepare('app/controllers/posts_controller.rb', content)
109
+ methods = Prepares.controller_methods
110
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
111
+ end
115
112
 
116
- it "DSL inherit_resources" do
117
- content =<<-EOF
118
- class PostsController
119
- inherit_resources
113
+ it "DSL inherit_resources" do
114
+ content =<<-EOF
115
+ class PostsController
116
+ inherit_resources
117
+ end
118
+ EOF
119
+ runner.prepare('app/controllers/posts_controller.rb', content)
120
+ methods = Prepares.controller_methods
121
+ methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
122
+ end
120
123
  end
121
- EOF
122
- runner.prepare('app/controllers/posts_controller.rb', content)
123
- methods = RailsBestPractices::Prepares.controller_methods
124
- methods.get_methods("PostsController").map(&:method_name).should == ["index", "show", "new", "create", "edit", "update", "destroy"]
125
124
  end
126
- end
127
- end
128
125
 
129
- context "helpers" do
130
- it "should add helper decendant" do
131
- content =<<-EOF
132
- module PostsHelper
133
- end
134
- EOF
135
- runner.prepare('app/helpers/posts_helper.rb', content)
136
- content =<<-EOF
137
- class PostsController
138
- include PostsHelper
126
+ context "helpers" do
127
+ it "should add helper decendant" do
128
+ content =<<-EOF
129
+ module PostsHelper
130
+ end
131
+ EOF
132
+ runner.prepare('app/helpers/posts_helper.rb', content)
133
+ content =<<-EOF
134
+ class PostsController
135
+ include PostsHelper
136
+ end
137
+ EOF
138
+ runner.prepare('app/controllers/posts_controller.rb', content)
139
+ helpers = Prepares.helpers
140
+ helpers.first.decendants.should == ["PostsController"]
141
+ end
139
142
  end
140
- EOF
141
- runner.prepare('app/controllers/posts_controller.rb', content)
142
- helpers = RailsBestPractices::Prepares.helpers
143
- helpers.first.decendants.should == ["PostsController"]
144
143
  end
145
144
  end
146
145
  end