rails_best_practices 0.2.5 → 0.2.6

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -33,7 +33,9 @@ module RailsBestPractices
33
33
  private
34
34
 
35
35
  def remember_callbacks(node)
36
- @callbacks << eval(node.arguments.to_ruby).to_s
36
+ node.arguments[1..-1].each do |argument|
37
+ @callbacks << eval(argument.to_ruby).to_s
38
+ end
37
39
  end
38
40
 
39
41
  def use_observer?(node)
@@ -1,11 +1,12 @@
1
1
  require 'optparse'
2
2
 
3
3
  def expand_dirs_to_files *dirs
4
+ # extensions = ['rb', 'erb', 'builder']
4
5
  extensions = ['rb', 'builder']
5
6
 
6
7
  dirs.flatten.map { |p|
7
8
  if File.directory? p
8
- Dir[File.join(p, '**', "*{#{extensions.join(',')}}")]
9
+ Dir[File.join(p, '**', "*.{#{extensions.join(',')}}")]
9
10
  else
10
11
  p
11
12
  end
@@ -27,6 +28,10 @@ def add_duplicate_migration_files files
27
28
  (files << migration_files).flatten
28
29
  end
29
30
 
31
+ def ignore_vendor_directories files
32
+ files.reject { |file| file.index("vendor/") }
33
+ end
34
+
30
35
  options = {}
31
36
  OptionParser.new do |opts|
32
37
  opts.banner = "Usage: rails_best_practices [options]"
@@ -40,7 +45,7 @@ OptionParser.new do |opts|
40
45
  end
41
46
 
42
47
  runner = RailsBestPractices::Core::Runner.new
43
- add_duplicate_migration_files(expand_dirs_to_files(ARGV)).each { |file| runner.check_file(file) }
48
+ ignore_vendor_directories(add_duplicate_migration_files(expand_dirs_to_files(ARGV))).each { |file| runner.check_file(file) }
44
49
  runner.errors.each {|error| puts error}
45
50
  puts "\nFound #{runner.errors.size} errors."
46
51
 
@@ -49,7 +49,7 @@ module RailsBestPractices
49
49
  begin
50
50
  @parser.parse(content, filename)
51
51
  rescue Exception => e
52
- puts "#{filename} looks like it's not a valid Ruby file. Skipping..." if ENV["ROODI_DEBUG"]
52
+ puts "#{filename} looks like it's not a valid Ruby file. Skipping..."
53
53
  nil
54
54
  end
55
55
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_best_practices}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
@@ -41,4 +41,27 @@ describe RailsBestPractices::Checks::UseObserverCheck do
41
41
  errors = @runner.errors
42
42
  errors.should be_empty
43
43
  end
44
+
45
+ it "should use observer with two after_create" do
46
+ content =<<-EOF
47
+ class Project < ActiveRecord::Base
48
+ after_create :send_create_notification, :update_author
49
+
50
+ private
51
+
52
+ def send_create_notification
53
+ self.members.each do |member|
54
+ ProjectMailer.deliver_notification(self, member)
55
+ end
56
+ end
57
+
58
+ def update_author
59
+ end
60
+ end
61
+ EOF
62
+ @runner.check('app/models/project.rb', content)
63
+ errors = @runner.errors
64
+ errors.should_not be_empty
65
+ errors[0].to_s.should == "app/models/project.rb:6 - use observer"
66
+ end
44
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang