zendesk2 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjY3NzNhNGNkOWQ2OGU5ZWE1YjNkNDJlZWI2YmNjMTFkODI5M2ZmMQ==
4
+ NTEwMjM0ZDE4MjQ2Mzc5N2RkYTFmODU5MjRkZGQ1YTQ0MjA5MmYzMA==
5
5
  data.tar.gz: !binary |-
6
- MmMxZTEwYTgwZDgwYWEzYjU0MDMzY2U2NjYxNTEwNDUxOWY3OGU0OQ==
6
+ YzBjZmVmOGNiNzU1NDgyNTQ0MDBkMGJkYzNiNTVlOTI1OGFiNjhmNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTJhYTViYWNhMGJlZGU5MGExOGQyMzg5NWE2YmI0OGNhNmIwODAyMzY1MDA3
10
- NDQ3ZTFhMmI2ZDc0ZmIwNDkyZmU4Y2UyZjk0ZDc3NzNmODIxOWVjNmJkNDRl
11
- ZGU5ZjI4MDRhYjIxYWQzZmQwNTk3NWI5N2IxMDU1NDI0NGUxYzk=
9
+ MmNlYTRjZjk2NjI1ZDY5MjQ1N2Y3M2I2MzI5OGIyNmI1N2Y5ZWNiM2M4N2Fm
10
+ OWU1ZDg0OTE3N2I5MGVmMDIwYzBiZjNlOWE1NjlmYzY5MDE2OTc5MGZjODNj
11
+ MTE5OWZlOWI5YTIyZDA0NDNiNDZkNDY2MGEwMDIwMGYxYzNlNmU=
12
12
  data.tar.gz: !binary |-
13
- YzFjNjRmZmU1NzczMDg0MTU2ZDk4MWM4ZThiMTQ5NDA4YmE1NzYyZGIyZjA1
14
- YTliOWZmODdhNGM4ODIzNjU3MDYwMzkwY2U2NWJhYTIwMWQ3OGNhYmE2ZjJj
15
- YzQ0ODU0ZDgxOTE2ZmI0ZDAyM2E1OTI2ZmRlMWU0ZTg0YWM0MTc=
13
+ MmE4NWQyNWIyMjEzMTU1MTYyODYxYTA5OWFmZTg4NTIyMWRjMGU4ZTNkYjM2
14
+ NjUzNTRjMGRjYjFhOTMzYzMzZGFmYThhZDYzMGUyMDI1YjdjYzlhZTkwYzkw
15
+ OWRkNzkzMTk4Y2NhYjY5MDYwNzViODU2ZGFhODE3YmFiNDQzOTQ=
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
  .rspec
19
19
  doc/
20
+ .rvmrc
21
+ .ruby-version
data/README.md CHANGED
@@ -59,6 +59,7 @@ Currently support resources
59
59
  * Groups
60
60
  * Organization
61
61
  * Ticket Audits
62
+ * Ticket Fields
62
63
  * Tickets
63
64
  * Topic Comments
64
65
  * Topics
@@ -49,8 +49,6 @@ class Zendesk2::Client::TicketField < Zendesk2::Model
49
49
  data = if new_record?
50
50
  requires :type, :title
51
51
 
52
- self.custom_field_options ||= []
53
-
54
52
  connection.create_ticket_field(params).body["ticket_field"]
55
53
  else
56
54
  requires :identity
@@ -14,6 +14,22 @@ class Zendesk2::Client
14
14
  identity = self.class.new_id
15
15
 
16
16
  if requester = params.delete('requester')
17
+ if !requester['name'] || requester['name'].size < 1
18
+ response(
19
+ :path => "/tickets.json",
20
+ :method => :post,
21
+ :status => 422,
22
+ :body => {
23
+ "error" => "RecordInvalid",
24
+ "description" => "Record validation errors",
25
+ "details" => {
26
+ "requester" => [
27
+ {
28
+ "description" => "Requester Name: is too short (minimum is 1 characters)"
29
+ }
30
+ ]}})
31
+ end
32
+
17
33
  user_id = if known_user = self.users.search(email: requester['email']).first
18
34
  known_user.identity
19
35
  else
@@ -24,13 +40,20 @@ class Zendesk2::Client
24
40
  params['requester_id'] = user_id
25
41
  end
26
42
 
43
+ custom_fields = (params.delete("custom_fields") || [])
44
+
45
+ self.data[:ticket_fields].each do |field_id, field|
46
+ custom_fields.find { |cf| cf["id"] == field_id } ||
47
+ custom_fields << {"id" => field_id, "value" => nil }
48
+ end
49
+
27
50
  record = {
28
51
  "id" => identity,
29
52
  "url" => url_for("/tickets/#{identity}.json"),
30
53
  "created_at" => Time.now.iso8601,
31
54
  "updated_at" => Time.now.iso8601,
32
55
  "collaborator_ids" => [],
33
- "custom_fields" => [],
56
+ "custom_fields" => custom_fields,
34
57
  }.merge(params)
35
58
 
36
59
  record["requester_id"] ||= current_user["id"]
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -11,13 +11,13 @@ shared_examples "a resource" do |_collection, _params, _update_params, _options|
11
11
  end
12
12
 
13
13
  it "by fetching a specific record" do
14
- record = collection.create(params)
14
+ record = collection.create!(params)
15
15
  collection.get(fetch_params.call(record)).should == record
16
16
  end
17
17
 
18
18
  context "that is paged" do
19
19
  before(:each) do
20
- 3.times.each { collection.create(instance_exec(&_params)) }
20
+ 3.times.each { collection.create!(instance_exec(&_params)) }
21
21
  end
22
22
 
23
23
  it "by retrieving the first page" do
@@ -38,7 +38,7 @@ shared_examples "a resource" do |_collection, _params, _update_params, _options|
38
38
  end
39
39
 
40
40
  it "by updating a record" do
41
- record = collection.create(params)
41
+ record = collection.create!(params)
42
42
  record.merge_attributes(update_params)
43
43
  record.save
44
44
  update_params.each {|k,v| record.send(k).should == v}
@@ -46,7 +46,7 @@ shared_examples "a resource" do |_collection, _params, _update_params, _options|
46
46
 
47
47
  it "by destroying a record" do
48
48
  pending if _collection == :forums
49
- record = collection.create(params)
49
+ record = collection.create!(params)
50
50
  record.identity.should_not be_nil
51
51
  record.destroy
52
52
  record.should be_destroyed
@@ -55,7 +55,7 @@ shared_examples "a resource" do |_collection, _params, _update_params, _options|
55
55
  # Search index takes 2-3 minutes according to the docs
56
56
  it "should search" do
57
57
  pending unless Zendesk2::Client.mocking?
58
- record = collection.create(params)
58
+ record = collection.create!(params)
59
59
  collection.search(params).should include(record)
60
60
  end
61
61
  end
data/spec/tickets_spec.rb CHANGED
@@ -2,25 +2,34 @@ require 'spec_helper'
2
2
 
3
3
  describe "tickets" do
4
4
  let(:client) { create_client }
5
- it_should_behave_like "a resource",
6
- :tickets,
5
+ it_should_behave_like "a resource", :tickets,
7
6
  lambda { {subject: Zendesk2.uuid, description: Zendesk2.uuid} },
8
7
  lambda { {subject: Zendesk2.uuid} }
9
8
 
10
9
  describe "when creating a ticket" do
11
- let!(:requester_email) { "newuser@example.org" }
12
- let!(:ticket) { client.tickets.create(subject: Zendesk2.uuid, description: Zendesk2.uuid, requester: {email: requester_email}) }
10
+ let!(:requester_email) { "#{Zendesk2.uuid}@example.org" }
13
11
 
14
12
  it "should create requester" do
15
- requester = client.users.search(email: requester_email).first
16
- requester.should_not be_nil
13
+ ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, requester: {name: "Josh Lane", email: requester_email})
14
+ if Zendesk2::Client.mocking? # this takes some time for realsies
15
+ requester = client.users.search(email: requester_email).first
16
+ requester.should_not be_nil
17
17
 
18
- ticket.requester.should == requester
18
+ ticket.reload.requester.should == requester
19
+ else
20
+ ticket.reload.requester.should_not be_nil
21
+ end
22
+ end
23
+
24
+ it "should require requester name" do
25
+ expect {
26
+ client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, requester: {email: requester_email})
27
+ }.to raise_exception(Zendesk2::Error, /Requester Name: .* too short/)
19
28
  end
20
29
  end
21
30
 
22
31
  describe "with a created ticket" do
23
- let(:ticket) { client.tickets.create(subject: Zendesk2.uuid, description: Zendesk2.uuid) }
32
+ let(:ticket) { client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid) }
24
33
  it "should get requester" do
25
34
  ticket.requester.should == client.users.current
26
35
  end
@@ -35,7 +44,7 @@ describe "tickets" do
35
44
  end
36
45
 
37
46
  describe "comments" do
38
- let(:ticket) { client.tickets.create(subject: Zendesk2.uuid, description: Zendesk2.uuid) }
47
+ let(:ticket) { client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid) }
39
48
 
40
49
  it "lists audits" do
41
50
  body = Zendesk2.uuid
@@ -60,4 +69,20 @@ describe "tickets" do
60
69
  (comment = ticket.comments.find{|c| c.body == body}).should_not be_nil
61
70
  end
62
71
  end
72
+
73
+ describe "custom fields" do
74
+ let!(:ticket_field) { client.ticket_fields.create!(title: Zendesk2.uuid, type: "textbox") }
75
+
76
+ it "should be based on ticket_fields" do
77
+ ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid)
78
+ custom_field = ticket.custom_fields.find { |cf| cf["id"] == ticket_field.identity }
79
+ custom_field.should_not be_nil
80
+ custom_field["value"].should be_nil
81
+
82
+ ticket = client.tickets.create!(subject: Zendesk2.uuid, description: Zendesk2.uuid, custom_fields: [{"id" => ticket_field.identity, "value" => "jessicaspacekat"}])
83
+ custom_field = ticket.custom_fields.find { |cf| cf["id"] == ticket_field.identity }
84
+ custom_field.should_not be_nil
85
+ custom_field["value"].should == "jessicaspacekat"
86
+ end
87
+ end
63
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-27 00:00:00.000000000 Z
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -88,7 +88,6 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - .gitignore
91
- - .rvmrc
92
91
  - .travis.yml
93
92
  - Gemfile
94
93
  - Guardfile
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.9.3