instructure-marginalia 1.1.3 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 412b0d5c9d4e67775eddfadc06b23cf0cffd4590
4
+ data.tar.gz: 69b196fda9c7a270da2d4b69d68139af458839cd
5
+ SHA512:
6
+ metadata.gz: b8d717d6ac49cff823ac18e7f5c625221a61052540673f418d9d0037c356c5d64013a2c23886c0edb8fea5b8bd92e9d4d12b8d4f09e82d811f11c114e5bce54a
7
+ data.tar.gz: 821d4ca7ba4833cc1296d5de71ad14dad7eca4eef490b9ef9ae8b598f2345dfa89156e26dfe96995075f4c5d012ab8723d8d0ae54b062918befc0ba4b94be8df
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  tmp
4
4
  marginalia_test
5
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ 2.1.2
@@ -1,6 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
6
  script: bundle exec rake db:reset test:all
7
+ env:
8
+ - "RAILS_VERSION=3.1.12"
9
+ - "RAILS_VERSION=3.2.19"
10
+ - "RAILS_VERSION=4.0.8"
data/Gemfile CHANGED
@@ -1,3 +1,14 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ version = ENV["RAILS_VERSION"] || "4.0.2"
6
+
7
+ rails = case version
8
+ when "master"
9
+ {:github => "rails/rails"}
10
+ else
11
+ "~> #{version}"
12
+ end
13
+
14
+ gem "rails", rails
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # marginalia [![Build Status](https://secure.travis-ci.org/37signals/marginalia.png?branch=master)](http://travis-ci.org/37signals/marginalia)
1
+ # marginalia [![Build Status](https://travis-ci.org/basecamp/marginalia.svg?branch=master)](https://travis-ci.org/basecamp/marginalia)
2
2
 
3
3
  Attach comments to your ActiveRecord queries. By default, it adds the application, controller, and action names as a
4
4
  comment at the end of each query.
@@ -19,23 +19,18 @@ This gem was created at 37signals. You can read more about how we use it [on
19
19
  our blog](http://37signals.com/svn/posts/3130-tech-note-mysql-query-comments-in-rails).
20
20
 
21
21
  This has been tested and used in production with both the mysql and mysql2 gems,
22
- tested on Rails 2.3.5 through 3.2-stable. It has also been tested for sqlite3 and postgres.
22
+ tested on Rails 2.3.5 through 4.0-stable. It has also been tested for sqlite3 and postgres.
23
23
 
24
24
  Patches are welcome for other database adapters.
25
25
 
26
- **The preferred way to get support is to send an email to
27
- marginalia@librelist.com. Github issues
28
- and pull requests will be checked occassionally, but email is the
29
- fastest way to get help.**
30
-
31
26
  ## Installation
32
27
 
33
- ### For Rails 3.x:
28
+ ### For Rails 3.x and 4.0:
34
29
 
35
30
  # Gemfile
36
31
  gem 'marginalia'
37
32
 
38
- #config/application.rb
33
+ # config/application.rb
39
34
  require 'marginalia/railtie'
40
35
 
41
36
 
@@ -8,21 +8,41 @@ module Marginalia
8
8
  def self.included(instrumented_class)
9
9
  Marginalia::Comment.components = [:application, :controller, :action]
10
10
  instrumented_class.class_eval do
11
- if method_defined? :execute
11
+ if instrumented_class.method_defined?(:execute)
12
12
  alias_method :execute_without_marginalia, :execute
13
13
  alias_method :execute, :execute_with_marginalia
14
14
  end
15
15
 
16
- if method_defined? :exec_query
17
- alias_method :exec_query_without_marginalia, :exec_query
18
- alias_method :exec_query, :exec_query_with_marginalia
16
+ is_mysql2 = defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) &&
17
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter == instrumented_class
18
+ # Dont instrument exec_query on mysql2 and AR 3.2+, as it calls execute internally
19
+ unless is_mysql2 && ActiveRecord::VERSION::STRING > "3.1"
20
+ if instrumented_class.method_defined?(:exec_query)
21
+ alias_method :exec_query_without_marginalia, :exec_query
22
+ alias_method :exec_query, :exec_query_with_marginalia
23
+ end
24
+ end
25
+
26
+ is_postgres = defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
27
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter == instrumented_class
28
+ # Instrument exec_delete and exec_update on AR 3.2+, since they don't
29
+ # call execute internally
30
+ if is_postgres && ActiveRecord::VERSION::STRING > "3.1"
31
+ if instrumented_class.method_defined?(:exec_delete)
32
+ alias_method :exec_delete_without_marginalia, :exec_delete
33
+ alias_method :exec_delete, :exec_delete_with_marginalia
34
+ end
35
+ if instrumented_class.method_defined?(:exec_update)
36
+ alias_method :exec_update_without_marginalia, :exec_update
37
+ alias_method :exec_update, :exec_update_with_marginalia
38
+ end
19
39
  end
20
40
  end
21
41
  end
22
42
 
23
43
  def annotate_sql(sql)
24
44
  comment = Marginalia::Comment.construct_comment
25
- if comment.present? && !sql.match(comment)
45
+ if comment.present? && !sql.include?(comment)
26
46
  "#{sql} /*#{comment}*/"
27
47
  else
28
48
  sql
@@ -36,6 +56,14 @@ module Marginalia
36
56
  def exec_query_with_marginalia(sql, name = 'SQL', binds = [])
37
57
  exec_query_without_marginalia(annotate_sql(sql), name, binds)
38
58
  end
59
+
60
+ def exec_delete_with_marginalia(sql, name = 'SQL', binds = [])
61
+ exec_delete_without_marginalia(annotate_sql(sql), name, binds)
62
+ end
63
+
64
+ def exec_update_with_marginalia(sql, name = 'SQL', binds = [])
65
+ exec_update_without_marginalia(annotate_sql(sql), name, binds)
66
+ end
39
67
  end
40
68
 
41
69
  end
@@ -13,10 +13,10 @@ module Marginalia
13
13
  self.components.each do |c|
14
14
  component_value = self.send(c)
15
15
  if component_value.present?
16
- ret << ',' if ret.present?
17
- ret << c.to_s << ':' << component_value.to_s
16
+ ret << "#{c.to_s}:#{component_value.to_s},"
18
17
  end
19
18
  end
19
+ ret.chop!
20
20
  ret
21
21
  end
22
22
 
@@ -40,11 +40,11 @@ module Marginalia
40
40
  end
41
41
 
42
42
  def self.action
43
- @controller.action_name if @controller.respond_to? :action_name
43
+ @controller.action_name if @controller.respond_to? :action_name
44
44
  end
45
45
 
46
46
  def self.line
47
- Marginalia::Comment.lines_to_ignore ||= /\.rvm|gem|vendor|marginalia|rbenv/
47
+ Marginalia::Comment.lines_to_ignore ||= /\.rvm|gem|vendor\/|marginalia|rbenv/
48
48
  last_line = caller.detect do |line|
49
49
  line !~ Marginalia::Comment.lines_to_ignore
50
50
  end
@@ -29,7 +29,7 @@ module Marginalia
29
29
  Marginalia::Comment.update!(self)
30
30
  yield
31
31
  ensure
32
- Marginalia::Comment.clear!
32
+ Marginalia::Comment.clear!
33
33
  end
34
34
  around_filter :record_query_comment
35
35
  end
@@ -61,9 +61,9 @@ module Marginalia
61
61
  end
62
62
  end
63
63
 
64
- if defined? ActiveRecord::ConnectionAdapters::SQLiteAdapter
65
- if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLiteAdapter)
66
- ActiveRecord::ConnectionAdapters::SQLiteAdapter.module_eval do
64
+ if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
65
+ if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
66
+ ActiveRecord::ConnectionAdapters::SQLite3Adapter.module_eval do
67
67
  include Marginalia::ActiveRecordInstrumentation
68
68
  end
69
69
  end
@@ -8,15 +8,17 @@ Gem::Specification.new do |gem|
8
8
  gem.test_files = `git ls-files -- {test}/*`.split("\n")
9
9
  gem.name = "instructure-marginalia"
10
10
  gem.require_paths = ["lib"]
11
- gem.version = "1.1.3"
11
+ gem.version = "1.1.6"
12
+ gem.license = "MIT"
12
13
 
13
- gem.add_runtime_dependency "actionpack", ">= 2.3", "< 3.3"
14
- gem.add_runtime_dependency "activerecord", ">= 2.3", "< 3.3"
14
+ gem.add_runtime_dependency "actionpack", ">= 2.3"
15
+ gem.add_runtime_dependency "activerecord", ">= 2.3"
15
16
  gem.add_development_dependency "rake"
16
17
  gem.add_development_dependency "mysql"
17
18
  gem.add_development_dependency "mysql2"
18
19
  gem.add_development_dependency "pg"
19
20
  gem.add_development_dependency "sqlite3"
21
+ gem.add_development_dependency "mocha"
20
22
 
21
- gem.summary = description = %q{Attach comments to your ActiveRecord queries.}
23
+ gem.summary = gem.description = %q{Attach comments to your ActiveRecord queries.}
22
24
  end
@@ -1,4 +1,6 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'test/unit'
3
+ require 'mocha/test_unit'
2
4
  require 'logger'
3
5
  require 'pp'
4
6
  require 'active_record'
@@ -41,11 +43,41 @@ class MarginaliaTest < Test::Unit::TestCase
41
43
  @env = Rack::MockRequest.env_for('/')
42
44
  end
43
45
 
46
+ def test_double_annotate
47
+ ActiveRecord::Base.connection.expects(:annotate_sql).returns("select id from posts").once
48
+ ActiveRecord::Base.connection.send(:select, "select id from posts")
49
+ ensure
50
+ ActiveRecord::Base.connection.unstub(:annotate_sql)
51
+ end
52
+
44
53
  def test_query_commenting_on_mysql_driver_with_no_action
45
54
  ActiveRecord::Base.connection.execute "select id from posts"
46
55
  assert_match %r{select id from posts /\*application:rails\*/$}, @queries.first
47
56
  end
48
57
 
58
+ if ENV["DRIVER"] =~ /^mysql/
59
+ def test_query_commenting_on_mysql_driver_with_binary_chars
60
+ ActiveRecord::Base.connection.execute "select id from posts /* \x81\x80\u0010\ */"
61
+ assert_equal "select id from posts /* \x81\x80\u0010 */ /*application:rails*/", @queries.first
62
+ end
63
+ end
64
+
65
+ if ENV["DRIVER"] =~ /^postgres/
66
+ def test_query_commenting_on_postgres_update
67
+ ActiveRecord::Base.connection.expects(:annotate_sql).returns("update posts set id = 1").once
68
+ ActiveRecord::Base.connection.send(:exec_update, "update posts set id = 1")
69
+ ensure
70
+ ActiveRecord::Base.connection.unstub(:annotate_sql)
71
+ end
72
+
73
+ def test_query_commenting_on_postgres_delete
74
+ ActiveRecord::Base.connection.expects(:annotate_sql).returns("delete from posts where id = 1").once
75
+ ActiveRecord::Base.connection.send(:exec_delete, "delete from posts where id = 1")
76
+ ensure
77
+ ActiveRecord::Base.connection.unstub(:annotate_sql)
78
+ end
79
+ end
80
+
49
81
  def test_query_commenting_on_mysql_driver_with_action
50
82
  PostsController.action(:driver_only).call(@env)
51
83
  assert_match %r{select id from posts /\*application:rails,controller:posts,action:driver_only\*/$}, @queries.first
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instructure-marginalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
5
- prerelease:
4
+ version: 1.1.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Noah Lorang
@@ -11,144 +10,131 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-04-08 00:00:00.000000000 Z
13
+ date: 2014-08-26 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: actionpack
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ! '>='
19
+ - - ">="
22
20
  - !ruby/object:Gem::Version
23
21
  version: '2.3'
24
- - - <
25
- - !ruby/object:Gem::Version
26
- version: '3.3'
27
22
  type: :runtime
28
23
  prerelease: false
29
24
  version_requirements: !ruby/object:Gem::Requirement
30
- none: false
31
25
  requirements:
32
- - - ! '>='
26
+ - - ">="
33
27
  - !ruby/object:Gem::Version
34
28
  version: '2.3'
35
- - - <
36
- - !ruby/object:Gem::Version
37
- version: '3.3'
38
29
  - !ruby/object:Gem::Dependency
39
30
  name: activerecord
40
31
  requirement: !ruby/object:Gem::Requirement
41
- none: false
42
32
  requirements:
43
- - - ! '>='
33
+ - - ">="
44
34
  - !ruby/object:Gem::Version
45
35
  version: '2.3'
46
- - - <
47
- - !ruby/object:Gem::Version
48
- version: '3.3'
49
36
  type: :runtime
50
37
  prerelease: false
51
38
  version_requirements: !ruby/object:Gem::Requirement
52
- none: false
53
39
  requirements:
54
- - - ! '>='
40
+ - - ">="
55
41
  - !ruby/object:Gem::Version
56
42
  version: '2.3'
57
- - - <
58
- - !ruby/object:Gem::Version
59
- version: '3.3'
60
43
  - !ruby/object:Gem::Dependency
61
44
  name: rake
62
45
  requirement: !ruby/object:Gem::Requirement
63
- none: false
64
46
  requirements:
65
- - - ! '>='
47
+ - - ">="
66
48
  - !ruby/object:Gem::Version
67
49
  version: '0'
68
50
  type: :development
69
51
  prerelease: false
70
52
  version_requirements: !ruby/object:Gem::Requirement
71
- none: false
72
53
  requirements:
73
- - - ! '>='
54
+ - - ">="
74
55
  - !ruby/object:Gem::Version
75
56
  version: '0'
76
57
  - !ruby/object:Gem::Dependency
77
58
  name: mysql
78
59
  requirement: !ruby/object:Gem::Requirement
79
- none: false
80
60
  requirements:
81
- - - ! '>='
61
+ - - ">="
82
62
  - !ruby/object:Gem::Version
83
63
  version: '0'
84
64
  type: :development
85
65
  prerelease: false
86
66
  version_requirements: !ruby/object:Gem::Requirement
87
- none: false
88
67
  requirements:
89
- - - ! '>='
68
+ - - ">="
90
69
  - !ruby/object:Gem::Version
91
70
  version: '0'
92
71
  - !ruby/object:Gem::Dependency
93
72
  name: mysql2
94
73
  requirement: !ruby/object:Gem::Requirement
95
- none: false
96
74
  requirements:
97
- - - ! '>='
75
+ - - ">="
98
76
  - !ruby/object:Gem::Version
99
77
  version: '0'
100
78
  type: :development
101
79
  prerelease: false
102
80
  version_requirements: !ruby/object:Gem::Requirement
103
- none: false
104
81
  requirements:
105
- - - ! '>='
82
+ - - ">="
106
83
  - !ruby/object:Gem::Version
107
84
  version: '0'
108
85
  - !ruby/object:Gem::Dependency
109
86
  name: pg
110
87
  requirement: !ruby/object:Gem::Requirement
111
- none: false
112
88
  requirements:
113
- - - ! '>='
89
+ - - ">="
114
90
  - !ruby/object:Gem::Version
115
91
  version: '0'
116
92
  type: :development
117
93
  prerelease: false
118
94
  version_requirements: !ruby/object:Gem::Requirement
119
- none: false
120
95
  requirements:
121
- - - ! '>='
96
+ - - ">="
122
97
  - !ruby/object:Gem::Version
123
98
  version: '0'
124
99
  - !ruby/object:Gem::Dependency
125
100
  name: sqlite3
126
101
  requirement: !ruby/object:Gem::Requirement
127
- none: false
128
102
  requirements:
129
- - - ! '>='
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: mocha
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
130
118
  - !ruby/object:Gem::Version
131
119
  version: '0'
132
120
  type: :development
133
121
  prerelease: false
134
122
  version_requirements: !ruby/object:Gem::Requirement
135
- none: false
136
123
  requirements:
137
- - - ! '>='
124
+ - - ">="
138
125
  - !ruby/object:Gem::Version
139
126
  version: '0'
140
- description:
127
+ description: Attach comments to your ActiveRecord queries.
141
128
  email:
142
129
  - noah@37signals.com
143
130
  executables: []
144
131
  extensions: []
145
132
  extra_rdoc_files: []
146
133
  files:
147
- - .gitignore
148
- - .rbenv-version
149
- - .travis.yml
134
+ - ".gitignore"
135
+ - ".ruby-version"
136
+ - ".travis.yml"
150
137
  - Gemfile
151
- - Gemfile.lock
152
138
  - LICENSE
153
139
  - README.md
154
140
  - Rakefile
@@ -159,27 +145,28 @@ files:
159
145
  - marginalia.gemspec
160
146
  - test/query_comments_test.rb
161
147
  homepage: https://github.com/37signals/marginalia
162
- licenses: []
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
163
151
  post_install_message:
164
152
  rdoc_options: []
165
153
  require_paths:
166
154
  - lib
167
155
  required_ruby_version: !ruby/object:Gem::Requirement
168
- none: false
169
156
  requirements:
170
- - - ! '>='
157
+ - - ">="
171
158
  - !ruby/object:Gem::Version
172
159
  version: '0'
173
160
  required_rubygems_version: !ruby/object:Gem::Requirement
174
- none: false
175
161
  requirements:
176
- - - ! '>='
162
+ - - ">="
177
163
  - !ruby/object:Gem::Version
178
164
  version: '0'
179
165
  requirements: []
180
166
  rubyforge_project:
181
- rubygems_version: 1.8.23
167
+ rubygems_version: 2.3.0
182
168
  signing_key:
183
- specification_version: 3
169
+ specification_version: 4
184
170
  summary: Attach comments to your ActiveRecord queries.
185
171
  test_files: []
172
+ has_rdoc:
@@ -1 +0,0 @@
1
- 1.9.3-p0
@@ -1,67 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- marginalia (1.1.0)
5
- actionpack (>= 2.3, < 3.3)
6
- activerecord (>= 2.3, < 3.3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (3.1.3)
12
- activemodel (= 3.1.3)
13
- activesupport (= 3.1.3)
14
- builder (~> 3.0.0)
15
- erubis (~> 2.7.0)
16
- i18n (~> 0.6)
17
- rack (~> 1.3.5)
18
- rack-cache (~> 1.1)
19
- rack-mount (~> 0.8.2)
20
- rack-test (~> 0.6.1)
21
- sprockets (~> 2.0.3)
22
- activemodel (3.1.3)
23
- activesupport (= 3.1.3)
24
- builder (~> 3.0.0)
25
- i18n (~> 0.6)
26
- activerecord (3.1.3)
27
- activemodel (= 3.1.3)
28
- activesupport (= 3.1.3)
29
- arel (~> 2.2.1)
30
- tzinfo (~> 0.3.29)
31
- activesupport (3.1.3)
32
- multi_json (~> 1.0)
33
- arel (2.2.1)
34
- builder (3.0.0)
35
- erubis (2.7.0)
36
- hike (1.2.1)
37
- i18n (0.6.0)
38
- multi_json (1.1.0)
39
- mysql (2.8.1)
40
- mysql2 (0.3.11)
41
- pg (0.13.2)
42
- rack (1.3.6)
43
- rack-cache (1.1)
44
- rack (>= 0.4)
45
- rack-mount (0.8.3)
46
- rack (>= 1.0.0)
47
- rack-test (0.6.1)
48
- rack (>= 1.0)
49
- rake (0.9.2.2)
50
- sprockets (2.0.3)
51
- hike (~> 1.2)
52
- rack (~> 1.0)
53
- tilt (~> 1.1, != 1.3.0)
54
- sqlite3 (1.3.6)
55
- tilt (1.3.3)
56
- tzinfo (0.3.32)
57
-
58
- PLATFORMS
59
- ruby
60
-
61
- DEPENDENCIES
62
- marginalia!
63
- mysql
64
- mysql2
65
- pg
66
- rake
67
- sqlite3