Skip to content

Commit

Permalink
[^] more tests, assigns_note was refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
nordringrayhide committed Sep 24, 2011
1 parent ef58f03 commit 2ed68b7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 24 deletions.
1 change: 0 additions & 1 deletion lib/rails-footnotes/abstract_note.rb
Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions lib/rails-footnotes/notes/assigns_note.rb
Expand Up @@ -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)
Expand Down
22 changes: 15 additions & 7 deletions spec/notes/assigns_note_spec.rb
Expand Up @@ -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
11 changes: 11 additions & 0 deletions 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
14 changes: 13 additions & 1 deletion spec/notes/javascripts_note_spec.rb
Expand Up @@ -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
5 changes: 4 additions & 1 deletion spec/notes/partials_notes_spec.rb
Expand Up @@ -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
15 changes: 14 additions & 1 deletion spec/notes/stylesheets_note_spec.rb
Expand Up @@ -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

0 comments on commit 2ed68b7

Please sign in to comment.