Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assigns_note to gnore assigns starts with '@_' #76

Merged
merged 1 commit into from Apr 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rails-footnotes/notes/assigns_note.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down
19 changes: 12 additions & 7 deletions spec/notes/assigns_note_spec.rb
Expand Up @@ -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}
Expand All @@ -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