Skip to content

Commit 2ed68b7

Browse files
[^] more tests, assigns_note was refactored
1 parent ef58f03 commit 2ed68b7

File tree

7 files changed

+63
-24
lines changed

7 files changed

+63
-24
lines changed

lib/rails-footnotes/abstract_note.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def mount_table(array, options = {})
145145
return '' if array.empty?
146146

147147
header = header.collect{|i| escape(i.to_s.humanize) }
148-
# array = array.collect { |a| a.collect { |b| c = b.to_s; escape(c) unless c == ""}}
149148
rows = array.collect{|i| "<tr><td>#{i.join('</td><td>')}</td></tr>" }
150149

151150
<<-TABLE

lib/rails-footnotes/notes/assigns_note.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,20 @@ def title
2626
end
2727

2828
def valid?
29-
assigns
29+
assigns.present?
3030
end
3131

3232
def content
33-
rows = []
34-
assigns.each do |key|
35-
rows << [ key, escape(assigned_value(key)) ]
36-
end
37-
mount_table(rows.unshift(['Name', 'Value']), :class => 'name_values', :summary => "Debug information for #{title}")
33+
mount_table(to_table, :summary => "Debug information for #{title}")
3834
end
3935

4036
protected
37+
def to_table
38+
@to_table ||= assigns.inject([]) {|rr, var| rr << [var, escape(assigned_value(var))]}.unshift(['Name', 'Value'])
39+
end
4140

4241
def assigns
43-
assign = []
44-
ignored = @@ignored_assigns
45-
46-
@controller.instance_variables.each {|x| assign << x.intern }
47-
48-
assign -= ignored
49-
return assign
42+
@assigns ||= @controller.instance_variables.map {|v| v.to_sym} - ignored_assigns
5043
end
5144

5245
def assigned_value(key)

spec/notes/assigns_note_spec.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22
require 'action_controller'
33
require "rails-footnotes/notes/assigns_note"
44

5-
class FootnotesController < ActionController::Base
6-
end
7-
85
describe Footnotes::Notes::AssignsNote do
96
let(:note) do
10-
@controller = FootnotesController.new
11-
@controller.stub(:instance_variables).and_return([:@action_has_layout, :@view_context_class, :@_status])
7+
@controller = mock
8+
@controller.stub(:instance_variables).and_return([:@action_has_layout, :@_status])
9+
@controller.instance_variable_set(:@action_has_layout, true)
10+
@controller.instance_variable_set(:@_status, 200)
1211
Footnotes::Notes::AssignsNote.new(@controller)
1312
end
1413
subject {note}
1514

1615
before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns = []}
16+
1717
it {should be_valid}
18-
its(:title) {should eql 'Assigns (3)'}
19-
specify {note.send(:assigns).should eql [:@action_has_layout, :@view_context_class, :@_status]}
18+
its(:title) {should eql 'Assigns (2)'}
19+
20+
specify {note.send(:assigns).should eql [:@action_has_layout, :@_status]}
21+
specify {note.send(:to_table).should eql [['Name', 'Value'], [:@action_has_layout, "true"], [:@_status, "200"]]}
2022

2123
describe "Ignored Assigns" do
2224
before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns = [:@_status]}
2325
it {note.send(:assigns).should_not include :@_status}
2426
end
27+
28+
it "should call #mount_table method with correct params" do
29+
note.should_receive(:mount_table).with(
30+
[['Name', 'Value'], [:@action_has_layout, "true"], [:@_status, "200"]], {:summary=>"Debug information for Assigns (2)"})
31+
note.content
32+
end
2533
end

spec/notes/files_note_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'spec_helper'
2+
require 'action_controller'
3+
require "rails-footnotes/notes/files_note"
4+
5+
describe Footnotes::Notes::FilesNote do
6+
let(:note) {Footnotes::Notes::FilesNote.new(mock('controller', :response => mock('', :body => '')))}
7+
subject {note}
8+
9+
it {should be_valid}
10+
its(:row) {should eql :edit}
11+
end

spec/notes/javascripts_note_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@
22
require "rails-footnotes/notes/javascripts_note"
33

44
describe Footnotes::Notes::JavascriptsNote do
5-
pending
5+
let(:note) {described_class.new(mock('controller', :response => mock('body', :body => '')))}
6+
subject {note}
7+
8+
it {should be_valid}
9+
10+
it "should return js links from html after #scan_text mehtod call" do
11+
subject.send(:scan_text, HTML_WITH_JS).should eql ['/javascripts/all.js', '/javascripts/jquery.js']
12+
end
613
end
14+
15+
HTML_WITH_JS = <<-EOF
16+
<script cache="false" src="/javascripts/all.js?1315913920" type="text/javascript"></script>
17+
<script cache="false" src="/javascripts/jquery.js?1315913920" type="text/javascript"></script>
18+
EOF

spec/notes/partials_notes_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
require "rails-footnotes/notes/partials_note"
33

44
describe Footnotes::Notes::PartialsNote do
5-
pending
5+
let(:note) {described_class.new(mock())}
6+
subject {note}
7+
8+
it {should be_valid}
69
end

spec/notes/stylesheets_note_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,18 @@
22
require "rails-footnotes/notes/stylesheets_note"
33

44
describe Footnotes::Notes::StylesheetsNote do
5-
pending
5+
6+
let(:note) {described_class.new(mock('controller', :response => mock('body', :body => '')))}
7+
subject {note}
8+
9+
it {should be_valid}
10+
11+
it "should return css link from html text after #scan_text call" do
12+
subject.send(:scan_text, HTML_WITH_CSS).should eql ['/stylesheets/compiled/print.css', '/stylesheets/compiled/print.css']
13+
end
614
end
15+
16+
HTML_WITH_CSS = <<-EOF
17+
<link href="/stylesheets/compiled/print.css?1315913920" media="print" rel="stylesheet" type="text/css" />'
18+
'<link href="/stylesheets/compiled/print.css?1315913920" media="print" rel="stylesheet" type="text/css" />'
19+
EOF

0 commit comments

Comments
 (0)