Skip to content

Enable conversion to hash #28

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/honeybadger-api/fault.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ def resolved?
@resolved == true
end

# Public: A hash comprised of all instance methods.
def to_h
{
:action => action,
:comments_count => comments_count,
:component => component,
:created_at => created_at.to_s,
:deploy_revision => deploy.revision,
:environment => environment,
:error_class => klass,
:error_message => message,
:id => id,
:ignored => ignored?,
:last_notice_at => last_notice_at.to_s,
:notices_count => notices_count,
:project_id => project_id,
:resolved => resolved?,
:tags => tags,
:url => url
}
end

# Public: Find all faults for a given project.
def self.all(project_id)
path = "projects/#{project_id}/faults"
Expand All @@ -67,4 +89,4 @@ def self.handler
end
end
end
end
end
6 changes: 5 additions & 1 deletion spec/fault_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
it "should have a deploy object" do
expect(@fault.deploy).to_not be_nil
end

it "should have a method to convert all its instance variables to a hash" do
expect(@fault.to_h.keys.sort).to eql([:action, :comments_count, :component, :created_at, :deploy_revision, :environment, :error_class, :error_message, :id, :ignored, :last_notice_at, :notices_count, :project_id, :resolved, :tags, :url])
end
end

describe "an ignored fault" do
Expand Down Expand Up @@ -159,4 +163,4 @@
Honeybadger::Api::Fault.find(@project_id, @fault_id)
end
end
end
end