rails_best_practices 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ module RailsBestPractices
15
15
  # 2. review process, it does real check, if the source code violates some best practices, the violations will be notified.
16
16
  class Runner
17
17
  attr_reader :checks
18
- attr_accessor :debug, :color
18
+ attr_accessor :debug, :whiny, :color
19
19
 
20
20
  # set the base path.
21
21
  #
@@ -48,6 +48,7 @@ module RailsBestPractices
48
48
 
49
49
  @checker ||= CheckingVisitor.new(:prepares => @prepares, :reviews => @reviews, :lexicals => @lexicals)
50
50
  @debug = false
51
+ @whiny = false
51
52
  end
52
53
 
53
54
  # lexical analysis the file.
@@ -107,6 +108,7 @@ module RailsBestPractices
107
108
  warning = warning.red if self.color
108
109
  puts warning
109
110
  end
111
+ raise e if @whiny
110
112
  nil
111
113
  end
112
114
  end
@@ -50,9 +50,10 @@ module RailsBestPractices
50
50
  def remember_association(association_node)
51
51
  association_meta = association_node.message
52
52
  association_name = association_node.arguments[1].to_s
53
- if association_node.arguments[2] && :hash == association_node.arguments[2].node_type
54
- association_options = eval(association_node.arguments[2].to_s)
55
- association_class = association_options["class_name"]
53
+ arguments_node = association_node.arguments[2]
54
+ if arguments_node && :hash == arguments_node.node_type
55
+ index = arguments_node.index(s(:lit, :class_name))
56
+ association_class = arguments_node[index + 1].to_s if index
56
57
  end
57
58
  @model_associations.add_association(@last_klazz, association_name, association_meta, association_class)
58
59
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "0.7.2"
3
+ VERSION = "0.7.3"
4
4
  end
5
5
 
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
  describe RailsBestPractices::Prepares::ModelPrepare do
4
4
  let(:runner) { RailsBestPractices::Core::Runner.new(:prepares => RailsBestPractices::Prepares::ModelPrepare.new) }
5
5
 
6
+ before :each do
7
+ runner.whiny = true
8
+ end
9
+
6
10
  it "should parse model associations" do
7
11
  content =<<-EOF
8
12
  class Project < ActiveRecord::Base
@@ -20,6 +24,16 @@ describe RailsBestPractices::Prepares::ModelPrepare do
20
24
  model_associations.get_association("Project", "categories").should == {:meta => :has_and_belongs_to_many, :class_name => "Category"}
21
25
  end
22
26
 
27
+ it "should not raise error for finder_sql option" do
28
+ content =<<-EOF
29
+ class EventSubscription < ActiveRecord::Base
30
+ has_many :event_notification_template, :finder_sql => ?
31
+ end
32
+ EOF
33
+ content.sub!('?', '\'SELECT event_notification_templates.* from event_notification_templates where event_type_id=#{event_type_id} and delivery_method_id=#{delivery_method_id}\'')
34
+ lambda { runner.prepare('app/models/event_subscription.rb', content) }.should_not raise_error
35
+ end
36
+
23
37
  context "class_name" do
24
38
  it "should parse belongs_to" do
25
39
  content =<<-EOF
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 2
10
- version: 0.7.2
9
+ - 3
10
+ version: 0.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang
@@ -15,12 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 +08:00
18
+ date: 2011-03-23 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :runtime
24
22
  requirement: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
@@ -32,11 +30,11 @@ dependencies:
32
30
  - 0
33
31
  - 4
34
32
  version: 2.0.4
33
+ prerelease: false
35
34
  version_requirements: *id001
35
+ type: :runtime
36
36
  name: ruby_parser
37
37
  - !ruby/object:Gem::Dependency
38
- prerelease: false
39
- type: :runtime
40
38
  requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
@@ -48,11 +46,11 @@ dependencies:
48
46
  - 0
49
47
  - 9
50
48
  version: 0.0.9
49
+ prerelease: false
51
50
  version_requirements: *id002
51
+ type: :runtime
52
52
  name: ruby-progressbar
53
53
  - !ruby/object:Gem::Dependency
54
- prerelease: false
55
- type: :runtime
56
54
  requirement: &id003 !ruby/object:Gem::Requirement
57
55
  none: false
58
56
  requirements:
@@ -63,11 +61,11 @@ dependencies:
63
61
  - 1
64
62
  - 2
65
63
  version: "1.2"
64
+ prerelease: false
66
65
  version_requirements: *id003
66
+ type: :runtime
67
67
  name: colored
68
68
  - !ruby/object:Gem::Dependency
69
- prerelease: false
70
- type: :runtime
71
69
  requirement: &id004 !ruby/object:Gem::Requirement
72
70
  none: false
73
71
  requirements:
@@ -79,11 +77,11 @@ dependencies:
79
77
  - 6
80
78
  - 6
81
79
  version: 2.6.6
80
+ prerelease: false
82
81
  version_requirements: *id004
82
+ type: :runtime
83
83
  name: erubis
84
84
  - !ruby/object:Gem::Dependency
85
- prerelease: false
86
- type: :runtime
87
85
  requirement: &id005 !ruby/object:Gem::Requirement
88
86
  none: false
89
87
  requirements:
@@ -95,11 +93,11 @@ dependencies:
95
93
  - 0
96
94
  - 18
97
95
  version: 3.0.18
96
+ prerelease: false
98
97
  version_requirements: *id005
98
+ type: :runtime
99
99
  name: haml
100
100
  - !ruby/object:Gem::Dependency
101
- prerelease: false
102
- type: :runtime
103
101
  requirement: &id006 !ruby/object:Gem::Requirement
104
102
  none: false
105
103
  requirements:
@@ -109,11 +107,11 @@ dependencies:
109
107
  segments:
110
108
  - 0
111
109
  version: "0"
110
+ prerelease: false
112
111
  version_requirements: *id006
112
+ type: :runtime
113
113
  name: i18n
114
114
  - !ruby/object:Gem::Dependency
115
- prerelease: false
116
- type: :runtime
117
115
  requirement: &id007 !ruby/object:Gem::Requirement
118
116
  none: false
119
117
  requirements:
@@ -123,11 +121,11 @@ dependencies:
123
121
  segments:
124
122
  - 0
125
123
  version: "0"
124
+ prerelease: false
126
125
  version_requirements: *id007
126
+ type: :runtime
127
127
  name: activesupport
128
128
  - !ruby/object:Gem::Dependency
129
- prerelease: false
130
- type: :development
131
129
  requirement: &id008 !ruby/object:Gem::Requirement
132
130
  none: false
133
131
  requirements:
@@ -137,11 +135,11 @@ dependencies:
137
135
  segments:
138
136
  - 0
139
137
  version: "0"
138
+ prerelease: false
140
139
  version_requirements: *id008
140
+ type: :development
141
141
  name: rake
142
142
  - !ruby/object:Gem::Dependency
143
- prerelease: false
144
- type: :development
145
143
  requirement: &id009 !ruby/object:Gem::Requirement
146
144
  none: false
147
145
  requirements:
@@ -153,11 +151,11 @@ dependencies:
153
151
  - 4
154
152
  - 0
155
153
  version: 2.4.0
154
+ prerelease: false
156
155
  version_requirements: *id009
156
+ type: :development
157
157
  name: rspec
158
158
  - !ruby/object:Gem::Dependency
159
- prerelease: false
160
- type: :development
161
159
  requirement: &id010 !ruby/object:Gem::Requirement
162
160
  none: false
163
161
  requirements:
@@ -168,11 +166,11 @@ dependencies:
168
166
  - 0
169
167
  - 6
170
168
  version: "0.6"
169
+ prerelease: false
171
170
  version_requirements: *id010
171
+ type: :development
172
172
  name: watchr
173
173
  - !ruby/object:Gem::Dependency
174
- prerelease: false
175
- type: :development
176
174
  requirement: &id011 !ruby/object:Gem::Requirement
177
175
  none: false
178
176
  requirements:
@@ -184,7 +182,9 @@ dependencies:
184
182
  - 0
185
183
  - 0
186
184
  version: 1.0.0
185
+ prerelease: false
187
186
  version_requirements: *id011
187
+ type: :development
188
188
  name: bundler
189
189
  description: a code metric tool for rails codes, written in Ruby.
190
190
  email:
@@ -339,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
339
339
  requirements: []
340
340
 
341
341
  rubyforge_project:
342
- rubygems_version: 1.5.2
342
+ rubygems_version: 1.4.2
343
343
  signing_key:
344
344
  specification_version: 3
345
345
  summary: a code metric tool for rails codes.