pipejump 0.2.0 → 0.3.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.
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ describe Pipejump::Note do
3
+
4
+ before do
5
+ @session = PipejumpSpec.session
6
+ @contact = @session.contacts.create(:name => 'contact1' + uuid)
7
+ end
8
+
9
+ after do
10
+ @contact.destroy
11
+ end
12
+
13
+ describe '#all' do
14
+
15
+ before do
16
+ @note = @contact.notes.create(:content => 'Some note')
17
+ end
18
+
19
+ after do
20
+ @note.destroy
21
+ end
22
+
23
+ it "should fetch notes within a contact" do
24
+ @contact.notes.size.should == 1
25
+ @contact.notes.first.content.should == 'Some note'
26
+ end
27
+
28
+ end
29
+
30
+ describe '#find' do
31
+
32
+ it "should fetch notes within a contact" do
33
+ @note = @contact.notes.create(:content => 'Some note')
34
+ @found = @contact.notes.find(@note.id)
35
+ @found.content.should == 'Some note'
36
+ end
37
+
38
+ it "should raise an error if not found" do
39
+ lambda {
40
+ @contact.notes.find(-1)
41
+ }.should raise_error(Pipejump::ResourceNotFound)
42
+ end
43
+
44
+ end
45
+
46
+ describe '#create' do
47
+
48
+ it "should create note with valid params" do
49
+ @note = @contact.notes.create(:content => 'Some note')
50
+ ["content", "created_at", "id", "updated_at", "username"].each do |key|
51
+ @note.attributes.keys.should include(key)
52
+ end
53
+ @note.destroy
54
+ end
55
+
56
+ it "should not create note with invalid params" do
57
+ @note = @contact.notes.create(:content => '')
58
+ @note.errors['note'].collect{ |e| e['error']['field'] }.sort.should == ['content']
59
+ end
60
+
61
+ end
62
+
63
+ describe '#update' do
64
+
65
+ before do
66
+ @note = @contact.notes.create(:content => 'Some note')
67
+ end
68
+
69
+ after do
70
+ @note.destroy
71
+ end
72
+
73
+ it "should update note with valid params" do
74
+ @note.content = 'Updated note'
75
+ @note.save.should == true
76
+ @contact.notes.find(@note.id).content.should == 'Updated note'
77
+ end
78
+
79
+ it "should not update note with invalid params" do
80
+ @note.content = ''
81
+ @note.save.should == false
82
+ @note.errors['note'].collect{ |e| e['error']['field'] }.sort.should == ['content']
83
+ end
84
+
85
+ end
86
+
87
+ describe '#destroy' do
88
+
89
+ it "should destroy a note" do
90
+ @note = @contact.notes.create(:content => 'Some note')
91
+ @note.destroy.should == true
92
+ lambda {
93
+ @contact.notes.find(@note.id)
94
+ }.should raise_error(Pipejump::ResourceNotFound)
95
+
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pipejump::Reminder do
4
+
5
+ before do
6
+ @session = PipejumpSpec.session
7
+ @contact = @session.contacts.create(:name => 'contact1' + uuid)
8
+ @valid = { :content => 'Some reminder', :remind => true, :hour => '13', :date => Time.now + 7 * 60 * 60 * 24 }
9
+ end
10
+
11
+ after do
12
+ @contact.destroy
13
+ end
14
+
15
+ describe '#all' do
16
+
17
+ before do
18
+ @reminder = @contact.reminders.create(@valid)
19
+ end
20
+
21
+ after do
22
+ @reminder.destroy
23
+ end
24
+
25
+ it "should fetch reminders within a contact" do
26
+ @contact.reminders.size.should == 1
27
+ last = @contact.reminders.last
28
+ last.content.should == 'Some reminder'
29
+ last.hour.to_i.should == 13
30
+ end
31
+
32
+ end
33
+
34
+ describe '#find' do
35
+
36
+ it "should find reminder" do
37
+ @reminder = @contact.reminders.create(@valid)
38
+ @found = @contact.reminders.find(@reminder.id)
39
+ @found.content.should == 'Some reminder'
40
+ end
41
+
42
+ it "should raise an error if not found" do
43
+ lambda {
44
+ @contact.reminders.find(-1)
45
+ }.should raise_error(Pipejump::ResourceNotFound)
46
+ end
47
+
48
+ end
49
+
50
+ describe '#create' do
51
+
52
+ describe 'with remind' do
53
+
54
+ it "should create reminder with valid params" do
55
+ @reminder = @contact.reminders.create(@valid)
56
+
57
+ ["content", "created_at", "date", "done", "id", "remind", "hour", "updated_at"].each do |key|
58
+ @reminder.attributes.keys.should include(key)
59
+ end
60
+
61
+ @reminder.destroy
62
+ end
63
+
64
+ it "should not create reminder with invalid params" do
65
+ @reminder = @contact.reminders.create(:content => '', :remind => true)
66
+ fields = @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort
67
+ fields.should include('content')
68
+ end
69
+
70
+ end
71
+
72
+ describe 'without remind' do
73
+
74
+ it "should create reminder with valid params" do
75
+ @reminder = @contact.reminders.create(:content => 'Foo', :remind => false)
76
+ ["content", "created_at", "date", "done", "id", "remind", "hour", "updated_at"].each do |key|
77
+ @reminder.attributes.keys.should include(key)
78
+ end
79
+ @reminder.destroy
80
+ end
81
+
82
+ it "should not create reminder with invalid params" do
83
+ @reminder = @contact.reminders.create(:content => '', :remind => false)
84
+ @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort.should == ["content"]
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ describe '#update' do
92
+
93
+ before do
94
+ @reminder = @contact.reminders.create(@valid)
95
+ end
96
+
97
+ after do
98
+ @reminder.destroy
99
+ end
100
+
101
+ it "should update reminder with valid params" do
102
+ @reminder.content = 'Updated reminder'
103
+ @reminder.save.should == true
104
+ @contact.reminders.find(@reminder.id).content.should == 'Updated reminder'
105
+ end
106
+
107
+ it "should not update reminder with invalid params" do
108
+ @reminder.content = ''
109
+ @reminder.save.should == false
110
+ @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort.should == ['content']
111
+ end
112
+
113
+ end
114
+
115
+ describe '#destroy' do
116
+
117
+ it "should destroy a reminder" do
118
+ @reminder = @contact.reminders.create(@valid)
119
+ @reminder.destroy.should == true
120
+ lambda {
121
+ @contact.reminders.find(@reminder.id)
122
+ }.should raise_error(Pipejump::ResourceNotFound)
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
@@ -1,93 +1,101 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
+
2
3
  describe Pipejump::Contact do
3
4
 
4
- before do
5
+ before do
5
6
  @session = PipejumpSpec.session
6
- @client = @session.clients.create(:name => 'Client1')
7
- @contact1 = @session.contacts.create(:name => 'contact1', :client_id => @client.id)
7
+ @organisation = @session.contacts.create(:name => 'Client1'+uuid, :is_organisation => true)
8
+ @contact1 = @session.contacts.create(:name => 'contact1'+uuid, :contact_id => @organisation.id)
8
9
  @contact1.id.should_not be_nil
9
- @contact2 = @session.contacts.create(:name => 'contact2', :client_id => @client.id)
10
+ @contact2 = @session.contacts.create(:name => 'contact2'+uuid, :contact_id => @organisation.id)
10
11
  @contact2.id.should_not be_nil
11
12
  end
12
-
13
+
13
14
  after do
14
- @client.destroy
15
+ @organisation.destroy
15
16
  @contact1.destroy
16
17
  @contact2.destroy
17
18
  end
18
-
19
+
19
20
  describe '@session.contacts' do
20
-
21
+
21
22
  it ".all should return all contacts" do
22
- @session.contacts.all.collect(&:name).should == [@contact1, @contact2].collect(&:name)
23
+ @session.contacts.all.collect(&:name).include?(@contact1.name).should == true
24
+ @session.contacts.all.collect(&:name).include?(@contact2.name).should == true
23
25
  end
24
26
 
25
- it ".first should return first contact" do
26
- @session.contacts.first.name.should == @contact1.name
27
+ it ".first should return first organisation" do
28
+ @session.contacts.first.class.should == Pipejump::Contact
27
29
  end
28
30
 
29
- it ".last should return last contact" do
30
- @session.contacts.last.name.should == @contact2.name
31
+ it ".last should return last organisation" do
32
+ @session.contacts.last.class.should == Pipejump::Contact
31
33
  end
32
-
34
+
33
35
  it ".find should find exact contact" do
34
36
  @session.contacts.find(@contact1.id).name.should == @contact1.name
35
37
  end
36
-
37
- end
38
-
38
+
39
+ end
40
+
39
41
  describe '#method_missing' do
40
-
41
- it "should correctly get and set attributes" do
42
- @contact1.attributes.keys.sort.should == ["client_id", "email", "id", "mobile", "name", "phone"]
43
- @contact1.attributes.keys.each do |attribute|
42
+
43
+ it "should correctly get and set attributes" do
44
+ ["contact_id", "email", "id", "mobile", "name", "phone", 'private'].each do |key|
45
+ @contact1.attributes.keys.include?(key).should == true
46
+ end
47
+ (@contact1.attributes.keys - ['organisation']).each do |attribute|
44
48
  @contact1.send(attribute).should == @contact1.attributes[attribute]
45
49
  end
46
50
  @contact1.name = 'Different name'
47
51
  @contact1.name.should == 'Different name'
48
52
  @contact1.attributes['name'].should == 'Different name'
49
53
  end
50
-
54
+
51
55
  it "should raise a NoMethodError when no accessor is set" do
52
56
  lambda {
53
57
  @contact1.not_a_method_name
54
58
  }.should raise_error(NoMethodError)
55
59
  end
56
-
60
+
57
61
  end
58
62
 
59
63
  describe '#create' do
60
-
64
+
61
65
  it "should create record" do
62
- @contact3 = @session.contacts.create(:name => 'contact3', :client_id => @client.id)
66
+ name = 'contact3'+uuid
67
+ @contact3 = @session.contacts.create(:name => name, :contact_id => @organisation.id)
63
68
  @contact3.id.should_not be_nil
64
- @contact3.name.should == 'contact3'
65
- @session.contacts.find(@contact3.id).name.should == 'contact3'
69
+ @contact3.name.should == name
70
+ @session.contacts.find(@contact3.id).name.should == name
66
71
  @contact3.destroy
67
72
  end
68
-
73
+
69
74
  it "should return error on validation fail" do
70
75
  @contact3 = @session.contacts.create(:name => '')
71
76
  @contact3.id.should be_nil
72
- @contact3.errors.should_not == {}
77
+ @contact3.errors.should_not == {}
73
78
  end
74
-
79
+
75
80
  end
76
81
 
77
82
  describe '#update' do
78
-
83
+
79
84
  it "should update record" do
80
- @contact1.name = 'Different name'
85
+ name = "Different name #{uuid}"
86
+ @contact1.name = name
87
+ @contact1.last_name = name
81
88
  @contact1.save.should == true
82
- @session.contacts.find(@contact1.id).name.should == 'Different name'
89
+ @session.contacts.find(@contact1.id).name.should == name
83
90
  end
84
-
91
+
85
92
  it "should return error on validation fail" do
86
93
  @contact1.name = ''
94
+ @contact1.last_name = ''
87
95
  @contact1.save.should == false
88
- @contact1.errors.should_not == {}
96
+ @contact1.errors.should_not == {}
89
97
  end
90
-
98
+
91
99
  end
92
100
 
93
101
  end
@@ -1,33 +1,33 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
  describe Pipejump::Note do
3
-
4
- before do
3
+
4
+ before do
5
5
  @session = PipejumpSpec.session
6
- @client = @session.clients.create(:name => 'Client1')
7
- @deal = @session.deals.create(:name => 'New deal', :client_id => @client.id)
6
+ @contact = @session.contacts.create(:name => 'contact1' + uuid)
7
+ @deal = @session.deals.create(:name => 'New deal' + uuid, :entity_id => @contact.id)
8
8
  end
9
9
 
10
10
  after do
11
- @client.destroy
11
+ @contact.destroy
12
12
  end
13
13
 
14
14
  describe '#all' do
15
-
15
+
16
16
  before do
17
17
  @note = @deal.notes.create(:content => 'Some note')
18
18
  end
19
-
19
+
20
20
  after do
21
21
  @note.destroy
22
22
  end
23
-
23
+
24
24
  it "should fetch notes within a deal" do
25
25
  @deal.notes.size.should == 1
26
26
  @deal.notes.first.content.should == 'Some note'
27
27
  end
28
28
 
29
29
  end
30
-
30
+
31
31
  describe '#find' do
32
32
 
33
33
  it "should fetch notes within a deal" do
@@ -41,60 +41,61 @@ describe Pipejump::Note do
41
41
  @deal.notes.find(-1)
42
42
  }.should raise_error(Pipejump::ResourceNotFound)
43
43
  end
44
-
44
+
45
45
  end
46
-
46
+
47
47
  describe '#create' do
48
-
48
+
49
49
  it "should create note with valid params" do
50
50
  @note = @deal.notes.create(:content => 'Some note')
51
- @note.attributes.keys.sort.should == ["content", "id", "username"]
51
+ ["content", "created_at", "id", "updated_at", "username"].each do |key|
52
+ @note.attributes.keys.should include(key)
53
+ end
52
54
  @note.destroy
53
55
  end
54
-
56
+
55
57
  it "should not create note with invalid params" do
56
58
  @note = @deal.notes.create(:content => '')
57
59
  @note.errors['note'].collect{ |e| e['error']['field'] }.sort.should == ['content']
58
60
  end
59
-
61
+
60
62
  end
61
-
63
+
62
64
  describe '#update' do
63
-
65
+
64
66
  before do
65
67
  @note = @deal.notes.create(:content => 'Some note')
66
68
  end
67
-
69
+
68
70
  after do
69
71
  @note.destroy
70
72
  end
71
-
73
+
72
74
  it "should update note with valid params" do
73
75
  @note.content = 'Updated note'
74
76
  @note.save.should == true
75
77
  @deal.notes.find(@note.id).content.should == 'Updated note'
76
78
  end
77
-
79
+
78
80
  it "should not update note with invalid params" do
79
81
  @note.content = ''
80
82
  @note.save.should == false
81
- @note.errors['note'].collect{ |e| e['error']['field'] }.sort.should == ['content']
83
+ @note.errors['note'].collect{ |e| e['error']['field'] }.sort.should == ['content']
82
84
  end
83
-
85
+
84
86
  end
85
-
87
+
86
88
  describe '#destroy' do
87
-
89
+
88
90
  it "should destroy a note" do
89
91
  @note = @deal.notes.create(:content => 'Some note')
90
92
  @note.destroy.should == true
91
93
  lambda {
92
94
  @deal.notes.find(@note.id)
93
95
  }.should raise_error(Pipejump::ResourceNotFound)
94
-
96
+
95
97
  end
96
98
 
97
99
  end
98
-
100
+
99
101
  end
100
-
@@ -1,35 +1,36 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
+
2
3
  describe Pipejump::Reminder do
3
-
4
- before do
4
+
5
+ before do
5
6
  @session = PipejumpSpec.session
6
- @client = @session.clients.create(:name => 'Client1')
7
- @deal = @session.deals.create(:name => 'New deal', :client_id => @client.id)
8
- @valid = { :content => 'Some reminder', :time => '13:00', :date => Time.now + 7 * 60 * 60 * 24 }
7
+ @contact = @session.contacts.create(:name => 'contact1' + uuid)
8
+ @deal = @session.deals.create(:name => 'New deal' + uuid, :entity_id => @contact.id)
9
+ @valid = { :content => 'Some reminder', :hour => '13:00', :date => Time.now + 7 * 60 * 60 * 24 }
9
10
  end
10
11
 
11
12
  after do
12
- @client.destroy
13
+ @contact.destroy
13
14
  end
14
15
 
15
16
  describe '#all' do
16
-
17
+
17
18
  before do
18
19
  @reminder = @deal.reminders.create(@valid)
19
20
  end
20
-
21
+
21
22
  after do
22
23
  @reminder.destroy
23
24
  end
24
-
25
+
25
26
  it "should fetch reminders within a deal" do
26
27
  @deal.reminders.size.should == 1
27
28
  @deal.reminders.first.content.should == 'Some reminder'
28
- @deal.reminders.first.time.should == '13:00'
29
+ @deal.reminders.first.hour.to_i.should == 13
29
30
  end
30
31
 
31
32
  end
32
-
33
+
33
34
  describe '#find' do
34
35
 
35
36
  it "should find reminder" do
@@ -43,31 +44,38 @@ describe Pipejump::Reminder do
43
44
  @deal.reminders.find(-1)
44
45
  }.should raise_error(Pipejump::ResourceNotFound)
45
46
  end
46
-
47
+
47
48
  end
48
-
49
+
49
50
  describe '#create' do
50
-
51
+
51
52
  describe 'with remind' do
52
-
53
+
53
54
  it "should create reminder with valid params" do
54
55
  @reminder = @deal.reminders.create(@valid)
55
- @reminder.attributes.keys.sort.should == ["content", "date", "done", "id", "remind", "time"]
56
+
57
+ ["content", "created_at", "date", "done", "id", "remind", "hour", "updated_at"].each do |key|
58
+ @reminder.attributes.keys.should include(key)
59
+ end
60
+
56
61
  @reminder.destroy
57
62
  end
58
63
 
59
64
  it "should not create reminder with invalid params" do
60
- @reminder = @deal.reminders.create(:content => '')
61
- @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort.should == ["content", "date", "time"]
65
+ @reminder = @deal.reminders.create(:content => '', :remind => true)
66
+ fields = @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort
67
+ fields.should include('content')
62
68
  end
63
-
69
+
64
70
  end
65
71
 
66
72
  describe 'without remind' do
67
-
73
+
68
74
  it "should create reminder with valid params" do
69
75
  @reminder = @deal.reminders.create(:content => 'Foo', :remind => false)
70
- @reminder.attributes.keys.sort.should == ["content", "date", "done", "id", "remind", "time"]
76
+ ["content", "created_at", "date", "done", "id", "remind", "hour", "updated_at"].each do |key|
77
+ @reminder.attributes.keys.should include(key)
78
+ end
71
79
  @reminder.destroy
72
80
  end
73
81
 
@@ -75,46 +83,46 @@ describe Pipejump::Reminder do
75
83
  @reminder = @deal.reminders.create(:content => '', :remind => false)
76
84
  @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort.should == ["content"]
77
85
  end
78
-
86
+
79
87
  end
80
-
88
+
81
89
  end
82
-
90
+
83
91
  describe '#update' do
84
-
92
+
85
93
  before do
86
94
  @reminder = @deal.reminders.create(@valid)
87
95
  end
88
-
96
+
89
97
  after do
90
98
  @reminder.destroy
91
99
  end
92
-
100
+
93
101
  it "should update reminder with valid params" do
94
102
  @reminder.content = 'Updated reminder'
95
103
  @reminder.save.should == true
96
104
  @deal.reminders.find(@reminder.id).content.should == 'Updated reminder'
97
105
  end
98
-
106
+
99
107
  it "should not update reminder with invalid params" do
100
108
  @reminder.content = ''
101
109
  @reminder.save.should == false
102
- @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort.should == ['content']
110
+ @reminder.errors['reminder'].collect{ |e| e['error']['field'] }.sort.should == ['content']
103
111
  end
104
-
112
+
105
113
  end
106
-
114
+
107
115
  describe '#destroy' do
108
-
116
+
109
117
  it "should destroy a reminder" do
110
118
  @reminder = @deal.reminders.create(@valid)
111
119
  @reminder.destroy.should == true
112
120
  lambda {
113
121
  @deal.reminders.find(@reminder.id)
114
122
  }.should raise_error(Pipejump::ResourceNotFound)
115
-
123
+
116
124
  end
117
125
 
118
126
  end
119
-
127
+
120
128
  end