capsule_crm 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +1 -1
- data/lib/capsule_crm/associations/belongs_to.rb +12 -10
- data/lib/capsule_crm/associations/belongs_to_association.rb +80 -0
- data/lib/capsule_crm/associations/has_many.rb +8 -18
- data/lib/capsule_crm/associations/has_many_association.rb +80 -0
- data/lib/capsule_crm/associations.rb +26 -0
- data/lib/capsule_crm/capsule_jsonable.rb +5 -1
- data/lib/capsule_crm/case.rb +7 -9
- data/lib/capsule_crm/contacts.rb +1 -1
- data/lib/capsule_crm/custom_field.rb +5 -8
- data/lib/capsule_crm/history.rb +11 -11
- data/lib/capsule_crm/opportunity.rb +5 -7
- data/lib/capsule_crm/organization.rb +6 -7
- data/lib/capsule_crm/participant.rb +0 -4
- data/lib/capsule_crm/party.rb +1 -1
- data/lib/capsule_crm/person.rb +6 -7
- data/lib/capsule_crm/serializer.rb +56 -0
- data/lib/capsule_crm/task.rb +7 -5
- data/lib/capsule_crm/track.rb +1 -1
- data/lib/capsule_crm/user.rb +5 -1
- data/lib/capsule_crm/version.rb +1 -1
- data/lib/capsule_crm.rb +1 -0
- data/spec/fabricators/custom_field_fabricator.rb +7 -0
- data/spec/lib/capsule_crm/associations/belongs_to_association_spec.rb +78 -0
- data/spec/lib/capsule_crm/associations/has_many_association_spec.rb +84 -0
- data/spec/lib/capsule_crm/associations/has_many_proxy_spec.rb +2 -2
- data/spec/lib/capsule_crm/associations_spec.rb +46 -0
- data/spec/lib/capsule_crm/custom_field_spec.rb +20 -597
- data/spec/lib/capsule_crm/history_spec.rb +8 -9
- data/spec/lib/capsule_crm/person_spec.rb +0 -16
- data/spec/lib/capsule_crm/serializer_spec.rb +103 -0
- data/spec/lib/capsule_crm/task_spec.rb +6 -14
- metadata +15 -2
data/lib/capsule_crm/track.rb
CHANGED
data/lib/capsule_crm/user.rb
CHANGED
@@ -6,7 +6,7 @@ module CapsuleCRM
|
|
6
6
|
include ActiveModel::Conversion
|
7
7
|
include ActiveModel::Validations
|
8
8
|
|
9
|
-
include CapsuleCRM::Associations
|
9
|
+
include CapsuleCRM::Associations
|
10
10
|
|
11
11
|
attribute :username, String
|
12
12
|
attribute :name, String
|
@@ -31,6 +31,10 @@ module CapsuleCRM
|
|
31
31
|
)
|
32
32
|
end
|
33
33
|
|
34
|
+
def id
|
35
|
+
username
|
36
|
+
end
|
37
|
+
|
34
38
|
def self.find_by_username(username)
|
35
39
|
all.select { |user| user.username == username }.first
|
36
40
|
end
|
data/lib/capsule_crm/version.rb
CHANGED
data/lib/capsule_crm.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CapsuleCRM::BelongsToAssociationTest
|
4
|
+
include Virtus
|
5
|
+
|
6
|
+
attribute :name
|
7
|
+
|
8
|
+
def self.find(id)
|
9
|
+
new(name: 'test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe CapsuleCRM::Associations::BelongsToAssociation do
|
14
|
+
let(:association_name) { Faker::Lorem.word.to_sym }
|
15
|
+
let(:defined_on) { double }
|
16
|
+
let(:options) do
|
17
|
+
{ class_name: 'CapsuleCRM::BelongsToAssociationTest' }
|
18
|
+
end
|
19
|
+
let(:association) do
|
20
|
+
CapsuleCRM::Associations::BelongsToAssociation.
|
21
|
+
new(association_name, defined_on, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#macro' do
|
25
|
+
subject { association.macro }
|
26
|
+
|
27
|
+
it 'should return :belongs_to' do
|
28
|
+
expect(subject).to eql(:belongs_to)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#foreign_key' do
|
33
|
+
context 'when a foreign_key is not supplied' do
|
34
|
+
subject { association.foreign_key }
|
35
|
+
|
36
|
+
it 'should build the foreign key' do
|
37
|
+
expect(subject).to eql("#{association_name}_id")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when a foreign key is supplied' do
|
42
|
+
before { options.merge!(foreign_key: 'bleurgh') }
|
43
|
+
subject { association.foreign_key }
|
44
|
+
|
45
|
+
it 'should return the supplied foreign key' do
|
46
|
+
expect(subject).to eql(options[:foreign_key])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#serializable_key' do
|
52
|
+
subject { association.serializable_key }
|
53
|
+
context 'when a serializable_key is supplied' do
|
54
|
+
let(:serializable_key) { Faker::Lorem.word }
|
55
|
+
before { options.merge!(serializable_key: serializable_key) }
|
56
|
+
|
57
|
+
it 'should return the serializable_key' do
|
58
|
+
expect(subject).to eql(serializable_key)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when a serializable_key is not supplied' do
|
63
|
+
it 'should return the foreign key' do
|
64
|
+
expect(subject).to eql(association.foreign_key)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#object' do
|
70
|
+
before { options.merge!(foreign_key: :some_id) }
|
71
|
+
let(:object) { double(some_id: Random.rand(1..10)) }
|
72
|
+
subject { association.parent(object) }
|
73
|
+
|
74
|
+
it 'should return the parent' do
|
75
|
+
expect(subject).to be_a(CapsuleCRM::BelongsToAssociationTest)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CapsuleCRM::SomeClass
|
4
|
+
include Virtus
|
5
|
+
|
6
|
+
attribute :name
|
7
|
+
|
8
|
+
def self._for_mock(mock_id)
|
9
|
+
['test']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe CapsuleCRM::Associations::HasManyAssociation do
|
14
|
+
let(:association_name) { Faker::Lorem.word.to_sym }
|
15
|
+
let(:defined_on) { double }
|
16
|
+
let(:options) do
|
17
|
+
{ class_name: 'CapsuleCRM::SomeClass' }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#macro' do
|
21
|
+
subject { described_class.new(association_name, defined_on, options).macro }
|
22
|
+
|
23
|
+
it 'should eql :has_many' do
|
24
|
+
expect(subject).to eql(:has_many)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#defined_on' do
|
29
|
+
subject do
|
30
|
+
described_class.new(association_name, defined_on, options).defined_on
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return the defined_on argument' do
|
34
|
+
expect(subject).to eql(defined_on)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#proxy' do
|
39
|
+
let(:association) do
|
40
|
+
described_class.new(association_name, defined_on, options)
|
41
|
+
end
|
42
|
+
let(:parent) { double(id: Random.rand(1..10)) }
|
43
|
+
|
44
|
+
context 'when a collection is not supplied' do
|
45
|
+
subject { association.proxy(parent) }
|
46
|
+
|
47
|
+
it 'should return a HasManyProxy' do
|
48
|
+
expect(subject).to eql(['test'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when a collection is not supplied' do
|
53
|
+
let(:name) { Faker::Lorem.word }
|
54
|
+
|
55
|
+
context 'when the collection is a hash' do
|
56
|
+
let(:collection) do
|
57
|
+
{ some_class: { name: name } }
|
58
|
+
end
|
59
|
+
subject { association.proxy(parent, collection) }
|
60
|
+
|
61
|
+
it 'should return an array' do
|
62
|
+
expect(subject).to be_a(Array)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should contain a new instance of the "SomeClass"' do
|
66
|
+
expect(subject.first).to be_a(CapsuleCRM::SomeClass)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should set the "SomeClass" instance attributes' do
|
70
|
+
expect(subject.first.name).to eql(name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when the collection is an array' do
|
75
|
+
let(:collection) { [CapsuleCRM::SomeClass.new(name: name)] }
|
76
|
+
subject { association.proxy(parent, collection) }
|
77
|
+
|
78
|
+
it 'should return the supplied array' do
|
79
|
+
expect(subject).to eql(collection)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class Parent
|
4
4
|
include Virtus
|
5
|
-
include CapsuleCRM::Associations
|
5
|
+
include CapsuleCRM::Associations
|
6
6
|
|
7
7
|
attribute :id, Integer
|
8
8
|
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
|
16
16
|
class Child
|
17
17
|
include Virtus
|
18
|
-
include CapsuleCRM::Associations
|
18
|
+
include CapsuleCRM::Associations
|
19
19
|
|
20
20
|
attribute :name
|
21
21
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CapsuleCRM::AssociationsTest
|
4
|
+
include Virtus
|
5
|
+
include CapsuleCRM::Associations
|
6
|
+
|
7
|
+
has_many :whatevers, class_name: 'CapsuleCRM::Party'
|
8
|
+
|
9
|
+
belongs_to :something, class_name: 'CapsuleCRM::Task'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe CapsuleCRM::Associations do
|
13
|
+
describe '.has_many_associations' do
|
14
|
+
subject { CapsuleCRM::AssociationsTest.has_many_associations }
|
15
|
+
|
16
|
+
it 'should return a hash' do
|
17
|
+
expect(subject).to be_a(Hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should contain 1 item' do
|
21
|
+
expect(subject.length).to eql(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should contain a has many association' do
|
25
|
+
expect(subject[:whatevers]).
|
26
|
+
to be_a(CapsuleCRM::Associations::HasManyAssociation)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.belongs_to_associations' do
|
31
|
+
subject { CapsuleCRM::AssociationsTest.belongs_to_associations }
|
32
|
+
|
33
|
+
it 'should return a hash' do
|
34
|
+
expect(subject).to be_a(Hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should contain 1 item' do
|
38
|
+
expect(subject.length).to eql(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should contain a belongs to association' do
|
42
|
+
expect(subject[:something]).
|
43
|
+
to be_a(CapsuleCRM::Associations::BelongsToAssociation)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|