Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[^] more tests, assigns_note was refactored

  • Loading branch information...
commit 2ed68b7c5cbfad6a166edb9e34ac59cf9971e2d0 1 parent ef58f03
@romanvbabenko romanvbabenko authored
View
1  lib/rails-footnotes/abstract_note.rb
@@ -145,7 +145,6 @@ def mount_table(array, options = {})
return '' if array.empty?
header = header.collect{|i| escape(i.to_s.humanize) }
-# array = array.collect { |a| a.collect { |b| c = b.to_s; escape(c) unless c == ""}}
rows = array.collect{|i| "<tr><td>#{i.join('</td><td>')}</td></tr>" }
<<-TABLE
View
19 lib/rails-footnotes/notes/assigns_note.rb
@@ -26,27 +26,20 @@ def title
end
def valid?
- assigns
+ assigns.present?
end
def content
- rows = []
- assigns.each do |key|
- rows << [ key, escape(assigned_value(key)) ]
- end
- mount_table(rows.unshift(['Name', 'Value']), :class => 'name_values', :summary => "Debug information for #{title}")
+ mount_table(to_table, :summary => "Debug information for #{title}")
end
protected
+ def to_table
+ @to_table ||= assigns.inject([]) {|rr, var| rr << [var, escape(assigned_value(var))]}.unshift(['Name', 'Value'])
+ end
def assigns
- assign = []
- ignored = @@ignored_assigns
-
- @controller.instance_variables.each {|x| assign << x.intern }
-
- assign -= ignored
- return assign
+ @assigns ||= @controller.instance_variables.map {|v| v.to_sym} - ignored_assigns
end
def assigned_value(key)
View
22 spec/notes/assigns_note_spec.rb
@@ -2,24 +2,32 @@
require 'action_controller'
require "rails-footnotes/notes/assigns_note"
-class FootnotesController < ActionController::Base
-end
-
describe Footnotes::Notes::AssignsNote do
let(:note) do
- @controller = FootnotesController.new
- @controller.stub(:instance_variables).and_return([:@action_has_layout, :@view_context_class, :@_status])
+ @controller = mock
+ @controller.stub(:instance_variables).and_return([:@action_has_layout, :@_status])
+ @controller.instance_variable_set(:@action_has_layout, true)
+ @controller.instance_variable_set(:@_status, 200)
Footnotes::Notes::AssignsNote.new(@controller)
end
subject {note}
before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns = []}
+
it {should be_valid}
- its(:title) {should eql 'Assigns (3)'}
- specify {note.send(:assigns).should eql [:@action_has_layout, :@view_context_class, :@_status]}
+ its(:title) {should eql 'Assigns (2)'}
+
+ specify {note.send(:assigns).should eql [:@action_has_layout, :@_status]}
+ specify {note.send(:to_table).should eql [['Name', 'Value'], [:@action_has_layout, "true"], [:@_status, "200"]]}
describe "Ignored Assigns" do
before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns = [:@_status]}
it {note.send(:assigns).should_not include :@_status}
end
+
+ it "should call #mount_table method with correct params" do
+ note.should_receive(:mount_table).with(
+ [['Name', 'Value'], [:@action_has_layout, "true"], [:@_status, "200"]], {:summary=>"Debug information for Assigns (2)"})
+ note.content
+ end
end
View
11 spec/notes/files_note_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+require 'action_controller'
+require "rails-footnotes/notes/files_note"
+
+describe Footnotes::Notes::FilesNote do
+ let(:note) {Footnotes::Notes::FilesNote.new(mock('controller', :response => mock('', :body => '')))}
+ subject {note}
+
+ it {should be_valid}
+ its(:row) {should eql :edit}
+end
View
14 spec/notes/javascripts_note_spec.rb
@@ -2,5 +2,17 @@
require "rails-footnotes/notes/javascripts_note"
describe Footnotes::Notes::JavascriptsNote do
- pending
+ let(:note) {described_class.new(mock('controller', :response => mock('body', :body => '')))}
+ subject {note}
+
+ it {should be_valid}
+
+ it "should return js links from html after #scan_text mehtod call" do
+ subject.send(:scan_text, HTML_WITH_JS).should eql ['/javascripts/all.js', '/javascripts/jquery.js']
+ end
end
+
+HTML_WITH_JS = <<-EOF
+ <script cache="false" src="/javascripts/all.js?1315913920" type="text/javascript"></script>
+ <script cache="false" src="/javascripts/jquery.js?1315913920" type="text/javascript"></script>
+EOF
View
5 spec/notes/partials_notes_spec.rb
@@ -2,5 +2,8 @@
require "rails-footnotes/notes/partials_note"
describe Footnotes::Notes::PartialsNote do
- pending
+ let(:note) {described_class.new(mock())}
+ subject {note}
+
+ it {should be_valid}
end
View
15 spec/notes/stylesheets_note_spec.rb
@@ -2,5 +2,18 @@
require "rails-footnotes/notes/stylesheets_note"
describe Footnotes::Notes::StylesheetsNote do
- pending
+
+ let(:note) {described_class.new(mock('controller', :response => mock('body', :body => '')))}
+ subject {note}
+
+ it {should be_valid}
+
+ it "should return css link from html text after #scan_text call" do
+ subject.send(:scan_text, HTML_WITH_CSS).should eql ['/stylesheets/compiled/print.css', '/stylesheets/compiled/print.css']
+ end
end
+
+HTML_WITH_CSS = <<-EOF
+ <link href="/stylesheets/compiled/print.css?1315913920" media="print" rel="stylesheet" type="text/css" />'
+ '<link href="/stylesheets/compiled/print.css?1315913920" media="print" rel="stylesheet" type="text/css" />'
+EOF
Please sign in to comment.
Something went wrong with that request. Please try again.