Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #76 from jugyo/fix_assigns_note

Fix assigns_note to ignore assigns starts with '@_'.
  • Loading branch information...
commit f61271f9f9afdaa036103492ecd611e69a633197 2 parents 26f7c4f + b6d239f
@romanvbabenko romanvbabenko authored
View
4 lib/rails-footnotes/notes/assigns_note.rb
@@ -16,6 +16,8 @@ class AssignsNote < AbstractNote
:@view_runtime
]
cattr_accessor :ignored_assigns, :instance_writter => false
+ @@ignored_assigns_pattern = /^@_/
+ cattr_accessor :ignored_assigns_pattern, :instance_writter => false
def initialize(controller)
@controller = controller
@@ -39,7 +41,7 @@ def to_table
end
def assigns
- @assigns ||= @controller.instance_variables.map {|v| v.to_sym} - ignored_assigns
+ @assigns ||= @controller.instance_variables.map {|v| v.to_sym}.select {|v| v !~ ignored_assigns_pattern } - ignored_assigns
end
def assigned_value(key)
View
19 spec/notes/assigns_note_spec.rb
@@ -5,9 +5,9 @@
describe Footnotes::Notes::AssignsNote do
let(:note) do
@controller = mock
- @controller.stub(:instance_variables).and_return([:@action_has_layout, :@_status])
+ @controller.stub(:instance_variables).and_return([:@action_has_layout, :@status])
@controller.instance_variable_set(:@action_has_layout, true)
- @controller.instance_variable_set(:@_status, 200)
+ @controller.instance_variable_set(:@status, 200)
Footnotes::Notes::AssignsNote.new(@controller)
end
subject {note}
@@ -17,17 +17,22 @@
it {should be_valid}
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"]]}
+ 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}
+ before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns = [:@status]}
+ it {note.send(:assigns).should_not include :@status}
+ end
+
+ describe "Ignored Assigns by regexp" do
+ before(:each) {Footnotes::Notes::AssignsNote.ignored_assigns_pattern = /^@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)"})
+ [['Name', 'Value'], [:@action_has_layout, "true"], [:@status, "200"]], {:summary=>"Debug information for Assigns (2)"})
note.content
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.