rails-footnotes 3.7.2 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.rspec.example +1 -0
- data/.watchr.example +13 -0
- data/Gemfile +1 -1
- data/README.rdoc +9 -6
- data/Rakefile +5 -6
- data/lib/rails-footnotes.rb +4 -3
- data/lib/rails-footnotes/{notes/abstract_note.rb → abstract_note.rb} +4 -4
- data/lib/rails-footnotes/footnotes.rb +0 -6
- data/lib/rails-footnotes/notes/all.rb +1 -0
- data/lib/rails-footnotes/notes/assigns_note.rb +3 -5
- data/lib/rails-footnotes/notes/controller_note.rb +11 -28
- data/lib/rails-footnotes/notes/cookies_note.rb +1 -3
- data/lib/rails-footnotes/notes/env_note.rb +0 -2
- data/lib/rails-footnotes/notes/files_note.rb +1 -3
- data/lib/rails-footnotes/notes/filters_note.rb +4 -6
- data/lib/rails-footnotes/notes/general_note.rb +1 -3
- data/lib/rails-footnotes/notes/javascripts_note.rb +1 -3
- data/lib/rails-footnotes/notes/layout_note.rb +0 -2
- data/lib/rails-footnotes/notes/log_note.rb +4 -6
- data/lib/rails-footnotes/notes/params_note.rb +0 -2
- data/lib/rails-footnotes/notes/partials_note.rb +0 -2
- data/lib/rails-footnotes/notes/queries_note.rb +0 -2
- data/lib/rails-footnotes/notes/routes_note.rb +1 -3
- data/lib/rails-footnotes/notes/session_note.rb +0 -2
- data/lib/rails-footnotes/notes/stylesheets_note.rb +1 -3
- data/lib/rails-footnotes/notes/view_note.rb +0 -2
- data/lib/rails-footnotes/version.rb +1 -1
- data/rails-footnotes.gemspec +2 -2
- data/spec/abstract_note_spec.rb +80 -0
- data/spec/footnotes_spec.rb +215 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +7 -3
- metadata +17 -17
- data/lib/rails-footnotes/backtracer.rb +0 -36
- data/lib/rails-footnotes/notes/rpm_note.rb +0 -30
- data/test/footnotes_test.rb +0 -222
- data/test/notes/abstract_note_test.rb +0 -107
@@ -1,30 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/abstract_note"
|
2
|
-
|
3
|
-
if defined?(NewRelic)
|
4
|
-
module Footnotes
|
5
|
-
module Notes
|
6
|
-
class RpmNote < AbstractNote
|
7
|
-
def initialize(controller)
|
8
|
-
@rpm_id=NewRelic::Agent.instance.transaction_sampler.current_sample_id
|
9
|
-
end
|
10
|
-
|
11
|
-
def row
|
12
|
-
:edit
|
13
|
-
end
|
14
|
-
|
15
|
-
def link
|
16
|
-
#{:controller => 'newrelic', :action => 'show_sample_detail', :id => @rpm_id}
|
17
|
-
"/newrelic/show_sample_detail/#{@rpm_id}" if @rpm_id
|
18
|
-
end
|
19
|
-
|
20
|
-
def valid?
|
21
|
-
if defined?(NewRelic::Control)
|
22
|
-
!NewRelic::Control.instance['skip_developer_route']
|
23
|
-
else
|
24
|
-
!NewRelic::Config.instance['skip_developer_route']
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/test/footnotes_test.rb
DELETED
@@ -1,222 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'action_controller'
|
4
|
-
require 'action_controller/test_case'
|
5
|
-
|
6
|
-
class FootnotesController < ActionController::Base; attr_accessor :template, :performed_render; end
|
7
|
-
|
8
|
-
module Footnotes::Notes
|
9
|
-
class TestNote < AbstractNote
|
10
|
-
def self.to_sym; :test; end
|
11
|
-
def valid?; true; end
|
12
|
-
end
|
13
|
-
|
14
|
-
class NoteXNote < TestNote; end
|
15
|
-
class NoteYNote < TestNote; end
|
16
|
-
class NoteZNote < TestNote; end
|
17
|
-
end
|
18
|
-
|
19
|
-
class FootnotesTest < Test::Unit::TestCase
|
20
|
-
def setup
|
21
|
-
@controller = FootnotesController.new
|
22
|
-
@controller.template = Object.new
|
23
|
-
@controller.request = ActionController::TestRequest.new
|
24
|
-
@controller.response = ActionController::TestResponse.new
|
25
|
-
@controller.response.body = $html.dup
|
26
|
-
@controller.params = {}
|
27
|
-
|
28
|
-
Footnotes::Filter.notes = [ :test ]
|
29
|
-
Footnotes::Filter.multiple_notes = false
|
30
|
-
@footnotes = Footnotes::Filter.new(@controller)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_footnotes_controller
|
34
|
-
index = @controller.response.body.index(/This is the HTML page/)
|
35
|
-
assert_equal 334, index
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_foonotes_included
|
39
|
-
footnotes_perform!
|
40
|
-
assert_not_equal $html, @controller.response.body
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_footnotes_not_included_when_request_is_xhr
|
44
|
-
@controller.request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
45
|
-
@controller.request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
|
46
|
-
|
47
|
-
footnotes_perform!
|
48
|
-
assert_equal $html, @controller.response.body
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_footnotes_not_included_when_content_type_is_javascript
|
52
|
-
@controller.response.headers['Content-Type'] = 'text/javascript'
|
53
|
-
|
54
|
-
footnotes_perform!
|
55
|
-
assert_equal $html, @controller.response.body
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_footnotes_included_when_content_type_is_html
|
59
|
-
@controller.response.headers['Content-Type'] = 'text/html'
|
60
|
-
|
61
|
-
footnotes_perform!
|
62
|
-
assert_not_equal $html, @controller.response.body
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_footnotes_included_when_content_type_is_nil
|
66
|
-
footnotes_perform!
|
67
|
-
assert_not_equal $html, @controller.response.body
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_not_included_when_body_is_not_a_string
|
71
|
-
@controller.response.body = Proc.new{ Time.now }
|
72
|
-
assert_nothing_raised do
|
73
|
-
footnotes_perform!
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_footnotes_prefix
|
78
|
-
assert_equal 'txmt://open?url=file://%s&line=%d&column=%d', Footnotes::Filter.prefix
|
79
|
-
assert_equal 'txmt://open?url=file://file&line=0&column=0', Footnotes::Filter.prefix('file', 0, 0)
|
80
|
-
assert_equal 'txmt://open?url=file://file&line=10&column=10', Footnotes::Filter.prefix('file', 10, 10)
|
81
|
-
assert_equal 'txmt://open?url=file://file&line=10&column=10', Footnotes::Filter.prefix('file', 10, 10, 10)
|
82
|
-
assert_equal 'txmt://open?url=file://file&line=10&column=10', Footnotes::Filter.prefix('file', '10', '10')
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_notes_are_initialized
|
86
|
-
footnotes_perform!
|
87
|
-
test_note = @footnotes.instance_variable_get('@notes').first
|
88
|
-
assert_equal 'Footnotes::Notes::TestNote', test_note.class.name
|
89
|
-
assert_equal :test, test_note.to_sym
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_notes_links
|
93
|
-
note = Footnotes::Notes::TestNote.new
|
94
|
-
note.expects(:row).times(2)
|
95
|
-
@footnotes.instance_variable_set(:@notes, [note])
|
96
|
-
footnotes_perform!
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_notes_fieldset
|
100
|
-
note = Footnotes::Notes::TestNote.new
|
101
|
-
note.expects(:has_fieldset?).times(3)
|
102
|
-
@footnotes.instance_variable_set(:@notes, [note])
|
103
|
-
footnotes_perform!
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_multiple_notes
|
107
|
-
Footnotes::Filter.multiple_notes = true
|
108
|
-
note = Footnotes::Notes::TestNote.new
|
109
|
-
note.expects(:has_fieldset?).times(2)
|
110
|
-
@footnotes.instance_variable_set(:@notes, [note])
|
111
|
-
footnotes_perform!
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_notes_are_reset
|
115
|
-
note = Footnotes::Notes::TestNote.new
|
116
|
-
note.class.expects(:close!)
|
117
|
-
@footnotes.instance_variable_set(:@notes, [note])
|
118
|
-
@footnotes.send(:close!, @controller)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_links_helper
|
122
|
-
note = Footnotes::Notes::TestNote.new
|
123
|
-
assert_equal '<a href="#" onclick="">Test</a>', @footnotes.send(:link_helper, note)
|
124
|
-
|
125
|
-
note.expects(:link).times(1).returns(:link)
|
126
|
-
assert_equal '<a href="link" onclick="">Test</a>', @footnotes.send(:link_helper, note)
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_links_helper_has_fieldset?
|
130
|
-
note = Footnotes::Notes::TestNote.new
|
131
|
-
note.expects(:has_fieldset?).times(1).returns(true)
|
132
|
-
assert_equal '<a href="#" onclick="Footnotes.hideAllAndToggle(\'test_debug_info\');return false;">Test</a>', @footnotes.send(:link_helper, note)
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_links_helper_onclick
|
136
|
-
note = Footnotes::Notes::TestNote.new
|
137
|
-
note.expects(:onclick).times(2).returns(:onclick)
|
138
|
-
assert_equal '<a href="#" onclick="onclick">Test</a>', @footnotes.send(:link_helper, note)
|
139
|
-
|
140
|
-
note.expects(:has_fieldset?).times(1).returns(true)
|
141
|
-
assert_equal '<a href="#" onclick="onclick">Test</a>', @footnotes.send(:link_helper, note)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_insert_style
|
145
|
-
@controller.response.body = "<head></head><split><body></body>"
|
146
|
-
@footnotes = Footnotes::Filter.new(@controller)
|
147
|
-
footnotes_perform!
|
148
|
-
assert @controller.response.body.split('<split>').first.include?('<!-- Footnotes Style -->')
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_insert_footnotes_inside_body
|
152
|
-
@controller.response.body = "<head></head><split><body></body>"
|
153
|
-
@footnotes = Footnotes::Filter.new(@controller)
|
154
|
-
footnotes_perform!
|
155
|
-
assert @controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->')
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_insert_footnotes_inside_holder
|
159
|
-
@controller.response.body = "<head></head><split><div id='footnotes_holder'></div>"
|
160
|
-
@footnotes = Footnotes::Filter.new(@controller)
|
161
|
-
footnotes_perform!
|
162
|
-
assert @controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->')
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_insert_text
|
166
|
-
@footnotes.send(:insert_text, :after, /<head>/, "Graffiti")
|
167
|
-
after = " <head>Graffiti"
|
168
|
-
assert_equal after, @controller.response.body.split("\n")[2]
|
169
|
-
|
170
|
-
@footnotes.send(:insert_text, :before, /<\/body>/, "Notes")
|
171
|
-
after = " Notes</body>"
|
172
|
-
assert_equal after, @controller.response.body.split("\n")[12]
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_hooks
|
176
|
-
Footnotes::Filter.notes = [:note_x, :note_y, :note_z]
|
177
|
-
Footnotes.setup {|config| config.before {|controller, filter| filter.notes -= [:note_y] }}
|
178
|
-
Footnotes::Filter.start!(@controller)
|
179
|
-
assert_equal [:note_x, :note_z], Footnotes::Filter.notes
|
180
|
-
|
181
|
-
Footnotes.setup {|config| config.after {|controller, filter| filter.notes -= [:note_y] }}
|
182
|
-
@footnotes.close!(@controller)
|
183
|
-
assert_equal [:note_x, :note_z], Footnotes::Filter.notes
|
184
|
-
end
|
185
|
-
|
186
|
-
protected
|
187
|
-
# First we make sure that footnotes will perform (long life to mocha!)
|
188
|
-
# Then we call add_footnotes!
|
189
|
-
#
|
190
|
-
def footnotes_perform!
|
191
|
-
template_expects('html')
|
192
|
-
@controller.performed_render = true
|
193
|
-
|
194
|
-
Footnotes::Filter.start!(@controller)
|
195
|
-
@footnotes.add_footnotes!
|
196
|
-
end
|
197
|
-
|
198
|
-
def template_expects(format)
|
199
|
-
if @controller.template.respond_to?(:template_format)
|
200
|
-
@controller.template.expects(:template_format).returns(format)
|
201
|
-
else
|
202
|
-
@controller.template.expects(:format).returns(format)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
$html = <<HTML
|
208
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
209
|
-
<html>
|
210
|
-
<head>
|
211
|
-
<title>HTML to XHTML Example: HTML page</title>
|
212
|
-
<link rel="Stylesheet" href="htmltohxhtml.css" type="text/css" media="screen">
|
213
|
-
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
214
|
-
</head>
|
215
|
-
<body>
|
216
|
-
<p>This is the HTML page. It works and is encoded just like any HTML page you
|
217
|
-
have previously done. View <a href="htmltoxhtml2.htm">the XHTML version</a> of
|
218
|
-
this page to view the difference between HTML and XHTML.</p>
|
219
|
-
<p>You will be glad to know that no changes need to be made to any of your CSS files.</p>
|
220
|
-
</body>
|
221
|
-
</html>
|
222
|
-
HTML
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AbstractNoteTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@note = Footnotes::Notes::AbstractNote.new
|
6
|
-
Footnotes::Filter.notes = [:abstract]
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_respond_to_start_and_close
|
10
|
-
assert_respond_to Footnotes::Notes::AbstractNote, :start!
|
11
|
-
assert_respond_to Footnotes::Notes::AbstractNote, :close!
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_respond_to_sym
|
15
|
-
assert_equal :abstract, Footnotes::Notes::AbstractNote.to_sym
|
16
|
-
assert_equal :abstract, @note.to_sym
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_respond_to_included?
|
20
|
-
assert Footnotes::Notes::AbstractNote.included?
|
21
|
-
Footnotes::Filter.notes = []
|
22
|
-
assert !Footnotes::Notes::AbstractNote.included?
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_respond_to_row
|
26
|
-
assert_equal :show, @note.row
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_respond_to_title
|
30
|
-
assert_respond_to @note.class, :title
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_respond_to_legend
|
34
|
-
assert_respond_to @note, :legend
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_respond_to_link
|
38
|
-
assert_respond_to @note, :link
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_respond_to_onclick
|
42
|
-
assert_respond_to @note, :onclick
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_respond_to_stylesheet
|
46
|
-
assert_respond_to @note, :stylesheet
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_respond_to_javascript
|
50
|
-
assert_respond_to @note, :javascript
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_respond_to_valid?
|
54
|
-
assert_respond_to @note, :valid?
|
55
|
-
assert @note.valid?
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_respond_to_has_fieldset?
|
59
|
-
assert_respond_to @note, :has_fieldset?
|
60
|
-
assert !@note.has_fieldset?
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_footnotes_prefix
|
64
|
-
Footnotes::Filter.prefix = ''
|
65
|
-
assert !@note.send(:prefix?)
|
66
|
-
Footnotes::Filter.prefix = 'txmt://open?url=file://%s&line=%d&column=%d'
|
67
|
-
assert @note.send(:prefix?)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_footnotes_escape
|
71
|
-
assert_equal '<', @note.send(:escape,'<')
|
72
|
-
assert_equal '&', @note.send(:escape,'&')
|
73
|
-
assert_equal '>', @note.send(:escape,'>')
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_footnotes_mount_table
|
77
|
-
assert_equal '', @note.send(:mount_table,[])
|
78
|
-
assert_equal '', @note.send(:mount_table,[['h1','h2','h3']], :class => 'table')
|
79
|
-
|
80
|
-
tab = <<-TABLE
|
81
|
-
<table class="table" >
|
82
|
-
<thead><tr><th>H1</th></tr></thead>
|
83
|
-
<tbody><tr><td>r1c1</td></tr></tbody>
|
84
|
-
</table>
|
85
|
-
TABLE
|
86
|
-
|
87
|
-
assert_equal tab, @note.send(:mount_table,[['h1'],['r1c1']], :class => 'table')
|
88
|
-
|
89
|
-
tab = <<-TABLE
|
90
|
-
<table >
|
91
|
-
<thead><tr><th>H1</th><th>H2</th><th>H3</th></tr></thead>
|
92
|
-
<tbody><tr><td>r1c1</td><td>r1c2</td><td>r1c3</td></tr></tbody>
|
93
|
-
</table>
|
94
|
-
TABLE
|
95
|
-
|
96
|
-
assert_equal tab, @note.send(:mount_table,[['h1','h2','h3'],['r1c1','r1c2','r1c3']])
|
97
|
-
|
98
|
-
tab = <<-TABLE
|
99
|
-
<table >
|
100
|
-
<thead><tr><th>H1</th><th>H2</th><th>H3</th></tr></thead>
|
101
|
-
<tbody><tr><td>r1c1</td><td>r1c2</td><td>r1c3</td></tr><tr><td>r2c1</td><td>r2c2</td><td>r2c3</td></tr></tbody>
|
102
|
-
</table>
|
103
|
-
TABLE
|
104
|
-
|
105
|
-
assert_equal tab, @note.send(:mount_table,[['h1','h2','h3'],['r1c1','r1c2','r1c3'],['r2c1','r2c2','r2c3']])
|
106
|
-
end
|
107
|
-
end
|