napa 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/LICENSE +4 -2
  4. data/README.md +25 -2
  5. data/docs/quickstart.md +27 -26
  6. data/lib/napa.rb +6 -2
  7. data/lib/napa/active_record_extensions/notifications_subscriber.rb +17 -0
  8. data/lib/napa/active_record_extensions/stats.rb +1 -14
  9. data/lib/napa/cli.rb +5 -2
  10. data/lib/napa/generators/api_generator.rb +5 -1
  11. data/lib/napa/generators/migration_generator.rb +6 -2
  12. data/lib/napa/generators/scaffold_generator.rb +4 -3
  13. data/lib/napa/generators/templates/api/app/apis/%name_tableize%_api.rb.tt +4 -5
  14. data/lib/napa/generators/templates/api/app/models/%name_underscore%.rb.tt +0 -1
  15. data/lib/napa/generators/templates/api/spec/apis/%name_tableize%_api_spec.rb.tt +16 -0
  16. data/lib/napa/generators/templates/api/spec/models/%name_underscore%_spec.rb.tt +9 -0
  17. data/lib/napa/generators/templates/migration/%migration_filename%.rb.tt +1 -1
  18. data/lib/napa/generators/templates/scaffold/.gitignore.tt +2 -0
  19. data/lib/napa/generators/templates/scaffold/Gemfile.tt +2 -2
  20. data/lib/napa/generators/templates/scaffold/app.rb +1 -1
  21. data/lib/napa/generators/templates/scaffold/config.ru.tt +1 -1
  22. data/lib/napa/generators/templates/scaffold/config/database.yml.tt +1 -0
  23. data/lib/napa/generators/templates/scaffold/spec/apis/hello_api_spec.rb.tt +1 -1
  24. data/lib/napa/generators/templates/scaffold/spec/spec_helper.rb +15 -2
  25. data/lib/napa/grape_extenders.rb +6 -2
  26. data/lib/napa/grape_extensions/error_formatter.rb +1 -1
  27. data/lib/napa/grape_extensions/grape_helpers.rb +8 -1
  28. data/lib/napa/logger/logger.rb +10 -0
  29. data/lib/napa/logger/parseable.rb +37 -0
  30. data/lib/napa/middleware/app_monitor.rb +1 -1
  31. data/lib/napa/middleware/database_stats.rb +15 -0
  32. data/lib/napa/middleware/logger.rb +6 -11
  33. data/lib/napa/middleware/request_stats.rb +7 -5
  34. data/lib/napa/{grape_extensions → output_formatters}/entity.rb +0 -0
  35. data/lib/napa/output_formatters/include_nil.rb +16 -0
  36. data/lib/napa/{grape_extensions → output_formatters}/representer.rb +2 -2
  37. data/lib/napa/rspec_extensions/response_helpers.rb +17 -0
  38. data/lib/napa/stats.rb +21 -1
  39. data/lib/napa/version.rb +1 -1
  40. data/lib/tasks/db.rake +7 -0
  41. data/lib/tasks/git.rake +3 -0
  42. data/napa.gemspec +0 -1
  43. data/spec/generators/api_generator_spec.rb +63 -0
  44. data/spec/generators/migration_generator_spec.rb +27 -0
  45. data/spec/generators/scaffold_generator_spec.rb +90 -0
  46. data/spec/grape_extensions/error_formatter_spec.rb +8 -0
  47. data/spec/grape_extensions/include_nil_spec.rb +23 -0
  48. data/spec/logger/logger_spec.rb +14 -0
  49. data/spec/logger/parseable_spec.rb +16 -0
  50. data/spec/middleware/database_stats_spec.rb +64 -0
  51. data/spec/middleware/request_stats_spec.rb +4 -5
  52. data/spec/spec_helper.rb +26 -0
  53. data/spec/stats_spec.rb +25 -1
  54. metadata +25 -20
  55. data/spec/active_record_extensions/stats_spec.rb +0 -59
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ require 'napa/generators/scaffold_generator'
3
+ require 'napa/cli'
4
+
5
+ describe Napa::Generators::ScaffoldGenerator do
6
+ let(:app_name) { 'my_test_app' }
7
+ let(:app_path) { 'spec/my_different_directory' }
8
+ let(:options) { {} }
9
+
10
+ before do
11
+ scaffold = Napa::CLI::Base.new(args, options)
12
+ scaffold.invoke(:new)
13
+ end
14
+
15
+ after do
16
+ if args[1] # if app_path exists, delete dir at app_path
17
+ FileUtils.rm_rf(args[1])
18
+ else # otherwise delete dir at app_name
19
+ FileUtils.rm_rf(args[0])
20
+ end
21
+ end
22
+
23
+ context 'given only an app name' do
24
+ let(:args) { [app_name] }
25
+
26
+ it 'creates a scaffold app in a directory that mirrors the app name' do
27
+ args = [app_name]
28
+ expect(Dir).to exist(app_name)
29
+ end
30
+ end
31
+
32
+ context 'given an app name and a directory' do
33
+ let(:args) { [app_name, app_path] }
34
+
35
+ it 'creates a scaffold app in a directory of my choosing' do
36
+ expect(Dir).to exist(app_path)
37
+ end
38
+
39
+ it 'creates a .env file with with a development database name' do
40
+ expect(File).to exist("#{app_path}/.env")
41
+ env_file = File.read("#{app_path}/.env")
42
+ expect(env_file).to match(/#{app_name}_development/)
43
+ end
44
+
45
+ it 'creates a .env.test file with a test database name' do
46
+ expect(File).to exist("#{app_path}/.env.test")
47
+ env_test_file = File.read("#{app_path}/.env.test")
48
+ expect(env_test_file).to match(/#{app_name}_test/)
49
+ end
50
+
51
+ it 'selects mysql as the default database adapter' do
52
+ database_config_file = File.read("#{app_path}/config/database.yml")
53
+ expect(database_config_file).to match(/adapter: mysql2/)
54
+ end
55
+
56
+ it 'adds the mysql2 gem in the Gemfile' do
57
+ gemfile = File.read("#{app_path}/Gemfile")
58
+ expect(gemfile).to match(/gem 'mysql2'/)
59
+ end
60
+
61
+ it 'generates an application api' do
62
+ expect(File).to exist("#{app_path}/app/apis/application_api.rb")
63
+ end
64
+
65
+ it 'the application API inherits from Grape::API' do
66
+ application_api_file = File.read("#{app_path}/app/apis/application_api.rb")
67
+ expect(application_api_file).to match(/class ApplicationApi < Grape::API/)
68
+ end
69
+
70
+ it 'generates an example API and spec' do
71
+ expect(File).to exist("#{app_path}/app/apis/hello_api.rb")
72
+ expect(File).to exist("#{app_path}/spec/apis/hello_api_spec.rb")
73
+ end
74
+ end
75
+
76
+ context 'with the -d=pg option' do
77
+ let(:args) { [app_name, app_path] }
78
+ let(:options) { { :database => "pg" } }
79
+
80
+ it 'selects postres/pg as the database' do
81
+ database_config_file = File.read("#{app_path}/config/database.yml")
82
+ expect(database_config_file).to match(/adapter: postgresql/)
83
+ end
84
+
85
+ it 'adds the pg gem in the Gemfile' do
86
+ gemfile = File.read("#{app_path}/Gemfile")
87
+ expect(gemfile).to match(/gem 'pg'/)
88
+ end
89
+ end
90
+ end
@@ -17,5 +17,13 @@ describe Grape::ErrorFormatter::Json do
17
17
  parsed['error']['code'].should eq('foo')
18
18
  parsed['error']['message'].should eq('bar')
19
19
  end
20
+
21
+ it 'adds the backtrace with rescue_option[:backtrace] specified' do
22
+ error = Grape::ErrorFormatter::Json.call('',
23
+ 'backtrace',
24
+ rescue_options: {backtrace: true})
25
+ parsed = JSON.parse(error)
26
+ parsed['backtrace'].should eq('backtrace')
27
+ end
20
28
  end
21
29
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'napa/output_formatters/include_nil'
3
+ require 'napa/grape_extensions/grape_helpers'
4
+ require 'pry'
5
+
6
+ describe Napa::Representable::IncludeNil do
7
+ class FooRepresenter < Napa::Representer
8
+ include Napa::Representable::IncludeNil
9
+ property :foo
10
+ property :bar
11
+ end
12
+
13
+ class DummyClass
14
+ include Napa::GrapeHelpers
15
+ end
16
+
17
+ it 'includes nil keys in a represented hash' do
18
+ input = OpenStruct.new(foo: 1, bar: nil)
19
+ output = DummyClass.new.represent(input, with: FooRepresenter).to_h
20
+ expect(output[:data]).to have_key('foo')
21
+ expect(output[:data]).to have_key('bar')
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'napa/logger/logger'
3
+
4
+ describe Napa::Logger do
5
+ context '#response' do
6
+ it 'returns response in the expected format' do
7
+ response = Napa::Logger.response('foo', 'bar', 'baz')
8
+
9
+ expect(response[:response][:status]).to eq('foo')
10
+ expect(response[:response][:headers]).to eq('bar')
11
+ expect(response[:response][:response]).to eq('baz')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'napa/logger/parseable'
3
+
4
+ describe Logging::Layouts::Parseable do
5
+ context '#format_obj' do
6
+ it 'formats text as an object' do
7
+ p = Logging::Layouts::Parseable.new
8
+ expect(p.format_obj('foobar')).to eq({ text: 'foobar' })
9
+ end
10
+
11
+ it 'does not reformat objects' do
12
+ p = Logging::Layouts::Parseable.new
13
+ expect(p.format_obj({ foo: :bar })).to eq({ foo: :bar })
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,64 @@
1
+ require 'active_record'
2
+ require 'spec_helper'
3
+ require 'napa/active_record_extensions/stats'
4
+
5
+ # Delete any prevous instantiations of the emitter and set valid statsd env vars
6
+ Napa::Stats.emitter = nil
7
+ ENV['STATSD_HOST'] = 'localhost'
8
+ ENV['STATSD_PORT'] = '8125'
9
+
10
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
11
+
12
+ ActiveRecord::Schema.define(version: 1) do
13
+ create_table :foos do |t|
14
+ t.string :word
15
+ end
16
+ end
17
+
18
+ class Foo < ActiveRecord::Base
19
+ end
20
+
21
+ describe Napa::Middleware::DatabaseStats do
22
+ before do
23
+ # Delete any prevous instantiations of the emitter and set valid statsd env vars
24
+ Napa::Stats.emitter = nil
25
+ ENV['STATSD_HOST'] = 'localhost'
26
+ ENV['STATSD_PORT'] = '8125'
27
+
28
+ @foo = Foo.create(word: 'bar')
29
+ end
30
+
31
+ after do
32
+ middleware = Napa::Middleware::DatabaseStats.new(@app)
33
+ env = Rack::MockRequest.env_for('/test/path')
34
+ middleware.call(env)
35
+ end
36
+
37
+ it 'should send a query_time for an insert' do
38
+ Napa::Stats.emitter.should_receive(:timing).with('sql.query_time', an_instance_of(Float))
39
+ Napa::Stats.emitter.should_receive(:timing).with('sql.table.foos.insert.query_time', an_instance_of(Float))
40
+
41
+ @app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, Foo.create(word: 'baz')] }
42
+ end
43
+
44
+ it 'should send a query_time for a select' do
45
+ Napa::Stats.emitter.should_receive(:timing).with('sql.query_time', an_instance_of(Float))
46
+ Napa::Stats.emitter.should_receive(:timing).with('sql.table.foos.select.query_time', an_instance_of(Float))
47
+
48
+ @app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, Foo.first] }
49
+ end
50
+
51
+ it 'should send a query_time for a delete' do
52
+ Napa::Stats.emitter.should_receive(:timing).with('sql.query_time', an_instance_of(Float))
53
+ Napa::Stats.emitter.should_receive(:timing).with('sql.table.foos.delete.query_time', an_instance_of(Float))
54
+
55
+ @app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, @foo.delete ] }
56
+ end
57
+
58
+ it 'should send a query_time for an update' do
59
+ Napa::Stats.emitter.should_receive(:timing).with('sql.query_time', an_instance_of(Float))
60
+ Napa::Stats.emitter.should_receive(:timing).with('sql.table.foos.update.query_time', an_instance_of(Float))
61
+
62
+ @app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, @foo.update_attributes(word: 'baz') ] }
63
+ end
64
+ end
@@ -10,7 +10,8 @@ describe Napa::Middleware::RequestStats do
10
10
  end
11
11
 
12
12
  it 'should increment api_requests counter' do
13
- Napa::Stats.emitter.should_receive(:increment).with(Napa::Identity.name + ".http.get." + "test.path.requests")
13
+ Napa::Stats.emitter.should_receive(:increment).with('request_count')
14
+ Napa::Stats.emitter.should_receive(:increment).with('path.get.test.path.request_count')
14
15
  app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, Array.new] }
15
16
  middleware = Napa::Middleware::RequestStats.new(app)
16
17
  env = Rack::MockRequest.env_for('/test/path')
@@ -18,10 +19,8 @@ describe Napa::Middleware::RequestStats do
18
19
  end
19
20
 
20
21
  it 'should send the api_response_time' do
21
- Napa::Stats.emitter.should_receive(:timing).with(
22
- Napa::Identity.name + ".http.get." + "test.path.response_time",
23
- an_instance_of(Float)
24
- )
22
+ Napa::Stats.emitter.should_receive(:timing).with('response_time', an_instance_of(Float))
23
+ Napa::Stats.emitter.should_receive(:timing).with('path.get.test.path.response_time', an_instance_of(Float))
25
24
  app = lambda { |env| [200, { 'Content-Type' => 'application/json'}, Array.new] }
26
25
  middleware = Napa::Middleware::RequestStats.new(app)
27
26
  env = Rack::MockRequest.env_for('/test/path')
@@ -1 +1,27 @@
1
1
  require 'napa'
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+
5
+ # from https://gist.github.com/adamstegman/926858
6
+ RSpec.configure do |config|
7
+ config.before(:all) { silence_output }
8
+ config.after(:all) { enable_output }
9
+ end
10
+
11
+ # Redirects stderr and stdout to /dev/null.
12
+ def silence_output
13
+ @orig_stderr = $stderr
14
+ @orig_stdout = $stdout
15
+
16
+ # redirect stderr and stdout to /dev/null
17
+ $stderr = File.new('/dev/null', 'w')
18
+ $stdout = File.new('/dev/null', 'w')
19
+ end
20
+
21
+ # Replace stdout and stderr so anything else is output correctly.
22
+ def enable_output
23
+ $stderr = @orig_stderr
24
+ $stdout = @orig_stdout
25
+ @orig_stderr = nil
26
+ @orig_stdout = nil
27
+ end
@@ -30,7 +30,7 @@ describe Napa::Stats do
30
30
 
31
31
  it 'the namespace of the StatsD client object should equal the service name' do
32
32
  ENV['SERVICE_NAME'] = 'my-service'
33
- expect(Napa::Stats.emitter.namespace).to eq('my-service')
33
+ expect(Napa::Stats.emitter.namespace).to eq("my-service.test")
34
34
  end
35
35
 
36
36
  it 'should use env variables to set statsd host and port' do
@@ -39,4 +39,28 @@ describe Napa::Stats do
39
39
  expect(Napa::Stats.emitter.host).to eq('localhost')
40
40
  expect(Napa::Stats.emitter.port).to eq('9000')
41
41
  end
42
+
43
+ describe '#namespace' do
44
+ it 'prepends the namespace with the STATSD_API_KEY if present' do
45
+ ENV['STATSD_API_KEY'] = 'foo'
46
+ expect(Napa::Stats.namespace).to eq("#{ENV['STATSD_API_KEY']}.#{Napa::Identity.name}.test")
47
+ end
48
+
49
+ it 'does not include the STATSD_API_KEY if empty' do
50
+ ENV['STATSD_API_KEY'] = nil
51
+ expect(Napa::Stats.namespace).to eq("#{Napa::Identity.name}.test")
52
+ end
53
+ end
54
+
55
+ describe '#path_to_key' do
56
+ it 'returns the key string with ids removed and parts joined with dots' do
57
+ method = 'GET'
58
+ path = '/foo/123/bar'
59
+ expect(Napa::Stats.path_to_key(method, path)).to eq('get.foo._.bar')
60
+
61
+ method = 'POST'
62
+ path = '/foo'
63
+ expect(Napa::Stats.path_to_key(method, path)).to eq('post.foo')
64
+ end
65
+ end
42
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: napa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darby Frey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-19 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: unicorn
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - '>='
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: statsd-ruby
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -282,6 +268,7 @@ files:
282
268
  - docs/quickstart.md
283
269
  - lib/napa.rb
284
270
  - lib/napa/active_record_extensions/filter_by_hash.rb
271
+ - lib/napa/active_record_extensions/notifications_subscriber.rb
285
272
  - lib/napa/active_record_extensions/stats.rb
286
273
  - lib/napa/authentication.rb
287
274
  - lib/napa/cli.rb
@@ -292,6 +279,8 @@ files:
292
279
  - lib/napa/generators/templates/api/app/apis/%name_tableize%_api.rb.tt
293
280
  - lib/napa/generators/templates/api/app/models/%name_underscore%.rb.tt
294
281
  - lib/napa/generators/templates/api/app/representers/%name_underscore%_representer.rb.tt
282
+ - lib/napa/generators/templates/api/spec/apis/%name_tableize%_api_spec.rb.tt
283
+ - lib/napa/generators/templates/api/spec/models/%name_underscore%_spec.rb.tt
295
284
  - lib/napa/generators/templates/migration/%migration_filename%.rb.tt
296
285
  - lib/napa/generators/templates/scaffold/.env.test.tt
297
286
  - lib/napa/generators/templates/scaffold/.env.tt
@@ -316,18 +305,22 @@ files:
316
305
  - lib/napa/generators/templates/scaffold/spec/factories/.gitkeep
317
306
  - lib/napa/generators/templates/scaffold/spec/spec_helper.rb
318
307
  - lib/napa/grape_extenders.rb
319
- - lib/napa/grape_extensions/entity.rb
320
308
  - lib/napa/grape_extensions/error_formatter.rb
321
309
  - lib/napa/grape_extensions/grape_helpers.rb
322
- - lib/napa/grape_extensions/representer.rb
323
310
  - lib/napa/identity.rb
324
311
  - lib/napa/json_error.rb
325
312
  - lib/napa/logger/log_transaction.rb
326
313
  - lib/napa/logger/logger.rb
314
+ - lib/napa/logger/parseable.rb
327
315
  - lib/napa/middleware/app_monitor.rb
328
316
  - lib/napa/middleware/authentication.rb
317
+ - lib/napa/middleware/database_stats.rb
329
318
  - lib/napa/middleware/logger.rb
330
319
  - lib/napa/middleware/request_stats.rb
320
+ - lib/napa/output_formatters/entity.rb
321
+ - lib/napa/output_formatters/include_nil.rb
322
+ - lib/napa/output_formatters/representer.rb
323
+ - lib/napa/rspec_extensions/response_helpers.rb
331
324
  - lib/napa/setup.rb
332
325
  - lib/napa/stats.rb
333
326
  - lib/napa/stats_d_timer.rb
@@ -338,13 +331,19 @@ files:
338
331
  - lib/tasks/routes.rake
339
332
  - napa.gemspec
340
333
  - spec/active_record_extensions/filter_by_hash_spec.rb
341
- - spec/active_record_extensions/stats_spec.rb
342
334
  - spec/authentication_spec.rb
335
+ - spec/generators/api_generator_spec.rb
336
+ - spec/generators/migration_generator_spec.rb
337
+ - spec/generators/scaffold_generator_spec.rb
343
338
  - spec/grape_extensions/error_formatter_spec.rb
339
+ - spec/grape_extensions/include_nil_spec.rb
344
340
  - spec/identity_spec.rb
345
341
  - spec/json_error_spec.rb
346
342
  - spec/logger/log_transaction_spec.rb
343
+ - spec/logger/logger_spec.rb
344
+ - spec/logger/parseable_spec.rb
347
345
  - spec/middleware/authentication_spec.rb
346
+ - spec/middleware/database_stats_spec.rb
348
347
  - spec/middleware/request_stats_spec.rb
349
348
  - spec/spec_helper.rb
350
349
  - spec/stats_spec.rb
@@ -375,13 +374,19 @@ specification_version: 4
375
374
  summary: A simple framework for building APIs with Grape
376
375
  test_files:
377
376
  - spec/active_record_extensions/filter_by_hash_spec.rb
378
- - spec/active_record_extensions/stats_spec.rb
379
377
  - spec/authentication_spec.rb
378
+ - spec/generators/api_generator_spec.rb
379
+ - spec/generators/migration_generator_spec.rb
380
+ - spec/generators/scaffold_generator_spec.rb
380
381
  - spec/grape_extensions/error_formatter_spec.rb
382
+ - spec/grape_extensions/include_nil_spec.rb
381
383
  - spec/identity_spec.rb
382
384
  - spec/json_error_spec.rb
383
385
  - spec/logger/log_transaction_spec.rb
386
+ - spec/logger/logger_spec.rb
387
+ - spec/logger/parseable_spec.rb
384
388
  - spec/middleware/authentication_spec.rb
389
+ - spec/middleware/database_stats_spec.rb
385
390
  - spec/middleware/request_stats_spec.rb
386
391
  - spec/spec_helper.rb
387
392
  - spec/stats_spec.rb
@@ -1,59 +0,0 @@
1
- require 'active_record'
2
- require 'spec_helper'
3
- require 'napa/active_record_extensions/stats.rb'
4
-
5
- # Delete any prevous instantiations of the emitter and set valid statsd env vars
6
- Napa::Stats.emitter = nil
7
- ENV['STATSD_HOST'] = 'localhost'
8
- ENV['STATSD_PORT'] = '8125'
9
-
10
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
11
-
12
- ActiveRecord::Schema.define(version: 1) do
13
- create_table :foos do |t|
14
- t.string :word
15
- end
16
- end
17
-
18
- class Foo < ActiveRecord::Base
19
- end
20
-
21
- describe Napa::ActiveRecordStats do
22
- before(:each) do
23
- Foo.delete_all
24
- @x = Foo.create(word: 'bar')
25
- end
26
-
27
- it 'should send a query_time for an insert' do
28
- Napa::Stats.emitter.should_receive(:timing).with(
29
- "#{Napa::Identity.name}.unknown.sql.foos.insert.query_time",
30
- an_instance_of(Float)
31
- )
32
- Foo.create(word: 'baz')
33
- end
34
-
35
- it 'should send a query_time for a select' do
36
- Napa::Stats.emitter.should_receive(:timing).with(
37
- "#{Napa::Identity.name}.unknown.sql.foos.select.query_time",
38
- an_instance_of(Float)
39
- )
40
- Foo.all
41
- end
42
-
43
- it 'should send a query_time for a delete' do
44
- Napa::Stats.emitter.should_receive(:timing).with(
45
- "#{Napa::Identity.name}.unknown.sql.foos.delete.query_time",
46
- an_instance_of(Float)
47
- )
48
- @x.delete
49
- end
50
-
51
- it 'should send a query_time for an update' do
52
- Napa::Stats.emitter.should_receive(:timing).with(
53
- "#{Napa::Identity.name}.unknown.sql.foos.update.query_time",
54
- an_instance_of(Float)
55
- )
56
- @x.word = 'baz'
57
- @x.save
58
- end
59
- end