capsule_crm 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hound.yml +1 -1
- data/CHANGELOG.md +15 -2
- data/lib/capsule_crm/associations/belongs_to.rb +13 -12
- data/lib/capsule_crm/associations/belongs_to_association.rb +18 -1
- data/lib/capsule_crm/errors/association_type_mismatch.rb +10 -0
- data/lib/capsule_crm/errors/record_invalid.rb +6 -0
- data/lib/capsule_crm/opportunity.rb +1 -0
- data/lib/capsule_crm/task.rb +1 -1
- data/lib/capsule_crm/task_category.rb +1 -1
- data/lib/capsule_crm/version.rb +1 -1
- data/lib/capsule_crm.rb +1 -0
- data/spec/lib/capsule_crm/associations/belongs_to_association_spec.rb +32 -0
- data/spec/lib/capsule_crm/errors/record_invalid_spec.rb +23 -0
- data/spec/lib/capsule_crm/history_spec.rb +3 -3
- data/spec/lib/capsule_crm/serializer_spec.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cfdc83bc1370520aadef70ff71c92d7ce027a9b
|
4
|
+
data.tar.gz: 06ff75f4e1278b8c3f1b15a7a1c90a72ed2c860f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ff92ce9719c2756affb46c7de48027d72cd3a7378b0bc5f9798460f6ba097a39ec6007b06d5c8c83c09f8c8c239580092336977d42719526ac98479e3d03f0
|
7
|
+
data.tar.gz: 56acc7915da8a8a42344c5f1bfebf97e9b52f536b4f5200d962864e2a0a955e8a3c7e2a46c6d4a70051dd2583f0e7edcbccb09f8d1ead15e1e829ffca15bc435
|
data/.hound.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,40 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.9.0
|
4
|
+
|
5
|
+
- Raise a CapsuleCRM::Errors::AssociationTypeMismatch when an object of the
|
6
|
+
wrong type is set on a belongs to association.
|
7
|
+
[#79](https://github.com/mattbeedle/capsule_crm/pull/79)
|
8
|
+
- CapsuleCRM::Errors::RecordInvalid#to_s and #inspect methods are now more
|
9
|
+
descriptive [#78](https://github.com/mattbeedle/capsule_crm/pull/78)
|
10
|
+
|
3
11
|
## 1.8.0
|
4
12
|
|
5
13
|
- Custom fields may now be deleted.
|
14
|
+
[#77](https://github.com/mattbeedle/capsule_crm/pull/77)
|
6
15
|
|
7
16
|
## 1.7.0
|
8
17
|
|
9
18
|
- Inspecting items only displays their attributes now. Much cleaner for working
|
10
19
|
on the console
|
20
|
+
[https://github.com/mattbeedle/capsule_crm/commit/cde082c1934ff97b6fa2dc9c56a01ca771d73b26](https://github.com/mattbeedle/capsule_crm/commit/cde082c1934ff97b6fa2dc9c56a01ca771d73b26)
|
11
21
|
|
12
22
|
## 1.6.2
|
13
23
|
|
14
|
-
- Fix bug where responses errors always had a blank body
|
24
|
+
- Fix bug where responses errors always had a blank body.
|
25
|
+
[#76](https://github.com/mattbeedle/capsule_crm/pull/76)
|
15
26
|
|
16
27
|
## 1.6.1
|
17
28
|
|
18
29
|
- Fix issue where if capsulecrm.com returned a blank error response the
|
19
|
-
ResponseError would raise an undefined method exception
|
30
|
+
ResponseError would raise an undefined method exception.
|
31
|
+
[#74](https://github.com/mattbeedle/capsule_crm/pull/74)
|
20
32
|
|
21
33
|
## 1.6.0
|
22
34
|
|
23
35
|
- ResponseError#to_s now return the response message from the server so errors
|
24
36
|
are a little easier to debug.
|
37
|
+
[#69](https://github.com/mattbeedle/capsule_crm/pull/69)
|
25
38
|
|
26
39
|
## 1.5.3
|
27
40
|
|
@@ -2,12 +2,12 @@ require_relative 'belongs_to_association'
|
|
2
2
|
require_relative 'belongs_to_finder'
|
3
3
|
|
4
4
|
module CapsuleCRM
|
5
|
-
module Associations
|
6
|
-
module BelongsTo
|
5
|
+
module Associations # nodoc
|
6
|
+
module BelongsTo # nodoc
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
+
# nodoc
|
9
10
|
module ClassMethods
|
10
|
-
|
11
11
|
# Public: Add getter and setter methods for belongs to associations
|
12
12
|
#
|
13
13
|
# association_name - The String name of the association
|
@@ -32,9 +32,9 @@ module CapsuleCRM
|
|
32
32
|
# person.organisation
|
33
33
|
# => organisation
|
34
34
|
def belongs_to(association_name, options = {})
|
35
|
-
association = CapsuleCRM::Associations::BelongsToAssociation
|
36
|
-
new(association_name, self, options)
|
37
|
-
|
35
|
+
association = CapsuleCRM::Associations::BelongsToAssociation
|
36
|
+
.new(association_name, self, options)
|
37
|
+
associations[association_name] = association
|
38
38
|
|
39
39
|
class_eval do
|
40
40
|
attribute association.foreign_key, Integer
|
@@ -42,24 +42,25 @@ module CapsuleCRM
|
|
42
42
|
|
43
43
|
(class << self; self; end).instance_eval do
|
44
44
|
define_method "_for_#{association_name}" do |id|
|
45
|
-
CapsuleCRM::Associations::BelongsToFinder.new(association)
|
46
|
-
call(id)
|
45
|
+
CapsuleCRM::Associations::BelongsToFinder.new(association)
|
46
|
+
.call(id)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
define_method association_name do
|
51
51
|
instance_variable_get(:"@#{association_name}") ||
|
52
|
-
if
|
52
|
+
if send(association.foreign_key)
|
53
53
|
association.parent(self).tap do |object|
|
54
|
-
|
54
|
+
send("#{association_name}=", object)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
define_method "#{association_name}=" do |associated_object|
|
60
60
|
associated_object.tap do |object|
|
61
|
-
|
62
|
-
|
61
|
+
association.check_object! object if object
|
62
|
+
instance_variable_set(:"@#{association_name}", object)
|
63
|
+
send "#{association.foreign_key}=", object.try(:id)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
@@ -75,11 +75,28 @@ module CapsuleCRM
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def serialize
|
78
|
-
@serialize ||= options[:serialize]
|
78
|
+
@serialize ||= options[:serialize] == false ? false : true
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_object!(object)
|
82
|
+
association_mismatch!(object) if object_invalid?(object)
|
79
83
|
end
|
80
84
|
|
81
85
|
private
|
82
86
|
|
87
|
+
def enforce_type?
|
88
|
+
true unless options[:enforce_type] == false
|
89
|
+
end
|
90
|
+
|
91
|
+
def object_invalid?(object)
|
92
|
+
enforce_type? && !object.is_a?(target_klass)
|
93
|
+
end
|
94
|
+
|
95
|
+
def association_mismatch!(object)
|
96
|
+
fail CapsuleCRM::Errors::AssociationTypeMismatch,
|
97
|
+
[object.class, target_klass], caller
|
98
|
+
end
|
99
|
+
|
83
100
|
def infer_foreign_key
|
84
101
|
"#{association_name}_id"
|
85
102
|
end
|
data/lib/capsule_crm/task.rb
CHANGED
@@ -28,7 +28,7 @@ module CapsuleCRM
|
|
28
28
|
belongs_to :case
|
29
29
|
belongs_to :owner, class_name: 'CapsuleCRM::User', serializable_key: :owner
|
30
30
|
belongs_to :category, class_name: 'CapsuleCRM::TaskCategory',
|
31
|
-
serializable_key: :category
|
31
|
+
serializable_key: :category, enforce_type: false
|
32
32
|
|
33
33
|
validates :id, numericality: { allow_blank: true }
|
34
34
|
validates :description, presence: true
|
data/lib/capsule_crm/version.rb
CHANGED
data/lib/capsule_crm.rb
CHANGED
@@ -30,6 +30,7 @@ require 'capsule_crm/website'
|
|
30
30
|
require 'capsule_crm/hash_helper'
|
31
31
|
require 'capsule_crm/results_proxy'
|
32
32
|
require 'capsule_crm/errors'
|
33
|
+
require 'capsule_crm/errors/association_type_mismatch'
|
33
34
|
require 'capsule_crm/errors/record_invalid'
|
34
35
|
require 'capsule_crm/errors/record_not_saved'
|
35
36
|
require 'capsule_crm/errors/response_error'
|
@@ -21,6 +21,38 @@ describe CapsuleCRM::Associations::BelongsToAssociation do
|
|
21
21
|
new(association_name, defined_on, options)
|
22
22
|
end
|
23
23
|
|
24
|
+
describe '#check_object!' do
|
25
|
+
context 'when the object is valid' do
|
26
|
+
let(:object) { CapsuleCRM::BelongsToAssociationTest.new }
|
27
|
+
|
28
|
+
it 'should not raise' do
|
29
|
+
expect { association.check_object!(object) }.not_to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when the object is not valid' do
|
34
|
+
context 'when type checking is turned off' do
|
35
|
+
let(:options) do
|
36
|
+
{
|
37
|
+
class_name: 'CapsuleCRM::BelongsToAssociationTest',
|
38
|
+
enforce_type: false
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should not raise' do
|
43
|
+
expect { association.check_object!(double) }.not_to raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when type checking is turned on' do
|
48
|
+
it 'should raise an AssociationMismatch' do
|
49
|
+
expect { association.check_object!(double) }
|
50
|
+
.to raise_error(CapsuleCRM::Errors::AssociationTypeMismatch)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
24
56
|
describe '#macro' do
|
25
57
|
subject { association.macro }
|
26
58
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapsuleCRM::Errors::RecordInvalid do
|
4
|
+
let(:errors) { double('errors', full_messages: full_messages) }
|
5
|
+
let(:full_messages) do
|
6
|
+
["Record can't be squishy", "Record can't be pink"]
|
7
|
+
end
|
8
|
+
let(:record) { double('Record', errors: errors) }
|
9
|
+
|
10
|
+
subject { described_class.new(record) }
|
11
|
+
|
12
|
+
describe '#to_s' do
|
13
|
+
it 'should return the full messages joined by ,' do
|
14
|
+
expect(subject.to_s).to eql(full_messages.join(', '))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#record' do
|
19
|
+
it 'should be accessible' do
|
20
|
+
expect(subject.record).to eql(record)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -28,7 +28,7 @@ describe CapsuleCRM::History do
|
|
28
28
|
|
29
29
|
context 'when it belongs to a case' do
|
30
30
|
before do
|
31
|
-
subject.case =
|
31
|
+
subject.case = CapsuleCRM::Case.new(id: Random.rand(1..10))
|
32
32
|
end
|
33
33
|
|
34
34
|
it { should_not validate_presence_of(:party) }
|
@@ -37,7 +37,7 @@ describe CapsuleCRM::History do
|
|
37
37
|
|
38
38
|
context 'when it belongs to a party' do
|
39
39
|
before do
|
40
|
-
subject.party =
|
40
|
+
subject.party = CapsuleCRM::Party.new(id: Random.rand(1..10))
|
41
41
|
end
|
42
42
|
|
43
43
|
it { should_not validate_presence_of(:case) }
|
@@ -47,7 +47,7 @@ describe CapsuleCRM::History do
|
|
47
47
|
context 'when it belongs to an opportunity' do
|
48
48
|
before do
|
49
49
|
subject.opportunity =
|
50
|
-
|
50
|
+
CapsuleCRM::Opportunity.new(id: Random.rand(1..10))
|
51
51
|
end
|
52
52
|
|
53
53
|
it { should_not validate_presence_of(:party) }
|
@@ -92,7 +92,7 @@ describe CapsuleCRM::Serializer do
|
|
92
92
|
context 'when there are belongs to associations' do
|
93
93
|
before do
|
94
94
|
SerializableTest.send(
|
95
|
-
:belongs_to, :person, class_name: '
|
95
|
+
:belongs_to, :person, class_name: 'CapsuleCRM::Person'
|
96
96
|
)
|
97
97
|
SerializableTest.send(
|
98
98
|
:has_many, :things, class_name: 'SerializableTest',
|
@@ -100,7 +100,7 @@ describe CapsuleCRM::Serializer do
|
|
100
100
|
)
|
101
101
|
object.person = person
|
102
102
|
end
|
103
|
-
let(:person) {
|
103
|
+
let(:person) { CapsuleCRM::Person.new(id: Random.rand(1..10)) }
|
104
104
|
|
105
105
|
context 'without a serializable key' do
|
106
106
|
it 'should include the person id' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capsule_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -274,6 +274,7 @@ files:
|
|
274
274
|
- lib/capsule_crm/custom_field_definition.rb
|
275
275
|
- lib/capsule_crm/email.rb
|
276
276
|
- lib/capsule_crm/errors.rb
|
277
|
+
- lib/capsule_crm/errors/association_type_mismatch.rb
|
277
278
|
- lib/capsule_crm/errors/record_invalid.rb
|
278
279
|
- lib/capsule_crm/errors/record_not_saved.rb
|
279
280
|
- lib/capsule_crm/errors/response_error.rb
|
@@ -334,6 +335,7 @@ files:
|
|
334
335
|
- spec/lib/capsule_crm/custom_field_definition_spec.rb
|
335
336
|
- spec/lib/capsule_crm/custom_field_spec.rb
|
336
337
|
- spec/lib/capsule_crm/email_spec.rb
|
338
|
+
- spec/lib/capsule_crm/errors/record_invalid_spec.rb
|
337
339
|
- spec/lib/capsule_crm/errors/response_error_spec.rb
|
338
340
|
- spec/lib/capsule_crm/errors_spec.rb
|
339
341
|
- spec/lib/capsule_crm/faraday/middleware/raise_error_spec.rb
|
@@ -446,6 +448,7 @@ test_files:
|
|
446
448
|
- spec/lib/capsule_crm/custom_field_definition_spec.rb
|
447
449
|
- spec/lib/capsule_crm/custom_field_spec.rb
|
448
450
|
- spec/lib/capsule_crm/email_spec.rb
|
451
|
+
- spec/lib/capsule_crm/errors/record_invalid_spec.rb
|
449
452
|
- spec/lib/capsule_crm/errors/response_error_spec.rb
|
450
453
|
- spec/lib/capsule_crm/errors_spec.rb
|
451
454
|
- spec/lib/capsule_crm/faraday/middleware/raise_error_spec.rb
|