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

Make CapsuleCRM::Errors::RecordInvalid more descriptive #78

Merged
merged 1 commit into from
Sep 16, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.9.0

- CapsuleCRM::Errors::RecordInvalid#to_s and #inspect methods are now more
descriptive

## 1.8.0

- Custom fields may now be deleted.
Expand Down
6 changes: 6 additions & 0 deletions lib/capsule_crm/errors/record_invalid.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module CapsuleCRM
module Errors
class RecordInvalid < StandardError
attr_reader :record

def initialize(record)
@record = record
super(record.errors.full_messages.join(', '))
end
end
end
end
23 changes: 23 additions & 0 deletions spec/lib/capsule_crm/errors/record_invalid_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe CapsuleCRM::Errors::RecordInvalid do
let(:errors) { double('errors', full_messages: full_messages) }
let(:full_messages) do
["Record can't be squishy", "Record can't be pink"]
end
let(:record) { double('Record', errors: errors) }

subject { described_class.new(record) }

describe '#to_s' do
it 'should return the full messages joined by ,' do
expect(subject.to_s).to eql(full_messages.join(', '))
end
end

describe '#record' do
it 'should be accessible' do
expect(subject.record).to eql(record)
end
end
end