Skip to content

Commit

Permalink
Add TaskCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbeedle committed Jan 18, 2014
1 parent 9366ebe commit d01fffe
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/capsule_crm.rb
Expand Up @@ -42,6 +42,7 @@
require 'capsule_crm/participant'
require 'capsule_crm/person'
require 'capsule_crm/milestone'
require 'capsule_crm/task_category'
require 'capsule_crm/track'
require 'capsule_crm/version'
require 'capsule_crm/faraday/middleware/raise_error'
Expand Down
8 changes: 2 additions & 6 deletions lib/capsule_crm/task.rb
Expand Up @@ -27,6 +27,8 @@ class Task
belongs_to :opportunity
belongs_to :case
belongs_to :owner, class_name: 'CapsuleCRM::User', serializable_key: :owner
belongs_to :category, class_name: 'CapsuleCRM::TaskCategory',
serializable_key: :category

validates :id, numericality: { allow_blank: true }
validates :description, presence: true
Expand Down Expand Up @@ -73,12 +75,6 @@ def reopen
self
end

# TODO Change this to an embedded association, like custom fields
def self.categories
CapsuleCRM::Connection.
get('/api/task/categories')['taskCategories']['taskCategory']
end

def create_url
if party_id
"party/#{party_id}/task"
Expand Down
32 changes: 32 additions & 0 deletions lib/capsule_crm/task_category.rb
@@ -0,0 +1,32 @@
module CapsuleCRM
class TaskCategory
include Virtus

include ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations

include CapsuleCRM::Associations
include CapsuleCRM::Querying::Configuration
include CapsuleCRM::Querying::FindAll
include CapsuleCRM::Serializable

queryable_config do |config|
config.plural = 'task/categories'
end

serializable_config do |config|
config.collection_root = 'taskCategories'
config.root = 'taskCategory'
config.attribute_to_assign = :name
end

attribute :name

validates :name, presence: true

has_many :tasks

def id; name; end
end
end
5 changes: 5 additions & 0 deletions spec/lib/capsule_crm/task_category_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe CapsuleCRM::TaskCategory do
it_behaves_like 'listable', '/task/categories', 'categories', 6
end
12 changes: 0 additions & 12 deletions spec/lib/capsule_crm/task_spec.rb
Expand Up @@ -74,18 +74,6 @@
it { should be_persisted }
end

describe '.categories' do
subject { CapsuleCRM::Task.categories }
before do
stub_request(:get, /\/api\/task\/categories$/).
to_return(body: File.read('spec/support/task_categories.json'))
end

it do
expect(subject).to eql(%w(Call Email Follow-up Meeting Milestone Send))
end
end

describe '#to_capsule_json' do
let(:task) { Fabricate.build(:task) }

Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions spec/support/no_categories.json
@@ -0,0 +1,5 @@
{
"taskCategories": {
"@size": "0"
}
}

0 comments on commit d01fffe

Please sign in to comment.