insightly 0.1.1

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,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::OpportunityStateReason do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+ Insightly::Configuration.logger = Insightly::Configuration._debug_logger
7
+
8
+
9
+ @open_state = Insightly::OpportunityStateReason.build({"STATE_REASON_ID" => 100,
10
+ "FOR_OPPORTUNITY_STATE" => "Open",
11
+ "STATE_REASON" => "Referral"})
12
+ @lost_state = Insightly::OpportunityStateReason.build({"STATE_REASON_ID" => 101,
13
+ "FOR_OPPORTUNITY_STATE" => "Lost",
14
+ "STATE_REASON" => "Chose the other guy"})
15
+ @abandoned_state = Insightly::OpportunityStateReason.build({"STATE_REASON_ID" => 102,
16
+ "FOR_OPPORTUNITY_STATE" => "Abandoned",
17
+ "STATE_REASON" => "No phone number."})
18
+ @won_state = Insightly::OpportunityStateReason.build({"STATE_REASON_ID" => 103,
19
+ "FOR_OPPORTUNITY_STATE" => "Won",
20
+ "STATE_REASON" => "They converted"})
21
+ @suspended_state = Insightly::OpportunityStateReason.build({"STATE_REASON_ID" => 104,
22
+ "FOR_OPPORTUNITY_STATE" => "Suspended",
23
+ "STATE_REASON" => "Follow up at Xmas"})
24
+ @all_states = [@open_state, @lost_state, @abandoned_state, @won_state, @suspended_state]
25
+ # @task_links = Insightly::TaskLink.all
26
+ # d = 1
27
+ end
28
+ it "should have a url base" do
29
+ Insightly::OpportunityStateReason.new.url_base.should == "OpportunityStateReasons"
30
+ end
31
+ it "should know the opportunity state" do
32
+ @open_state.state.should == "Open"
33
+ end
34
+ context "remote query" do
35
+ before(:each) do
36
+ Insightly::OpportunityStateReason.any_instance.stub(:get_collection).and_return(@all_states.collect { |x| x.remote_data })
37
+ end
38
+ it "should return nil if there is no match for state and reason" do
39
+ Insightly::OpportunityStateReason.find_by_state_reason("Won","They hated us.").should be nil
40
+ Insightly::OpportunityStateReason.find_by_state_reason("Wont","They converted").should be nil
41
+ Insightly::OpportunityStateReason.find_by_state_reason("Wont","They hated us.").should be nil
42
+ end
43
+ it "should return a opportunity state reason if you search by state and reason" do
44
+ Insightly::OpportunityStateReason.find_by_state_reason("Won","They converted").should == @won_state
45
+ end
46
+ it "should return nil if there is no match for the reason in a given state" do
47
+ Insightly::OpportunityStateReason.won("They hated us.").should be nil
48
+
49
+ end
50
+ it "should return an opportunity state reason if you search for a reason for a given state" do
51
+ Insightly::OpportunityStateReason.won("They converted").should == @won_state
52
+ end
53
+ it "should be able to pull down all of them" do
54
+ Insightly::OpportunityStateReason.all.should == @all_states
55
+ end
56
+
57
+ it "should pull reasons for Open" do
58
+ Insightly::OpportunityStateReason.open.should == [@open_state]
59
+ end
60
+ it "should pull reasons for Lost" do
61
+ Insightly::OpportunityStateReason.lost.should == [@lost_state]
62
+ end
63
+ it "should pull reasons for Abandoned" do
64
+ Insightly::OpportunityStateReason.abandoned.should == [@abandoned_state]
65
+ end
66
+ it "should pull reasons for Won" do
67
+ Insightly::OpportunityStateReason.won.should == [@won_state]
68
+ end
69
+ it "should pull reasons for Suspended" do
70
+
71
+ Insightly::OpportunityStateReason.suspended.should == [@suspended_state]
72
+ end
73
+
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::TaskLink do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+
7
+ @tl1 = Insightly::TaskLink.new.build({"CONTACT_ID" => 3004829,
8
+ "OPPORTUNITY_ID" => nil,
9
+ "TASK_ID" => 11751,
10
+ "TASK_LINK_ID" => 106710,
11
+ "ORGANIZATION_ID" => nil,
12
+ "PROJECT_ID" => nil})
13
+ @tl2 = Insightly::TaskLink.new.build({"CONTACT_ID" => nil,
14
+ "OPPORTUNITY_ID" => 1000,
15
+ "TASK_ID" => 151751,
16
+ "TASK_LINK_ID" => 106710,
17
+ "ORGANIZATION_ID" => nil,
18
+ "PROJECT_ID" => nil})
19
+ # @task_links = Insightly::TaskLink.all
20
+ # d = 1
21
+ end
22
+ it "should have a url base" do
23
+ Insightly::TaskLink.new.url_base.should == "TaskLinks"
24
+ end
25
+ it "should know the task id" do
26
+ @tl1.task_id.should == 11751
27
+ @tl2.task_id.should == 151751
28
+ end
29
+ it "should know the opportunity id" do
30
+ @tl1.opportunity_id.should == nil
31
+ @tl2.opportunity_id.should == 1000
32
+ end
33
+ it "should be able to pull down all of them" do
34
+
35
+ result = [ @tl1.remote_data, @tl2.remote_data]
36
+
37
+ Insightly::TaskLink.any_instance.stub(:get_collection).and_return(result)
38
+ Insightly::TaskLink.all.should == [@tl1,@tl2]
39
+ end
40
+ it "should be able to search by opportunity id" do
41
+ result = [ @tl1.remote_data, @tl2.remote_data]
42
+
43
+ Insightly::TaskLink.any_instance.stub(:get_collection).and_return(result)
44
+ Insightly::TaskLink.search_by_opportunity_id(@tl2.opportunity_id).should == [@tl2]
45
+ end
46
+
47
+ end
@@ -0,0 +1,135 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Insightly::Task do
4
+ before(:each) do
5
+ Insightly::Configuration.api_key = INSIGHTLY_API_KEY
6
+ Insightly::Configuration.logger = Insightly::Configuration._debug_logger
7
+ @task = Insightly::Task.new.build({
8
+ "TASKLINKS" => {"OPPORTUNITY_ID" => 955454,
9
+ "TASK_LINK_ID" => 2744236,
10
+ "PROJECT_ID" => nil,
11
+ "CONTACT_ID" => nil,
12
+ "TASK_ID" => nil,
13
+ "ORGANIZATION_ID" => nil
14
+ },
15
+ "STATUS" => "NOT STARTED",
16
+ "OWNER_USER_ID" => 226277,
17
+ "RESPONSIBLE_USER_ID" => 226277,
18
+ "PUBLICLY_VISIBLE" => true,
19
+ "PARENT_TASK_ID" => nil,
20
+ "COMPLETED_DATE_UTC" => nil,
21
+ "CATEGORY_ID" => 125618,
22
+ "PERCENT_COMPLETE" => 0,
23
+ "START_DATE" => 0,
24
+ "PRIORITY" => 2,
25
+ "DETAILS" => "Make sure you log into the app to set the flag.",
26
+ "DUE_DATE" => "2012-09-05 16:12:20",
27
+ "PROJECT_ID" => nil,
28
+ "COMPLETED" => false,
29
+ "TASK_ID" => 3216775,
30
+ "DATE_CREATED_UTC" => "2012-09-05 16:12:20",
31
+ "TITLE" => "Flag the Customer"
32
+ })
33
+
34
+ # @task = Insightly::Task.new(3216775)
35
+ end
36
+ it "should be able to create a task" do
37
+ end
38
+ it "should have a url base" do
39
+ @task.url_base.should == "Tasks"
40
+ end
41
+ it "should know the task id" do
42
+ @task.task_id.should == 3216775
43
+ end
44
+ it "should know that the remote id and the task id are the same" do
45
+ @task.remote_id.should == @task.task_id
46
+ end
47
+ it "should allow you to load based on an id"
48
+ it "should allow you to build an object from a hash" do
49
+ task = Insightly::Task.new.build({"TITLE" => "Other"})
50
+ task.remote_data.should == {"TITLE" => "Other"}
51
+ end
52
+ it "should know the status of the task" do
53
+ @task.status.should == "NOT STARTED"
54
+ end
55
+ context "comments" do
56
+ before(:each) do
57
+ #@task = Insightly::Task.new(3216775)
58
+ @comment = Insightly::Comment.new.build({
59
+ "COMMENT_ID" => 132456,
60
+ "BODY" => "test comment",
61
+ "OWNER_USER_ID" => 12345,
62
+ "DATE_CREATED_UTC" => "2012-03-09 11:59:19",
63
+ "DATE_UPDATED_UTC" => "2012-03-09 11:59:19",
64
+ "FILE_ATTACHMENTS" =>
65
+ {
66
+ "FILE_ID" => 4567899,
67
+ "FILE_NAME" => "test.docx",
68
+ "CONTENT_TYPE" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
69
+ "FILE_SIZE" => 2489,
70
+ "FILE_CATEGORY_ID" => nil,
71
+ "OWNER_USER_ID" => 12345,
72
+ "DATE_CREATED_UTC" => "2012-03-09 11:59:20",
73
+ "DATE_UPDATED_UTC" => "2012-03-09 11:59:20",
74
+ "URL" => "/api/fileattachments/4567899"
75
+ }
76
+ }
77
+ )
78
+
79
+ end
80
+ it "should be able to fetch the comments" do
81
+ Insightly::Task.any_instance.should_receive(:get_collection).with("Tasks/#{@task.task_id}/comments").and_return([@comment.remote_data])
82
+ comments = @task.comments
83
+ comments.length.should == 1
84
+ comments.first.body.should == "test comment"
85
+ end
86
+ it "should be able to post a new comment" do
87
+ value= "Test Comment #{Time.now}"
88
+ @comment.body = value
89
+ incoming_comment = Insightly::Comment.new.build({"BODY" => value})
90
+ Insightly::Task.any_instance.should_receive(:post_collection).with("Tasks/#{@task.task_id}/comments", incoming_comment.remote_data.to_json).and_return(@comment.remote_data)
91
+ #@task = Insightly::Task.new(3216775)
92
+
93
+ result = @task.comment_on(value)
94
+ result.comment_id.should_not be_nil
95
+ result.body.should == value
96
+ end
97
+ end
98
+ context "Status query" do
99
+ before(:each) do
100
+ @statuses = ["NOT STARTED", "IN PROGRESS", "WAITING", "COMPLETED", "DEFERRED"]
101
+ end
102
+ it "should know that is it not started" do
103
+ @statuses.each do |s|
104
+ @task.status = s
105
+ s == "NOT STARTED" ? (@task.should be_not_started) : (@task.should_not be_not_started)
106
+ end
107
+ end
108
+ it "should know that is it in progress" do
109
+ @statuses.each do |s|
110
+ @task.status = s
111
+ s == "IN PROGRESS" ? (@task.should be_in_progress) : (@task.should_not be_in_progress)
112
+ end
113
+ end
114
+ it "should know that is it waiting" do
115
+ @statuses.each do |s|
116
+ @task.status = s
117
+ s == "WAITING" ? (@task.should be_waiting) : (@task.should_not be_waiting)
118
+ end
119
+ end
120
+ it "should know that is it completed" do
121
+ @statuses.each do |s|
122
+ @task.status = s
123
+ s == "COMPLETED" ? (@task.should be_completed) : (@task.should_not be_completed)
124
+ end
125
+ end
126
+ it "should know that is it deferred" do
127
+ @statuses.each do |s|
128
+ @task.status = s
129
+ s == "DEFERRED" ? (@task.should be_deferred) : (@task.should_not be_deferred)
130
+ end
131
+ end
132
+
133
+
134
+ end
135
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: insightly
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Dirk Elmendorf
14
+ - r26D
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-09-10 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ version: 2.0.0
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ name: builder
37
+ - !ruby/object:Gem::Dependency
38
+ type: :runtime
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 1
45
+ segments:
46
+ - 1
47
+ - 7
48
+ - 5
49
+ version: 1.7.5
50
+ version_requirements: *id002
51
+ prerelease: false
52
+ name: json
53
+ - !ruby/object:Gem::Dependency
54
+ type: :runtime
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 1
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 7
65
+ version: 1.6.7
66
+ version_requirements: *id003
67
+ prerelease: false
68
+ name: rest-client
69
+ - !ruby/object:Gem::Dependency
70
+ type: :runtime
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 15
77
+ segments:
78
+ - 1
79
+ - 2
80
+ - 8
81
+ version: 1.2.8
82
+ version_requirements: *id004
83
+ prerelease: false
84
+ name: logger
85
+ - !ruby/object:Gem::Dependency
86
+ type: :runtime
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 7
93
+ segments:
94
+ - 3
95
+ - 0
96
+ - 0
97
+ version: 3.0.0
98
+ version_requirements: *id005
99
+ prerelease: false
100
+ name: active_support
101
+ - !ruby/object:Gem::Dependency
102
+ type: :runtime
103
+ requirement: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 5
109
+ segments:
110
+ - 0
111
+ - 6
112
+ - 1
113
+ version: 0.6.1
114
+ version_requirements: *id006
115
+ prerelease: false
116
+ name: i18n
117
+ description: Ruby library for integrating with http://Insight.ly
118
+ email: code@r26d.com
119
+ executables: []
120
+
121
+ extensions: []
122
+
123
+ extra_rdoc_files: []
124
+
125
+ files:
126
+ - README.rdoc
127
+ - LICENSE
128
+ - lib/insightly.rb
129
+ - lib/insightly/base.rb
130
+ - lib/insightly/comment.rb
131
+ - lib/insightly/configuration.rb
132
+ - lib/insightly/task_link.rb
133
+ - lib/insightly/read_only.rb
134
+ - lib/insightly/read_write.rb
135
+ - lib/insightly/version.rb
136
+ - lib/insightly/opportunity.rb
137
+ - lib/insightly/task.rb
138
+ - lib/insightly/opportunity_state_reason.rb
139
+ - spec/unit/task_link_spec.rb
140
+ - spec/unit/configuration_spec.rb
141
+ - spec/unit/task_spec.rb
142
+ - spec/unit/comment_spec.rb
143
+ - spec/unit/base_spec.rb
144
+ - spec/unit/opportunity_spec.rb
145
+ - spec/unit/opportunity_state_reason_spec.rb
146
+ - spec/spec_helper.rb
147
+ - insightly.gemspec
148
+ homepage: https://github.com/r26D/insightly
149
+ licenses: []
150
+
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.24
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Insight.ly Ruby Client Library
181
+ test_files: []
182
+