i18n-instrument 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +141 -0
- data/i18n-instrument.gemspec +22 -0
- data/lib/assets/javascripts/i18n/instrument.js.erb +33 -0
- data/lib/i18n/instrument.rb +20 -0
- data/lib/i18n/instrument/configurator.rb +43 -0
- data/lib/i18n/instrument/middleware.rb +122 -0
- data/lib/i18n/instrument/railtie.rb +10 -0
- data/lib/i18n/instrument/version.rb +5 -0
- data/spec/Rakefile +8 -0
- data/spec/app/controllers/tests_controller.rb +6 -0
- data/spec/config/application.rb +12 -0
- data/spec/config/initializers/i18n_instrument.rb +1 -0
- data/spec/config/initializers/secret_token.rb +1 -0
- data/spec/config/routes.rb +4 -0
- data/spec/javascript_middleware_spec.rb +59 -0
- data/spec/log/development.log +0 -0
- data/spec/log/test.log +5362 -0
- data/spec/ruby_middleware_spec.rb +102 -0
- data/spec/spec_helper.rb +21 -0
- metadata +105 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe I18n::Instrument::Middleware, type: :request do
|
5
|
+
let(:recorded_params) { [] }
|
6
|
+
let(:config) { I18n::Instrument.config }
|
7
|
+
let(:control_file) do
|
8
|
+
File.join('spec', 'config', 'enable_i18n_instrumentation')
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
I18n::Instrument.configure do |config|
|
13
|
+
config.on_record { |params| recorded_params << params }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_control_file
|
18
|
+
FileUtils.touch(control_file)
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
File.unlink(control_file)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "with default enable behavior, is disabled if the control file doesn't exist" do
|
25
|
+
expect { get('/tests') }.to_not change { recorded_params.size }.from(0)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "with default enable behavior, is enabled if the control file exists" do
|
29
|
+
with_control_file do
|
30
|
+
expect { get('/tests') }.to change { recorded_params.size }.from(0).to(1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with instrumentation enabled' do
|
35
|
+
before(:each) do
|
36
|
+
config.on_check_enabled { true }
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'records ruby I18n.t calls' do
|
40
|
+
expect { get('/tests') }.to change { recorded_params.size }.from(0).to(1)
|
41
|
+
expect(response).to be_success
|
42
|
+
params = recorded_params.first
|
43
|
+
|
44
|
+
expect(params[:source]).to eq('ruby')
|
45
|
+
expect(params[:trace]).to include('app/controllers/tests_controller.rb')
|
46
|
+
expect(params[:url]).to eq('/tests')
|
47
|
+
expect(params[:key]).to eq('en.foo.bar')
|
48
|
+
expect(params[:locale]).to eq('en')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'by default, renders a 500 for errors that happen during lookup' do
|
52
|
+
config.on_record { raise 'jelly beans' }
|
53
|
+
get '/tests'
|
54
|
+
expect(response).to_not be_success
|
55
|
+
end
|
56
|
+
|
57
|
+
# @TODO
|
58
|
+
it 'by default, renders a 500 for for errors that happen in the middleware stack' do
|
59
|
+
expect_any_instance_of(I18n::Instrument::Middleware).to(
|
60
|
+
receive(:handle_regular_request).and_raise('jelly beans')
|
61
|
+
)
|
62
|
+
|
63
|
+
get '/tests'
|
64
|
+
expect(response).to_not be_success
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with errors recorded' do
|
68
|
+
let(:recorded_errors) { [] }
|
69
|
+
|
70
|
+
before(:each) do
|
71
|
+
config.on_error { |e| recorded_errors << e }
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'reports errors that happen during lookup' do
|
75
|
+
config.on_record { raise 'jelly beans' }
|
76
|
+
expect { get('/tests') }.to change { recorded_errors.size }.from(0).to(1)
|
77
|
+
expect(recorded_errors.first.message).to eq('jelly beans')
|
78
|
+
expect(response).to be_success
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'reports errors that happen during the middleware stack' do
|
82
|
+
expect_any_instance_of(I18n::Instrument::Middleware).to(
|
83
|
+
receive(:handle_regular_request).and_raise('jelly beans')
|
84
|
+
)
|
85
|
+
|
86
|
+
expect { get '/tests' }.to change { recorded_errors.size }.from(0).to(1)
|
87
|
+
expect(response).to be_success
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with instrumentation disabled' do
|
93
|
+
before(:each) do
|
94
|
+
config.on_check_enabled { false }
|
95
|
+
end
|
96
|
+
|
97
|
+
it "doesn't record ruby I18n.t calls" do
|
98
|
+
expect { get('/tests') }.to_not change { recorded_params.size }.from(0)
|
99
|
+
expect(response).to be_success
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
$:.push(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'pry-byebug'
|
6
|
+
|
7
|
+
require 'rails'
|
8
|
+
require 'action_controller/railtie'
|
9
|
+
require 'action_view/railtie'
|
10
|
+
|
11
|
+
require 'rspec'
|
12
|
+
require 'rspec/rails'
|
13
|
+
|
14
|
+
ENV['RAILS_ENV'] ||= 'test'
|
15
|
+
|
16
|
+
require 'i18n/instrument'
|
17
|
+
|
18
|
+
Dir.chdir('spec') do
|
19
|
+
require File.expand_path('../config/application', __FILE__)
|
20
|
+
I18n::Instrument::DummyApplication.initialize!
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n-instrument
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Dutro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n-debug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: request_store
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description: Instrument calls to I18n.t in Ruby and JavaScript.
|
56
|
+
email:
|
57
|
+
- camertron@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- i18n-instrument.gemspec
|
65
|
+
- lib/assets/javascripts/i18n/instrument.js.erb
|
66
|
+
- lib/i18n/instrument.rb
|
67
|
+
- lib/i18n/instrument/configurator.rb
|
68
|
+
- lib/i18n/instrument/middleware.rb
|
69
|
+
- lib/i18n/instrument/railtie.rb
|
70
|
+
- lib/i18n/instrument/version.rb
|
71
|
+
- spec/Rakefile
|
72
|
+
- spec/app/controllers/tests_controller.rb
|
73
|
+
- spec/config/application.rb
|
74
|
+
- spec/config/initializers/i18n_instrument.rb
|
75
|
+
- spec/config/initializers/secret_token.rb
|
76
|
+
- spec/config/routes.rb
|
77
|
+
- spec/javascript_middleware_spec.rb
|
78
|
+
- spec/log/development.log
|
79
|
+
- spec/log/test.log
|
80
|
+
- spec/ruby_middleware_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: https://github.com/lumoslabs/i18n-instrument
|
83
|
+
licenses: []
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Instrument calls to I18n.t in Ruby and JavaScript.
|
105
|
+
test_files: []
|