rails-footnotes 7.0.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- it "foonotes_included" do
69
- footnotes_perform!
70
- expect(@controller.response_body).not_to eq(HTML_DOCUMENT)
71
- end
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
- it "should escape links with special chars" do
74
- note_with_link = Footnotes::Notes::FileURINote.new
75
- link = Footnotes::Filter.prefix(note_with_link.link, 1, 1, 1)
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
- specify "footnotes_not_included_when_request_is_xhr" do
80
- @controller.request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
81
- @controller.request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
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
- specify "footnotes_not_included_when_content_type_is_javascript" do
87
- @controller.response.content_type = 'text/javascript'
88
- footnotes_perform!
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
- specify "footnotes_included_when_content_type_is_html" do
93
- @controller.response.content_type = 'text/html; charset=utf-8'
94
- footnotes_perform!
95
- expect(@controller.response.body).not_to eql HTML_DOCUMENT
96
- end
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
- specify "footnotes_included_when_content_type_is_nil" do
99
- footnotes_perform!
100
- expect(@controller.response.body).not_to eql HTML_DOCUMENT
101
- end
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
- specify "not_included_when_body_is_not_a_string" do
104
- allow(@controller.response).to receive(:body).and_return(Time.now)# = Proc.new { Time.now }
105
- expect(Footnotes::Filter.new(@controller).send(:valid?)).not_to be
106
- expect(@controller.response.body).not_to match(/<!-- Footnotes/)
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
- specify "notes_are_initialized" do
110
- footnotes_perform!
111
- test_note = @footnotes.instance_variable_get('@notes').first
112
- expect(test_note.class.name).to eql 'Footnotes::Notes::TestNote'
113
- expect(test_note.to_sym).to eql :test
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&amp;line=1&amp;column=1"
109
+ end
115
110
 
116
- specify "notes_links" do
117
- note = Footnotes::Notes::TestNote.new
118
- expect(note).to receive(:row).twice
119
- @footnotes.instance_variable_set(:@notes, [note])
120
- footnotes_perform!
121
- end
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
- specify "notes_fieldset" do
124
- note = Footnotes::Notes::TestNote.new
125
- expect(note).to receive(:has_fieldset?).exactly(3).times
126
- @footnotes.instance_variable_set(:@notes, [note])
127
- footnotes_perform!
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
- specify "multiple_notes" do
131
- Footnotes::Filter.multiple_notes = true
132
- note = Footnotes::Notes::TestNote.new
133
- expect(note).to receive(:has_fieldset?).twice
134
- @footnotes.instance_variable_set(:@notes, [note])
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
- specify "notes_are_reset" do
139
- note = Footnotes::Notes::TestNote.new
140
- expect(note.class).to receive(:close!)
141
- @footnotes.instance_variable_set(:@notes, [note])
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
- specify "links_helper" do
146
- note = Footnotes::Notes::TestNote.new
147
- expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="">Test</a>'
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
- expect(note).to receive(:link).once.and_return(:link)
150
- expect(@footnotes.send(:link_helper, note)).to eql '<a href="link" onclick="">Test</a>'
151
- end
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
- specify "links_helper_has_fieldset?" do
154
- note = Footnotes::Notes::TestNote.new
155
- expect(note).to receive(:has_fieldset?).once.and_return(true)
156
- expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="Footnotes.hideAllAndToggle(\'test_debug_info\');return false;">Test</a>'
157
- end
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
- specify "links_helper_onclick" do
160
- note = Footnotes::Notes::TestNote.new
161
- expect(note).to receive(:onclick).twice.and_return(:onclick)
162
- expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="onclick">Test</a>'
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
- expect(note).to receive(:has_fieldset?).once.and_return(true)
165
- expect(@footnotes.send(:link_helper, note)).to eql '<a href="#" onclick="onclick">Test</a>'
166
- end
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
- specify "insert_style" do
169
- @controller.response.body = "<head></head><split><body></body>"
170
- @footnotes = Footnotes::Filter.new(@controller)
171
- footnotes_perform!
172
- expect(@controller.response.body.split('<split>').first.include?('<!-- Footnotes Style -->')).to be
173
- end
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
- specify "insert_footnotes_inside_body" do
176
- @controller.response.body = "<head></head><split><body></body>"
177
- @footnotes = Footnotes::Filter.new(@controller)
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
- specify "insert_footnotes_inside_holder" do
183
- @controller.response.body = "<head></head><split><div id='footnotes_holder'></div>"
184
- @footnotes = Footnotes::Filter.new(@controller)
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
- specify "insert_text" do
190
- @footnotes.send(:insert_text, :after, /<head>/, "Graffiti")
191
- after = " <head>Graffiti"
192
- expect(@controller.response.body.split("\n")[2]).to eql after
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
- @footnotes.send(:insert_text, :before, /<\/body>/, "Notes")
195
- after = " Notes</body>"
196
- expect(@controller.response.body.split("\n")[12]).to eql after
197
- end
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
- describe 'Hooks' do
200
- before {Footnotes::Filter.notes = [:note_x, :note_y, :note_z]}
201
- context 'before' do
202
- specify do
203
- Footnotes.setup {|config| config.before {|controller, filter| filter.notes -= [:note_y] }}
204
- Footnotes::Filter.start!(@controller)
205
- expect(Footnotes::Filter.notes).to eql [:note_x, :note_z]
206
- end
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
- context "after" do
209
- specify do
210
- Footnotes.setup {|config| config.after {|controller, filter| filter.notes -= [:note_y] }}
211
- Footnotes::Filter.start!(@controller)
212
- expect(Footnotes::Filter.notes).to eql [:note_x, :note_z]
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 'action_controller'
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(:note) do
7
- @controller = double
8
- allow(@controller).to receive(:instance_variables).and_return([:@action_has_layout, :@status])
9
- @controller.instance_variable_set(:@action_has_layout, true)
10
- @controller.instance_variable_set(:@status, 200)
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 {note}
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>", "#&lt;ActiveRecord::Relation []&gt;"],
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.0
4
+ version: 7.1.0
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-11-29 00:00:00.000000000 Z
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.rdoc
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