glimpse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +160 -0
- data/Rakefile +13 -0
- data/app/assets/images/glimpse/bar/development.gif +0 -0
- data/app/assets/images/glimpse/bar/production.gif +0 -0
- data/app/assets/images/glimpse/bar/staging.gif +0 -0
- data/app/assets/javascripts/glimpse/vendor/jquery.cookies.js +94 -0
- data/app/assets/javascripts/glimpse.coffee +22 -0
- data/app/assets/stylesheets/glimpse.scss +56 -0
- data/app/views/glimpse/_bar.html.erb +9 -0
- data/app/views/glimpse/_results.html.erb +10 -0
- data/glimpse.gemspec +21 -0
- data/lib/glimpse/controller_helpers.rb +15 -0
- data/lib/glimpse/railtie.rb +19 -0
- data/lib/glimpse/version.rb +3 -0
- data/lib/glimpse/views/view.rb +47 -0
- data/lib/glimpse.rb +37 -0
- data/test/glimpse/views/view_test.rb +19 -0
- data/test/glimpse_test.rb +69 -0
- data/test/test_helper.rb +9 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Garrett Bjerkhoel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Glimpse
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/dewski/glimpse.png?branch=master)](https://travis-ci.org/dewski/glimpse)
|
4
|
+
|
5
|
+
Provide a glimpse into your Rails application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'glimpse'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install glimpse
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Run the Rails generator to get Glimpse up and included into your project:
|
24
|
+
|
25
|
+
```
|
26
|
+
rails generate glimpse:install
|
27
|
+
```
|
28
|
+
|
29
|
+
This will create a file at `config/initializers/glimpse.rb` which will give you
|
30
|
+
example views to include into your Glimpse bar.
|
31
|
+
|
32
|
+
Feel free to pick and choose from the list or create your own. The order they
|
33
|
+
are added to Glimpse, the order they will appear in your bar.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Glimpse.into Glimpse::Views::Git, :nwo => 'github/janky'
|
37
|
+
Glimpse.into Glimpse::Views::Mongo
|
38
|
+
Glimpse.into Glimpse::Views::Mysql2
|
39
|
+
Glimpse.into Glimpse::Views::Redis
|
40
|
+
```
|
41
|
+
|
42
|
+
To render the Glimpse bar in your application just add the following snippet
|
43
|
+
just before the opening `<body>` tag in your application layout.
|
44
|
+
|
45
|
+
```erb
|
46
|
+
<%= render 'glimpse/bar' %>
|
47
|
+
```
|
48
|
+
|
49
|
+
It will look something like:
|
50
|
+
|
51
|
+
```erb
|
52
|
+
<html>
|
53
|
+
<head>
|
54
|
+
<title>Application</title>
|
55
|
+
</head>
|
56
|
+
<body>
|
57
|
+
<%= render 'glimpse/bar' %>
|
58
|
+
<%= yield %>
|
59
|
+
</body>
|
60
|
+
</html>
|
61
|
+
```
|
62
|
+
|
63
|
+
Some Glimpse views require the view to render before data is collected and can
|
64
|
+
be presented, ie: the number of MySQL queries ran on the page and how
|
65
|
+
long it took.
|
66
|
+
|
67
|
+
For this to work, you need to include the performance partial at the end of your
|
68
|
+
application layout.
|
69
|
+
|
70
|
+
It will look something like:
|
71
|
+
|
72
|
+
```erb
|
73
|
+
<html>
|
74
|
+
<head>
|
75
|
+
<title>Application</title>
|
76
|
+
</head>
|
77
|
+
<body>
|
78
|
+
<%= render 'glimpse/bar' %>
|
79
|
+
<%= yield %>
|
80
|
+
<%= render 'glimpse/results' %>
|
81
|
+
</body>
|
82
|
+
</html>
|
83
|
+
```
|
84
|
+
|
85
|
+
Now that you have the partials in your application, you will need to include the
|
86
|
+
assets required to make everything :sparkles:
|
87
|
+
|
88
|
+
In `app/assets/stylesheets/application.scss`:
|
89
|
+
|
90
|
+
```scss
|
91
|
+
//= require glimpse
|
92
|
+
```
|
93
|
+
|
94
|
+
In `app/assets/javascripts/application.coffee`:
|
95
|
+
|
96
|
+
```coffeescript
|
97
|
+
#= require jquery
|
98
|
+
#= require jquery_ujs
|
99
|
+
#= require glimpse
|
100
|
+
```
|
101
|
+
|
102
|
+
## Using Glimpse with PJAX
|
103
|
+
|
104
|
+
When using PJAX requests won't render default application layout which ends
|
105
|
+
up not including the required results partial. It's fairly simple to work around
|
106
|
+
if you're using the [pjax_rails](https://github.com/rails/pjax_rails) gem.
|
107
|
+
|
108
|
+
Create a new layout at `app/views/layouts/pjax.html.erb`:
|
109
|
+
|
110
|
+
```erb
|
111
|
+
<%= yield %>
|
112
|
+
<%= render 'glimpse/results' %>
|
113
|
+
```
|
114
|
+
|
115
|
+
Now you'll just need use the PJAX layout:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class ApplicationController < ActionController::Base
|
119
|
+
def pjax_layout
|
120
|
+
'pjax'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
You're done! Now every time a PJAX request is made, the Glimpse bar will update with
|
126
|
+
the data of the PJAX request.
|
127
|
+
|
128
|
+
## Access Control
|
129
|
+
|
130
|
+
You probably don't want to give this data to ALL your users. So by default Glimpse
|
131
|
+
only shows up in development or staging environments. If you'd like to restrict Glimpse
|
132
|
+
to a select few users, you can do so by overriding the `glimpse_enabled?` guard in
|
133
|
+
ApplicationController.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
class ApplicationController < ActionController::Base
|
137
|
+
def glimpse_enabled?
|
138
|
+
current_user.staff?
|
139
|
+
end
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
## Available Glimpse views
|
144
|
+
|
145
|
+
- [glimpse-dalli](https://github.com/dewski/glimpse-dalli)
|
146
|
+
- [glimpse-git](https://github.com/dewski/glimpse-git)
|
147
|
+
- [glimpse-mongo](https://github.com/dewski/glimpse-mongo)
|
148
|
+
- [glimpse-mysql2](https://github.com/dewski/glimpse-mysql2)
|
149
|
+
- [glimpse-pg](https://github.com/dewski/glimpse-pg)
|
150
|
+
- [glimpse-redis](https://github.com/dewski/glimpse-redis)
|
151
|
+
- Navigation Time :soon:
|
152
|
+
- Unicorn :soon:
|
153
|
+
|
154
|
+
## Contributing
|
155
|
+
|
156
|
+
1. Fork it
|
157
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
158
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
159
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
160
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Default: run tests'
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc 'Run Glimpse tests.'
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.libs << 'test'
|
11
|
+
t.test_files = FileList['test/**/*_test.rb']
|
12
|
+
t.verbose = true
|
13
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,94 @@
|
|
1
|
+
/*!
|
2
|
+
* jQuery Cookie Plugin v1.3.1
|
3
|
+
* https://github.com/carhartl/jquery-cookie
|
4
|
+
*
|
5
|
+
* Copyright 2013 Klaus Hartl
|
6
|
+
* Released under the MIT license
|
7
|
+
*/
|
8
|
+
(function (factory) {
|
9
|
+
if (typeof define === 'function' && define.amd) {
|
10
|
+
// AMD. Register as anonymous module.
|
11
|
+
define(['jquery'], factory);
|
12
|
+
} else {
|
13
|
+
// Browser globals.
|
14
|
+
factory(jQuery);
|
15
|
+
}
|
16
|
+
}(function ($) {
|
17
|
+
|
18
|
+
var pluses = /\+/g;
|
19
|
+
|
20
|
+
function raw(s) {
|
21
|
+
return s;
|
22
|
+
}
|
23
|
+
|
24
|
+
function decoded(s) {
|
25
|
+
return decodeURIComponent(s.replace(pluses, ' '));
|
26
|
+
}
|
27
|
+
|
28
|
+
function converted(s) {
|
29
|
+
if (s.indexOf('"') === 0) {
|
30
|
+
// This is a quoted cookie as according to RFC2068, unescape
|
31
|
+
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
32
|
+
}
|
33
|
+
try {
|
34
|
+
return config.json ? JSON.parse(s) : s;
|
35
|
+
} catch(er) {}
|
36
|
+
}
|
37
|
+
|
38
|
+
var config = $.cookie = function (key, value, options) {
|
39
|
+
|
40
|
+
// write
|
41
|
+
if (value !== undefined) {
|
42
|
+
options = $.extend({}, config.defaults, options);
|
43
|
+
|
44
|
+
if (typeof options.expires === 'number') {
|
45
|
+
var days = options.expires, t = options.expires = new Date();
|
46
|
+
t.setDate(t.getDate() + days);
|
47
|
+
}
|
48
|
+
|
49
|
+
value = config.json ? JSON.stringify(value) : String(value);
|
50
|
+
|
51
|
+
return (document.cookie = [
|
52
|
+
config.raw ? key : encodeURIComponent(key),
|
53
|
+
'=',
|
54
|
+
config.raw ? value : encodeURIComponent(value),
|
55
|
+
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
56
|
+
options.path ? '; path=' + options.path : '',
|
57
|
+
options.domain ? '; domain=' + options.domain : '',
|
58
|
+
options.secure ? '; secure' : ''
|
59
|
+
].join(''));
|
60
|
+
}
|
61
|
+
|
62
|
+
// read
|
63
|
+
var decode = config.raw ? raw : decoded;
|
64
|
+
var cookies = document.cookie.split('; ');
|
65
|
+
var result = key ? undefined : {};
|
66
|
+
for (var i = 0, l = cookies.length; i < l; i++) {
|
67
|
+
var parts = cookies[i].split('=');
|
68
|
+
var name = decode(parts.shift());
|
69
|
+
var cookie = decode(parts.join('='));
|
70
|
+
|
71
|
+
if (key && key === name) {
|
72
|
+
result = converted(cookie);
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (!key) {
|
77
|
+
result[name] = converted(cookie);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
return result;
|
82
|
+
};
|
83
|
+
|
84
|
+
config.defaults = {};
|
85
|
+
|
86
|
+
$.removeCookie = function (key, options) {
|
87
|
+
if ($.cookie(key) !== undefined) {
|
88
|
+
$.cookie(key, '', $.extend(options, { expires: -1 }));
|
89
|
+
return true;
|
90
|
+
}
|
91
|
+
return false;
|
92
|
+
};
|
93
|
+
|
94
|
+
}));
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#= require glimpse/vendor/jquery.cookies.js
|
2
|
+
|
3
|
+
updatePerformanceBar = ->
|
4
|
+
glimpseResults = $('#glimpse-results')
|
5
|
+
$('#glimpse [data-defer-to]').each ->
|
6
|
+
deferKey = $(this).data 'defer-to'
|
7
|
+
data = glimpseResults.data deferKey
|
8
|
+
$(this).text data
|
9
|
+
|
10
|
+
toggleBar = (event) ->
|
11
|
+
return if $(event.target).is ':input'
|
12
|
+
|
13
|
+
if event.keyCode == 96
|
14
|
+
$('#glimpse').toggleClass 'disabled'
|
15
|
+
enable = $.cookie('glimpse') == 'false'
|
16
|
+
$.cookie('glimpse', enable)
|
17
|
+
|
18
|
+
$(document).on 'pjax:end', updatePerformanceBar
|
19
|
+
$(document).on 'keypress', toggleBar
|
20
|
+
|
21
|
+
$ ->
|
22
|
+
updatePerformanceBar()
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#glimpse {
|
2
|
+
background: #000;
|
3
|
+
height: 35px;
|
4
|
+
line-height: 35px;
|
5
|
+
color: #999;
|
6
|
+
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
|
7
|
+
|
8
|
+
.hidden {
|
9
|
+
display: none;
|
10
|
+
}
|
11
|
+
|
12
|
+
&.disabled {
|
13
|
+
display: none;
|
14
|
+
}
|
15
|
+
|
16
|
+
&.production {
|
17
|
+
background: image-url('glimpse/bar/production.gif') repeat 0 0;
|
18
|
+
}
|
19
|
+
|
20
|
+
&.staging {
|
21
|
+
background: image-url('glimpse/bar/staging.gif') repeat 0 0;
|
22
|
+
}
|
23
|
+
|
24
|
+
&.development {
|
25
|
+
background: image-url('glimpse/bar/development.gif') repeat 0 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
.wrapper {
|
29
|
+
width: 800px;
|
30
|
+
margin: 0 auto;
|
31
|
+
}
|
32
|
+
|
33
|
+
// UI Elements
|
34
|
+
.bucket {
|
35
|
+
background: #111;
|
36
|
+
display: inline-block;
|
37
|
+
padding: 4px 6px;
|
38
|
+
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
39
|
+
line-height: 1;
|
40
|
+
color: #ccc;
|
41
|
+
border-radius: 3px;
|
42
|
+
box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 1px 2px rgba(0,0,0,.25);
|
43
|
+
|
44
|
+
.hidden {
|
45
|
+
display: none;
|
46
|
+
}
|
47
|
+
|
48
|
+
&:hover .hidden {
|
49
|
+
display: inline;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
strong {
|
54
|
+
color: #fff;
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<% if glimpse_enabled? %>
|
2
|
+
<div id="glimpse" class="<%= Glimpse.env %><%= ' disabled' if cookies[:glimpse] == 'false' %>">
|
3
|
+
<div class="wrapper">
|
4
|
+
<% Glimpse.views.each do |view| %>
|
5
|
+
<%= render view.partial_path, :view => view %>
|
6
|
+
<% end %>
|
7
|
+
</div>
|
8
|
+
</div>
|
9
|
+
<% end %>
|
data/glimpse.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'glimpse/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'glimpse'
|
8
|
+
gem.version = Glimpse::VERSION
|
9
|
+
gem.authors = ['Garrett Bjerkhoel']
|
10
|
+
gem.email = ['me@garrettbjerkhoel.com']
|
11
|
+
gem.description = %q{Provide a glimpse into your Rails application.}
|
12
|
+
gem.summary = %q{Provide a glimpse into your Rails application.}
|
13
|
+
gem.homepage = 'https://github.com/dewski/glimpse'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'rails'
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'glimpse/controller_helpers'
|
2
|
+
|
3
|
+
module Glimpse
|
4
|
+
class Railtie < ::Rails::Engine
|
5
|
+
config.glimpse = Glimpse
|
6
|
+
|
7
|
+
initializer 'glimpse.setup_subscribers' do
|
8
|
+
ActiveSupport.on_load(:after_initialize) do
|
9
|
+
Glimpse.views
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
initializer 'glimpse.include_controller_helpers' do
|
14
|
+
config.to_prepare do
|
15
|
+
ApplicationController.send(:include, Glimpse::ControllerHelpers)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Glimpse
|
2
|
+
module Views
|
3
|
+
class View
|
4
|
+
def initialize(options = {})
|
5
|
+
@options = options
|
6
|
+
|
7
|
+
setup_subscribers
|
8
|
+
end
|
9
|
+
|
10
|
+
def enabled?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def partial_path
|
15
|
+
self.class.to_s.underscore
|
16
|
+
end
|
17
|
+
|
18
|
+
def defer_key
|
19
|
+
self.class.to_s.split('::').last.underscore.gsub(/\_/, '-')
|
20
|
+
end
|
21
|
+
|
22
|
+
def results
|
23
|
+
{}
|
24
|
+
end
|
25
|
+
|
26
|
+
def subscribe(*args)
|
27
|
+
ActiveSupport::Notifications.subscribe(*args) do |name, start, finish, id, payload|
|
28
|
+
yield name, start, finish, id, payload
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def setup_subscribers
|
35
|
+
# pass
|
36
|
+
end
|
37
|
+
|
38
|
+
# Helper method for subscribing to the event that is fired when new
|
39
|
+
# requests are made.
|
40
|
+
def before_request
|
41
|
+
subscribe 'start_processing.action_controller' do |name, start, finish, id, payload|
|
42
|
+
yield name, start, finish, id, payload
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/glimpse.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'glimpse/version'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
require 'glimpse/views/view'
|
5
|
+
Dir[File.join(File.dirname(__FILE__), 'glimpse', 'views', '*.rb')].each do |view|
|
6
|
+
require view
|
7
|
+
end
|
8
|
+
|
9
|
+
module Glimpse
|
10
|
+
def self.enabled?
|
11
|
+
['development', 'staging'].include?(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.env
|
15
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.views
|
19
|
+
@cached_views ||= if @views && @views.any?
|
20
|
+
@views.collect { |klass, options| klass.new(options.dup) }.select(&:enabled?)
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.into(klass, options = {})
|
27
|
+
@views ||= []
|
28
|
+
@views << [klass, options]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.reset
|
32
|
+
@views = nil
|
33
|
+
@cached_views = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'glimpse/railtie'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Glimpse::Views::View do
|
4
|
+
before do
|
5
|
+
@view = Glimpse::Views::View.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "partial path" do
|
9
|
+
it "should return correct partial class" do
|
10
|
+
assert_equal 'glimpse/views/view', @view.partial_path
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "toggling off and on" do
|
15
|
+
it "should be enabled by default" do
|
16
|
+
assert @view.enabled?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Staff < Glimpse::Views::View
|
4
|
+
def initialize(options = {})
|
5
|
+
@username = options.delete(:username)
|
6
|
+
end
|
7
|
+
|
8
|
+
def username
|
9
|
+
@username
|
10
|
+
end
|
11
|
+
|
12
|
+
def enabled?
|
13
|
+
!!@username
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Glimpse do
|
18
|
+
describe "enabled?" do
|
19
|
+
it "should not be enabled in test" do
|
20
|
+
refute Glimpse.enabled?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "env" do
|
25
|
+
it "should return the current environment" do
|
26
|
+
assert_equal 'test', Glimpse.env
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "views" do
|
31
|
+
before do
|
32
|
+
Glimpse.reset
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have none by default" do
|
36
|
+
assert_equal [], Glimpse.views
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be able to append views" do
|
40
|
+
Glimpse.into Staff, :username => 'dewski'
|
41
|
+
assert_kind_of Staff, Glimpse.views.first
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to append views with options" do
|
45
|
+
Glimpse.into Staff, :username => 'dewski'
|
46
|
+
@staff = Glimpse.views.first
|
47
|
+
assert_kind_of Staff, @staff
|
48
|
+
assert_equal 'dewski', @staff.username
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should only return enabled views" do
|
52
|
+
Glimpse.into Staff, :username => false
|
53
|
+
assert_equal [], Glimpse.views
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "reset" do
|
58
|
+
before do
|
59
|
+
Glimpse.reset
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should clear any current views" do
|
63
|
+
Glimpse.into Staff, :username => 'dewski'
|
64
|
+
assert_kind_of Staff, Glimpse.views.first
|
65
|
+
Glimpse.reset
|
66
|
+
assert_equal [], Glimpse.views
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glimpse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Garrett Bjerkhoel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Provide a glimpse into your Rails application.
|
31
|
+
email:
|
32
|
+
- me@garrettbjerkhoel.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- app/assets/images/glimpse/bar/development.gif
|
43
|
+
- app/assets/images/glimpse/bar/production.gif
|
44
|
+
- app/assets/images/glimpse/bar/staging.gif
|
45
|
+
- app/assets/javascripts/glimpse.coffee
|
46
|
+
- app/assets/javascripts/glimpse/vendor/jquery.cookies.js
|
47
|
+
- app/assets/stylesheets/glimpse.scss
|
48
|
+
- app/views/glimpse/_bar.html.erb
|
49
|
+
- app/views/glimpse/_results.html.erb
|
50
|
+
- glimpse.gemspec
|
51
|
+
- lib/glimpse.rb
|
52
|
+
- lib/glimpse/controller_helpers.rb
|
53
|
+
- lib/glimpse/railtie.rb
|
54
|
+
- lib/glimpse/version.rb
|
55
|
+
- lib/glimpse/views/view.rb
|
56
|
+
- test/glimpse/views/view_test.rb
|
57
|
+
- test/glimpse_test.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
homepage: https://github.com/dewski/glimpse
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.23
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Provide a glimpse into your Rails application.
|
83
|
+
test_files:
|
84
|
+
- test/glimpse/views/view_test.rb
|
85
|
+
- test/glimpse_test.rb
|
86
|
+
- test/test_helper.rb
|