rails-footnotes 7.0.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +107 -68
- data/{README.rdoc → README.md} +65 -59
- data/lib/generators/templates/rails_footnotes.rb +3 -0
- data/lib/rails-footnotes/filter.rb +42 -29
- data/lib/rails-footnotes/notes/assigns_note.rb +23 -20
- data/lib/rails-footnotes/notes/controller_note.rb +1 -1
- data/lib/rails-footnotes/notes/log_note/note_logger.rb +0 -38
- data/lib/rails-footnotes/notes/log_note.rb +8 -5
- data/lib/rails-footnotes/notes/partials_note.rb +2 -2
- data/lib/rails-footnotes/notes/queries_note.rb +4 -6
- data/lib/rails-footnotes/notes/view_note.rb +4 -4
- data/lib/rails-footnotes/version.rb +1 -1
- data/lib/rails-footnotes.rb +18 -16
- data/rails-footnotes.gemspec +1 -3
- data/spec/footnotes_spec.rb +173 -140
- data/spec/notes/assigns_note_spec.rb +27 -9
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +22 -0
- metadata +5 -3
data/spec/footnotes_spec.rb
CHANGED
@@ -27,30 +27,23 @@ module Footnotes::Notes
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "Footnotes" do
|
30
|
-
before do
|
31
|
-
@controller = FootnotesController.new
|
32
|
-
@controller.template = Object.new
|
33
|
-
@controller.request = ActionDispatch::TestRequest.create
|
34
|
-
@controller.response = ActionDispatch::TestResponse.new
|
35
|
-
@controller.response_body = HTML_DOCUMENT.dup
|
36
|
-
@controller.params = {}
|
37
|
-
|
38
|
-
Footnotes::Filter.notes = [ :test ]
|
39
|
-
Footnotes::Filter.multiple_notes = false
|
40
|
-
@footnotes = Footnotes::Filter.new(@controller)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "footnotes_controller" do
|
44
|
-
index = @controller.response.body.index(/This is the HTML page/)
|
45
|
-
expect(index).to eql 334
|
46
|
-
end
|
47
|
-
|
48
30
|
context "response_body is file" do
|
49
31
|
before do
|
32
|
+
@controller = FootnotesController.new
|
33
|
+
@controller.template = Object.new
|
34
|
+
@controller.request = ActionDispatch::TestRequest.create
|
35
|
+
@controller.response = ActionDispatch::TestResponse.new
|
36
|
+
@controller.params = {}
|
37
|
+
|
38
|
+
Footnotes::Filter.notes = [ :test ]
|
39
|
+
Footnotes::Filter.multiple_notes = false
|
40
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
41
|
+
|
50
42
|
@file = Tempfile.new("test")
|
51
43
|
def @file.body; read; end
|
52
44
|
@file.write "foobarbaz"
|
53
45
|
@file.rewind
|
46
|
+
@controller.response_body = @file
|
54
47
|
end
|
55
48
|
|
56
49
|
after do
|
@@ -58,158 +51,198 @@ describe "Footnotes" do
|
|
58
51
|
end
|
59
52
|
|
60
53
|
it "should not change file position" do
|
61
|
-
@controller.response_body = @file
|
62
54
|
expect {
|
63
55
|
@footnotes = Footnotes::Filter.new(@controller)
|
64
56
|
}.not_to change{ @controller.response_body.pos }
|
65
57
|
end
|
66
58
|
end
|
67
59
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
60
|
+
context "response_body is Rack::File::Iterator" do
|
61
|
+
before do
|
62
|
+
@controller = FootnotesController.new
|
63
|
+
@controller.template = Object.new
|
64
|
+
@controller.request = ActionDispatch::TestRequest.create
|
65
|
+
@controller.response = ActionDispatch::TestResponse.new
|
66
|
+
@controller.params = {}
|
72
67
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
expect(link).to eql "txmt://open?url=file:///example/local%20file%20path/with-special-chars/%C3%B6%C3%A4%C3%BC/file&line=1&column=1"
|
77
|
-
end
|
68
|
+
Footnotes::Filter.notes = [ :test ]
|
69
|
+
Footnotes::Filter.multiple_notes = false
|
70
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
78
71
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
footnotes_perform!
|
83
|
-
expect(@controller.response.body).to eql HTML_DOCUMENT
|
84
|
-
end
|
72
|
+
@file = Rack::File::Iterator.new("README.md", (0..-1), {})
|
73
|
+
@controller.response_body = @file
|
74
|
+
end
|
85
75
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
expect(@controller.response.body).to eql HTML_DOCUMENT
|
76
|
+
it "should work" do
|
77
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
78
|
+
end
|
90
79
|
end
|
91
80
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
81
|
+
context "response_body is HTML" do
|
82
|
+
before do
|
83
|
+
@controller = FootnotesController.new
|
84
|
+
@controller.template = Object.new
|
85
|
+
@controller.request = ActionDispatch::TestRequest.create
|
86
|
+
@controller.response = ActionDispatch::TestResponse.new
|
87
|
+
@controller.response_body = HTML_DOCUMENT.dup
|
88
|
+
@controller.params = {}
|
89
|
+
|
90
|
+
Footnotes::Filter.notes = [ :test ]
|
91
|
+
Footnotes::Filter.multiple_notes = false
|
92
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
93
|
+
end
|
97
94
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
95
|
+
it "footnotes_controller" do
|
96
|
+
index = @controller.response.body.index(/This is the HTML page/)
|
97
|
+
expect(index).to eql 334
|
98
|
+
end
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
100
|
+
it "foonotes_included" do
|
101
|
+
footnotes_perform!
|
102
|
+
expect(@controller.response_body).not_to eq(HTML_DOCUMENT)
|
103
|
+
end
|
108
104
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
105
|
+
it "should escape links with special chars" do
|
106
|
+
note_with_link = Footnotes::Notes::FileURINote.new
|
107
|
+
link = Footnotes::Filter.prefix(note_with_link.link, 1, 1, 1)
|
108
|
+
expect(link).to eql "txmt://open?url=file:///example/local%20file%20path/with-special-chars/%C3%B6%C3%A4%C3%BC/file&line=1&column=1"
|
109
|
+
end
|
115
110
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
111
|
+
specify "footnotes_not_included_when_request_is_xhr" do
|
112
|
+
@controller.request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
113
|
+
@controller.request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
|
114
|
+
footnotes_perform!
|
115
|
+
expect(@controller.response.body).to eql HTML_DOCUMENT
|
116
|
+
end
|
122
117
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
118
|
+
specify "footnotes_not_included_when_content_type_is_javascript" do
|
119
|
+
@controller.response.content_type = 'text/javascript'
|
120
|
+
footnotes_perform!
|
121
|
+
expect(@controller.response.body).to eql HTML_DOCUMENT
|
122
|
+
end
|
129
123
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
footnotes_perform!
|
136
|
-
end
|
124
|
+
specify "footnotes_included_when_content_type_is_html" do
|
125
|
+
@controller.response.content_type = 'text/html; charset=utf-8'
|
126
|
+
footnotes_perform!
|
127
|
+
expect(@controller.response.body).not_to eql HTML_DOCUMENT
|
128
|
+
end
|
137
129
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
@footnotes.send(:close!, @controller)
|
143
|
-
end
|
130
|
+
specify "footnotes_included_when_content_type_is_nil" do
|
131
|
+
footnotes_perform!
|
132
|
+
expect(@controller.response.body).not_to eql HTML_DOCUMENT
|
133
|
+
end
|
144
134
|
|
145
|
-
|
146
|
-
|
147
|
-
|
135
|
+
specify "not_included_when_body_is_not_a_string" do
|
136
|
+
allow(@controller.response).to receive(:body).and_return(Time.now)# = Proc.new { Time.now }
|
137
|
+
expect(Footnotes::Filter.new(@controller).send(:valid?)).not_to be
|
138
|
+
expect(@controller.response.body).not_to match(/<!-- Footnotes/)
|
139
|
+
end
|
148
140
|
|
149
|
-
|
150
|
-
|
151
|
-
|
141
|
+
specify "notes_are_initialized" do
|
142
|
+
footnotes_perform!
|
143
|
+
test_note = @footnotes.instance_variable_get('@notes').first
|
144
|
+
expect(test_note.class.name).to eql 'Footnotes::Notes::TestNote'
|
145
|
+
expect(test_note.to_sym).to eql :test
|
146
|
+
end
|
152
147
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
148
|
+
specify "notes_links" do
|
149
|
+
note = Footnotes::Notes::TestNote.new
|
150
|
+
expect(note).to receive(:row).twice
|
151
|
+
@footnotes.instance_variable_set(:@notes, [note])
|
152
|
+
footnotes_perform!
|
153
|
+
end
|
158
154
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
155
|
+
specify "notes_fieldset" do
|
156
|
+
note = Footnotes::Notes::TestNote.new
|
157
|
+
expect(note).to receive(:has_fieldset?).exactly(3).times
|
158
|
+
@footnotes.instance_variable_set(:@notes, [note])
|
159
|
+
footnotes_perform!
|
160
|
+
end
|
163
161
|
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
specify "multiple_notes" do
|
163
|
+
Footnotes::Filter.multiple_notes = true
|
164
|
+
note = Footnotes::Notes::TestNote.new
|
165
|
+
expect(note).to receive(:has_fieldset?).twice
|
166
|
+
@footnotes.instance_variable_set(:@notes, [note])
|
167
|
+
footnotes_perform!
|
168
|
+
end
|
167
169
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
specify "notes_are_reset" do
|
171
|
+
note = Footnotes::Notes::TestNote.new
|
172
|
+
expect(note.class).to receive(:close!)
|
173
|
+
@footnotes.instance_variable_set(:@notes, [note])
|
174
|
+
@footnotes.send(:close!, @controller)
|
175
|
+
end
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
footnotes_perform!
|
179
|
-
expect(@controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->')).to be
|
180
|
-
end
|
177
|
+
specify "links_helper" do
|
178
|
+
note = Footnotes::Notes::TestNote.new
|
179
|
+
expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="">Test</a>'
|
181
180
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
footnotes_perform!
|
186
|
-
expect(@controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->')).to be
|
187
|
-
end
|
181
|
+
expect(note).to receive(:link).once.and_return(:link)
|
182
|
+
expect(@footnotes.send(:link_helper, note)).to eql '<a href="link" onclick="">Test</a>'
|
183
|
+
end
|
188
184
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
185
|
+
specify "links_helper_has_fieldset?" do
|
186
|
+
note = Footnotes::Notes::TestNote.new
|
187
|
+
expect(note).to receive(:has_fieldset?).once.and_return(true)
|
188
|
+
expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="Footnotes.hideAllAndToggle(\'test_debug_info\');return false;">Test</a>'
|
189
|
+
end
|
193
190
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
191
|
+
specify "links_helper_onclick" do
|
192
|
+
note = Footnotes::Notes::TestNote.new
|
193
|
+
expect(note).to receive(:onclick).twice.and_return(:onclick)
|
194
|
+
expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="onclick">Test</a>'
|
198
195
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
196
|
+
expect(note).to receive(:has_fieldset?).once.and_return(true)
|
197
|
+
expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="onclick">Test</a>'
|
198
|
+
end
|
199
|
+
|
200
|
+
specify "insert_style" do
|
201
|
+
@controller.response.body = "<head></head><split><body></body>"
|
202
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
203
|
+
footnotes_perform!
|
204
|
+
expect(@controller.response.body.split('<split>').first.include?('<!-- Footnotes Style -->')).to be
|
205
|
+
end
|
206
|
+
|
207
|
+
specify "insert_footnotes_inside_body" do
|
208
|
+
@controller.response.body = "<head></head><split><body></body>"
|
209
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
210
|
+
footnotes_perform!
|
211
|
+
expect(@controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->')).to be
|
207
212
|
end
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
+
|
214
|
+
specify "insert_footnotes_inside_holder" do
|
215
|
+
@controller.response.body = "<head></head><split><div id='footnotes_holder'></div>"
|
216
|
+
@footnotes = Footnotes::Filter.new(@controller)
|
217
|
+
footnotes_perform!
|
218
|
+
expect(@controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->')).to be
|
219
|
+
end
|
220
|
+
|
221
|
+
specify "insert_text" do
|
222
|
+
@footnotes.send(:insert_text, :after, /<head>/, "Graffiti")
|
223
|
+
after = " <head>Graffiti"
|
224
|
+
expect(@controller.response.body.split("\n")[2]).to eql after
|
225
|
+
|
226
|
+
@footnotes.send(:insert_text, :before, /<\/body>/, "Notes")
|
227
|
+
after = " Notes</body>"
|
228
|
+
expect(@controller.response.body.split("\n")[12]).to eql after
|
229
|
+
end
|
230
|
+
|
231
|
+
describe 'Hooks' do
|
232
|
+
before {Footnotes::Filter.notes = [:note_x, :note_y, :note_z]}
|
233
|
+
context 'before' do
|
234
|
+
specify do
|
235
|
+
Footnotes.setup {|config| config.before {|controller, filter| filter.notes -= [:note_y] }}
|
236
|
+
Footnotes::Filter.start!(@controller)
|
237
|
+
expect(Footnotes::Filter.notes).to eql [:note_x, :note_z]
|
238
|
+
end
|
239
|
+
end
|
240
|
+
context "after" do
|
241
|
+
specify do
|
242
|
+
Footnotes.setup {|config| config.after {|controller, filter| filter.notes -= [:note_y] }}
|
243
|
+
Footnotes::Filter.start!(@controller)
|
244
|
+
expect(Footnotes::Filter.notes).to eql [:note_x, :note_z]
|
245
|
+
end
|
213
246
|
end
|
214
247
|
end
|
215
248
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require
|
2
|
+
require "action_controller"
|
3
3
|
require "rails-footnotes/notes/assigns_note"
|
4
|
+
require "support/active_record"
|
4
5
|
|
5
6
|
describe Footnotes::Notes::AssignsNote do
|
6
|
-
let(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Footnotes::Notes::AssignsNote.new(@controller)
|
7
|
+
let(:controller) do
|
8
|
+
double(instance_variables: [:@action_has_layout, :@status]).tap do |c|
|
9
|
+
c.instance_variable_set(:@action_has_layout, true)
|
10
|
+
c.instance_variable_set(:@status, 200)
|
11
|
+
end
|
12
12
|
end
|
13
|
-
subject {
|
13
|
+
subject(:note) { Footnotes::Notes::AssignsNote.new(controller) }
|
14
14
|
|
15
15
|
before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns = []}
|
16
16
|
|
17
|
-
it {should be_valid}
|
17
|
+
it { should be_valid }
|
18
18
|
|
19
19
|
describe '#title' do
|
20
20
|
subject { super().title }
|
@@ -47,4 +47,22 @@ describe Footnotes::Notes::AssignsNote do
|
|
47
47
|
], {:summary=>"Debug information for Assigns (2)"})
|
48
48
|
note.content
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "when it is an ActiveRecord::Relation" do
|
52
|
+
let(:controller) do
|
53
|
+
double(instance_variables: [:@widgets]).tap do |c|
|
54
|
+
c.instance_variable_set(:@widgets, Widget.all)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should still work" do
|
59
|
+
expect(note).to receive(:mount_table).with(
|
60
|
+
[
|
61
|
+
["Name", "Value"],
|
62
|
+
["<strong>@widgets</strong><br /><em>ActiveRecord::Relation</em>", "#<ActiveRecord::Relation []>"],
|
63
|
+
], {:summary=>"Debug information for Assigns (1)"})
|
64
|
+
expect(note).to be_valid
|
65
|
+
note.content
|
66
|
+
end
|
67
|
+
end
|
50
68
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -30,12 +30,12 @@ module Helpers
|
|
30
30
|
end
|
31
31
|
|
32
32
|
RSpec.configure do |config|
|
33
|
-
|
34
33
|
Rails.application.initialize!
|
35
34
|
|
36
35
|
config.include Capybara::DSL
|
37
36
|
config.include Helpers
|
38
37
|
config.example_status_persistence_file_path = ".rspec_results"
|
38
|
+
config.filter_run_when_matching :focus
|
39
39
|
|
40
40
|
Rails.application.routes.draw do
|
41
41
|
get 'footnotes/foo'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
4
|
+
|
5
|
+
ActiveRecord::Migration.verbose = false
|
6
|
+
|
7
|
+
ActiveRecord::Migration.create_table :widgets do |t|
|
8
|
+
t.string :name
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
class Widget < ActiveRecord::Base
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.around do |example|
|
17
|
+
ActiveRecord::Base.transaction do
|
18
|
+
example.run
|
19
|
+
raise ActiveRecord::Rollback
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-footnotes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.
|
4
|
+
version: 7.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman V. Babenko
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2023-
|
16
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rails
|
@@ -47,7 +47,7 @@ files:
|
|
47
47
|
- Gemfile
|
48
48
|
- Gemfile.lock
|
49
49
|
- MIT-LICENSE
|
50
|
-
- README.
|
50
|
+
- README.md
|
51
51
|
- Rakefile
|
52
52
|
- bin/rake
|
53
53
|
- bin/rspec
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- spec/notes/stylesheets_note_spec.rb
|
107
107
|
- spec/notes/view_note_spec.rb
|
108
108
|
- spec/spec_helper.rb
|
109
|
+
- spec/support/active_record.rb
|
109
110
|
homepage: http://github.com/indirect/rails-footnotes
|
110
111
|
licenses: []
|
111
112
|
metadata: {}
|
@@ -152,3 +153,4 @@ test_files:
|
|
152
153
|
- spec/notes/stylesheets_note_spec.rb
|
153
154
|
- spec/notes/view_note_spec.rb
|
154
155
|
- spec/spec_helper.rb
|
156
|
+
- spec/support/active_record.rb
|