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.
Files changed (37) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec.example +1 -0
  3. data/.watchr.example +13 -0
  4. data/Gemfile +1 -1
  5. data/README.rdoc +9 -6
  6. data/Rakefile +5 -6
  7. data/lib/rails-footnotes.rb +4 -3
  8. data/lib/rails-footnotes/{notes/abstract_note.rb → abstract_note.rb} +4 -4
  9. data/lib/rails-footnotes/footnotes.rb +0 -6
  10. data/lib/rails-footnotes/notes/all.rb +1 -0
  11. data/lib/rails-footnotes/notes/assigns_note.rb +3 -5
  12. data/lib/rails-footnotes/notes/controller_note.rb +11 -28
  13. data/lib/rails-footnotes/notes/cookies_note.rb +1 -3
  14. data/lib/rails-footnotes/notes/env_note.rb +0 -2
  15. data/lib/rails-footnotes/notes/files_note.rb +1 -3
  16. data/lib/rails-footnotes/notes/filters_note.rb +4 -6
  17. data/lib/rails-footnotes/notes/general_note.rb +1 -3
  18. data/lib/rails-footnotes/notes/javascripts_note.rb +1 -3
  19. data/lib/rails-footnotes/notes/layout_note.rb +0 -2
  20. data/lib/rails-footnotes/notes/log_note.rb +4 -6
  21. data/lib/rails-footnotes/notes/params_note.rb +0 -2
  22. data/lib/rails-footnotes/notes/partials_note.rb +0 -2
  23. data/lib/rails-footnotes/notes/queries_note.rb +0 -2
  24. data/lib/rails-footnotes/notes/routes_note.rb +1 -3
  25. data/lib/rails-footnotes/notes/session_note.rb +0 -2
  26. data/lib/rails-footnotes/notes/stylesheets_note.rb +1 -3
  27. data/lib/rails-footnotes/notes/view_note.rb +0 -2
  28. data/lib/rails-footnotes/version.rb +1 -1
  29. data/rails-footnotes.gemspec +2 -2
  30. data/spec/abstract_note_spec.rb +80 -0
  31. data/spec/footnotes_spec.rb +215 -0
  32. data/{test/test_helper.rb → spec/spec_helper.rb} +7 -3
  33. metadata +17 -17
  34. data/lib/rails-footnotes/backtracer.rb +0 -36
  35. data/lib/rails-footnotes/notes/rpm_note.rb +0 -30
  36. data/test/footnotes_test.rb +0 -222
  37. data/test/notes/abstract_note_test.rb +0 -107
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class ViewNote < AbstractNote
@@ -1,3 +1,3 @@
1
1
  module Footnotes
2
- VERSION = "3.7.2"
2
+ VERSION = "3.7.3"
3
3
  end
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency "rails", ">= 3.0.0"
18
18
 
19
- s.add_development_dependency "autotest"
20
- s.add_development_dependency "mocha"
21
19
  s.add_development_dependency "rails", ">= 3.0.0"
20
+ s.add_development_dependency "rspec"
21
+ s.add_development_dependency "watchr"
22
22
 
23
23
  s.files = `git ls-files`.split("\n")
24
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ describe Footnotes::Notes::AbstractNote do
4
+ before do
5
+ @note = Footnotes::Notes::AbstractNote.new
6
+ Footnotes::Filter.notes = [:abstract]
7
+ end
8
+
9
+ it {described_class.should respond_to :start!}
10
+ it {described_class.should respond_to :close!}
11
+ it {described_class.should respond_to :title}
12
+
13
+ it {should respond_to :to_sym}
14
+ its(:to_sym) {should eql :abstract}
15
+
16
+ it { described_class.should be_included }
17
+ specify do
18
+ Footnotes::Filter.notes = []
19
+ described_class.should_not be_included
20
+ end
21
+
22
+ it { should respond_to :row }
23
+ it { should respond_to :legend }
24
+ it { should respond_to :link }
25
+ it { should respond_to :onclick }
26
+ it { should respond_to :stylesheet }
27
+ it { should respond_to :javascript }
28
+
29
+ it { should respond_to :valid? }
30
+ it { should be_valid }
31
+
32
+ it { should respond_to :has_fieldset? }
33
+ it { should_not have_fieldset }
34
+
35
+ specify { Footnotes::Filter.prefix = ''; should_not be_prefix }
36
+ specify do
37
+ Footnotes::Filter.prefix = 'txmt://open?url=file://%s&amp;line=%d&amp;column=%d'
38
+ should be_prefix
39
+ end
40
+
41
+ #TODO should be moved to builder
42
+ #helpers
43
+ specify { subject.escape('<').should eql '&lt;' }
44
+ specify { subject.escape('&').should eql '&amp;' }
45
+ specify { subject.escape('>').should eql '&gt;' }
46
+
47
+ specify { subject.mount_table([]).should be_blank }
48
+ specify { subject.mount_table([['h1', 'h2', 'h3']], :class => 'table').should be_blank }
49
+
50
+ specify {
51
+ tab = <<-TABLE
52
+ <table class="table" >
53
+ <thead><tr><th>H1</th></tr></thead>
54
+ <tbody><tr><td>r1c1</td></tr></tbody>
55
+ </table>
56
+ TABLE
57
+
58
+ subject.mount_table([['h1'],['r1c1']], :class => 'table').should eql tab
59
+ }
60
+
61
+ specify {
62
+ tab = <<-TABLE
63
+ <table >
64
+ <thead><tr><th>H1</th><th>H2</th><th>H3</th></tr></thead>
65
+ <tbody><tr><td>r1c1</td><td>r1c2</td><td>r1c3</td></tr></tbody>
66
+ </table>
67
+ TABLE
68
+ subject.mount_table([['h1', 'h2', 'h3'],['r1c1', 'r1c2', 'r1c3']]).should eql tab
69
+ }
70
+
71
+ specify {
72
+ tab = <<-TABLE
73
+ <table >
74
+ <thead><tr><th>H1</th><th>H2</th><th>H3</th></tr></thead>
75
+ <tbody><tr><td>r1c1</td><td>r1c2</td><td>r1c3</td></tr><tr><td>r2c1</td><td>r2c2</td><td>r2c3</td></tr></tbody>
76
+ </table>
77
+ TABLE
78
+ subject.mount_table([['h1', 'h2', 'h3'], ['r1c1', 'r1c2', 'r1c3'], ['r2c1', 'r2c2', 'r2c3']])
79
+ }
80
+ end
@@ -0,0 +1,215 @@
1
+ require "spec_helper"
2
+ require 'action_controller'
3
+ require 'action_controller/test_case'
4
+
5
+ class FootnotesController < ActionController::Base
6
+ attr_accessor :template, :performed_render
7
+ end
8
+
9
+ module Footnotes::Notes
10
+ class TestNote < AbstractNote
11
+ def self.to_sym; :test; end
12
+ def valid?; true; end
13
+ end
14
+
15
+ class NoteXNote < TestNote; end
16
+ class NoteYNote < TestNote; end
17
+ class NoteZNote < TestNote; end
18
+ end
19
+
20
+ describe "Footnotes" do
21
+ before do
22
+ @controller = FootnotesController.new
23
+ @controller.template = Object.new
24
+ @controller.request = ActionController::TestRequest.new
25
+ @controller.response = ActionController::TestResponse.new
26
+ @controller.response_body = $html.dup
27
+ @controller.params = {}
28
+
29
+ Footnotes::Filter.notes = [ :test ]
30
+ Footnotes::Filter.multiple_notes = false
31
+ @footnotes = Footnotes::Filter.new(@controller)
32
+ end
33
+
34
+ it "footnotes_controller" do
35
+ index = @controller.response.body.index(/This is the HTML page/)
36
+ index.should eql 334
37
+ end
38
+
39
+ it "foonotes_included" do
40
+ footnotes_perform!
41
+ @controller.response_body.should_not eql $html
42
+ end
43
+
44
+ specify "footnotes_not_included_when_request_is_xhr" do
45
+ @controller.request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
46
+ @controller.request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
47
+ footnotes_perform!
48
+ @controller.response.body.should eql $html
49
+ end
50
+
51
+ specify "footnotes_not_included_when_content_type_is_javascript" do
52
+ @controller.response.headers['Content-Type'] = 'text/javascript'
53
+ footnotes_perform!
54
+ @controller.response.body.should eql $html
55
+ end
56
+
57
+ specify "footnotes_included_when_content_type_is_html" do
58
+ @controller.response.headers['Content-Type'] = 'text/html'
59
+ footnotes_perform!
60
+ @controller.response.body.should_not eql $html
61
+ end
62
+
63
+ specify "footnotes_included_when_content_type_is_nil" do
64
+ footnotes_perform!
65
+ @controller.response.body.should_not eql $html
66
+ end
67
+
68
+ specify "not_included_when_body_is_not_a_string" do
69
+ @controller.response.body = Proc.new { Time.now }
70
+ expect { footnotes_perform! }.should_not raise_exception
71
+ end
72
+
73
+ specify "notes_are_initialized" do
74
+ footnotes_perform!
75
+ test_note = @footnotes.instance_variable_get('@notes').first
76
+ test_note.class.name.should eql 'Footnotes::Notes::TestNote'
77
+ test_note.to_sym.should eql :test
78
+ end
79
+
80
+ specify "notes_links" do
81
+ note = Footnotes::Notes::TestNote.new
82
+ note.should_receive(:row).twice
83
+ @footnotes.instance_variable_set(:@notes, [note])
84
+ footnotes_perform!
85
+ end
86
+
87
+ specify "notes_fieldset" do
88
+ note = Footnotes::Notes::TestNote.new
89
+ note.should_receive(:has_fieldset?).exactly(3).times
90
+ @footnotes.instance_variable_set(:@notes, [note])
91
+ footnotes_perform!
92
+ end
93
+
94
+ specify "multiple_notes" do
95
+ Footnotes::Filter.multiple_notes = true
96
+ note = Footnotes::Notes::TestNote.new
97
+ note.should_receive(:has_fieldset?).twice
98
+ @footnotes.instance_variable_set(:@notes, [note])
99
+ footnotes_perform!
100
+ end
101
+
102
+ specify "notes_are_reset" do
103
+ note = Footnotes::Notes::TestNote.new
104
+ note.class.should_receive(:close!)
105
+ @footnotes.instance_variable_set(:@notes, [note])
106
+ @footnotes.send(:close!, @controller)
107
+ end
108
+
109
+ specify "links_helper" do
110
+ note = Footnotes::Notes::TestNote.new
111
+ @footnotes.send(:link_helper, note).should eql '<a href="#" onclick="">Test</a>'
112
+
113
+ note.should_receive(:link).once.and_return(:link)
114
+ @footnotes.send(:link_helper, note).should eql '<a href="link" onclick="">Test</a>'
115
+ end
116
+
117
+ specify "links_helper_has_fieldset?" do
118
+ note = Footnotes::Notes::TestNote.new
119
+ note.should_receive(:has_fieldset?).once.and_return(true)
120
+ @footnotes.send(:link_helper, note).should eql '<a href="#" onclick="Footnotes.hideAllAndToggle(\'test_debug_info\');return false;">Test</a>'
121
+ end
122
+
123
+ specify "links_helper_onclick" do
124
+ note = Footnotes::Notes::TestNote.new
125
+ note.should_receive(:onclick).twice.and_return(:onclick)
126
+ @footnotes.send(:link_helper, note).should eql '<a href="#" onclick="onclick">Test</a>'
127
+
128
+ note.should_receive(:has_fieldset?).once.and_return(true)
129
+ @footnotes.send(:link_helper, note).should eql '<a href="#" onclick="onclick">Test</a>'
130
+ end
131
+
132
+ specify "insert_style" do
133
+ @controller.response.body = "<head></head><split><body></body>"
134
+ @footnotes = Footnotes::Filter.new(@controller)
135
+ footnotes_perform!
136
+ @controller.response.body.split('<split>').first.include?('<!-- Footnotes Style -->').should be
137
+ end
138
+
139
+ specify "insert_footnotes_inside_body" do
140
+ @controller.response.body = "<head></head><split><body></body>"
141
+ @footnotes = Footnotes::Filter.new(@controller)
142
+ footnotes_perform!
143
+ @controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->').should be
144
+ end
145
+
146
+ specify "insert_footnotes_inside_holder" do
147
+ @controller.response.body = "<head></head><split><div id='footnotes_holder'></div>"
148
+ @footnotes = Footnotes::Filter.new(@controller)
149
+ footnotes_perform!
150
+ @controller.response.body.split('<split>').last.include?('<!-- End Footnotes -->').should be
151
+ end
152
+
153
+ specify "insert_text" do
154
+ @footnotes.send(:insert_text, :after, /<head>/, "Graffiti")
155
+ after = " <head>Graffiti"
156
+ @controller.response.body.split("\n")[2].should eql after
157
+
158
+ @footnotes.send(:insert_text, :before, /<\/body>/, "Notes")
159
+ after = " Notes</body>"
160
+ @controller.response.body.split("\n")[12].should eql after
161
+ end
162
+
163
+ describe 'Hooks' do
164
+ before {Footnotes::Filter.notes = [:note_x, :note_y, :note_z]}
165
+ context 'before' do
166
+ specify do
167
+ Footnotes.setup {|config| config.before {|controller, filter| filter.notes -= [:note_y] }}
168
+ Footnotes::Filter.start!(@controller)
169
+ Footnotes::Filter.notes.should eql [:note_x, :note_z]
170
+ end
171
+ end
172
+ context "after" do
173
+ specify do
174
+ Footnotes.setup {|config| config.after {|controller, filter| filter.notes -= [:note_y] }}
175
+ Footnotes::Filter.start!(@controller)
176
+ Footnotes::Filter.notes.should eql [:note_x, :note_z]
177
+ end
178
+ end
179
+ end
180
+
181
+ protected
182
+ def footnotes_perform!
183
+ template_expects('html')
184
+ @controller.performed_render = true
185
+
186
+ Footnotes::Filter.start!(@controller)
187
+ @footnotes.add_footnotes!
188
+ end
189
+
190
+ def template_expects(format)
191
+ if @controller.template.respond_to?(:template_format)
192
+ @controller.template.stub(:template_format).and_return(format)
193
+ else
194
+ @controller.template.stub(:format).and_return(format)
195
+ end
196
+ end
197
+
198
+ $html = <<HTML
199
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
200
+ <html>
201
+ <head>
202
+ <title>HTML to XHTML Example: HTML page</title>
203
+ <link rel="Stylesheet" href="htmltohxhtml.css" type="text/css" media="screen">
204
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
205
+ </head>
206
+ <body>
207
+ <p>This is the HTML page. It works and is encoded just like any HTML page you
208
+ have previously done. View <a href="htmltoxhtml2.htm">the XHTML version</a> of
209
+ this page to view the difference between HTML and XHTML.</p>
210
+ <p>You will be glad to know that no changes need to be made to any of your CSS files.</p>
211
+ </body>
212
+ </html>
213
+ HTML
214
+
215
+ end
@@ -1,11 +1,15 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'rubygems'
2
- require 'test/unit'
3
- require 'mocha'
4
5
 
5
6
  ENV['RAILS_ENV'] = 'test'
6
7
 
7
8
  require 'active_support'
8
9
  require 'active_support/all' unless Class.respond_to?(:cattr_accessor)
9
10
  require 'rails-footnotes/footnotes'
10
- require 'rails-footnotes/notes/abstract_note'
11
+ require 'rails-footnotes/abstract_note'
11
12
  require "rails-footnotes"
13
+
14
+ RSpec.configure do |config|
15
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails-footnotes
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.7.2
5
+ version: 3.7.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Keenan Brock
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-02 00:00:00 Z
13
+ date: 2011-05-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -24,18 +24,18 @@ dependencies:
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: autotest
27
+ name: rails
28
28
  prerelease: false
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: "0"
34
+ version: 3.0.0
35
35
  type: :development
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
- name: mocha
38
+ name: rspec
39
39
  prerelease: false
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false
@@ -46,14 +46,14 @@ dependencies:
46
46
  type: :development
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
- name: rails
49
+ name: watchr
50
50
  prerelease: false
51
51
  requirement: &id004 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 3.0.0
56
+ version: "0"
57
57
  type: :development
58
58
  version_requirements: *id004
59
59
  description: Every Rails page has footnotes that gives information about your application and links back to your editor.
@@ -67,6 +67,8 @@ extra_rdoc_files: []
67
67
 
68
68
  files:
69
69
  - .gitignore
70
+ - .rspec.example
71
+ - .watchr.example
70
72
  - CHANGELOG
71
73
  - Gemfile
72
74
  - Gemfile.lock
@@ -74,9 +76,9 @@ files:
74
76
  - README.rdoc
75
77
  - Rakefile
76
78
  - lib/rails-footnotes.rb
77
- - lib/rails-footnotes/backtracer.rb
79
+ - lib/rails-footnotes/abstract_note.rb
78
80
  - lib/rails-footnotes/footnotes.rb
79
- - lib/rails-footnotes/notes/abstract_note.rb
81
+ - lib/rails-footnotes/notes/all.rb
80
82
  - lib/rails-footnotes/notes/assigns_note.rb
81
83
  - lib/rails-footnotes/notes/controller_note.rb
82
84
  - lib/rails-footnotes/notes/cookies_note.rb
@@ -91,15 +93,14 @@ files:
91
93
  - lib/rails-footnotes/notes/partials_note.rb
92
94
  - lib/rails-footnotes/notes/queries_note.rb
93
95
  - lib/rails-footnotes/notes/routes_note.rb
94
- - lib/rails-footnotes/notes/rpm_note.rb
95
96
  - lib/rails-footnotes/notes/session_note.rb
96
97
  - lib/rails-footnotes/notes/stylesheets_note.rb
97
98
  - lib/rails-footnotes/notes/view_note.rb
98
99
  - lib/rails-footnotes/version.rb
99
100
  - rails-footnotes.gemspec
100
- - test/footnotes_test.rb
101
- - test/notes/abstract_note_test.rb
102
- - test/test_helper.rb
101
+ - spec/abstract_note_spec.rb
102
+ - spec/footnotes_spec.rb
103
+ - spec/spec_helper.rb
103
104
  homepage: http://github.com/josevalim/rails-footnotes
104
105
  licenses: []
105
106
 
@@ -128,7 +129,6 @@ signing_key:
128
129
  specification_version: 3
129
130
  summary: Every Rails page has footnotes that gives information about your application and links back to your editor.
130
131
  test_files:
131
- - test/footnotes_test.rb
132
- - test/notes/abstract_note_test.rb
133
- - test/test_helper.rb
134
- has_rdoc:
132
+ - spec/abstract_note_spec.rb
133
+ - spec/footnotes_spec.rb
134
+ - spec/spec_helper.rb
@@ -1,36 +0,0 @@
1
- module Footnotes
2
- module Extensions
3
- module Exception
4
- def self.included(base)
5
- base.class_eval do
6
- alias_method_chain :clean_backtrace, :links
7
- end
8
- end
9
-
10
- def add_links_to_backtrace(lines)
11
- lines.collect do |line|
12
- expanded = line.gsub('#{RAILS_ROOT}', Rails.root)
13
- if match = expanded.match(/^(.+):(\d+):in/) || match = expanded.match(/^(.+):(\d+)\s*$/)
14
- file = File.expand_path(match[1])
15
- line_number = match[2]
16
- html = %[<a href="#{Footnotes::Filter.prefix(file, line_number, 1)}">#{line}</a>]
17
- else
18
- line
19
- end
20
- end
21
- end
22
-
23
- def clean_backtrace_with_links
24
- unless ::Footnotes::Filter.prefix.blank?
25
- add_links_to_backtrace(clean_backtrace_without_links)
26
- else
27
- clean_backtrace_without_links
28
- end
29
- end
30
- end
31
- end
32
- end
33
-
34
- if Rails.version < '3.0'
35
- Exception.send :include, Footnotes::Extensions::Exception
36
- end