daengine 0.6.16 → 0.6.17
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.
- checksums.yaml +4 -4
- data/app/controllers/content_folder_controller.rb +30 -0
- data/app/controllers/digital_assets_controller.rb +5 -5
- data/app/models/content_folder.rb +49 -0
- data/config/routes.rb +3 -1
- data/lib/daengine/version.rb +1 -1
- data/spec/acceptance/content_folder_controller_spec.rb +72 -0
- data/spec/factories.rb +18 -0
- data/spec/models/content_folder_spec.rb +95 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc3d0461ac1c9337ae22dbdf014261e342f8ff2d
|
4
|
+
data.tar.gz: db9e2cb957aed90668d113cde843e1cd66d05e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec076eec326d72752ce4de5b7b2764257d7581ade1380ec116f23ef4594946b0b07dd9b64bdb72153e9b6e4bf2ac031f431a19112990e09f245624e1cf609f5
|
7
|
+
data.tar.gz: 772e62c3bc2a8141a54d416f5c70bbe9271736b7143605b7f3d4a73482ce70cb69d5c44e1cfe5942958e8f43c592fe5e7d461b772506f59b7bd8b68a4fcc1e55
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ContentFolderController < ApplicationController
|
2
|
+
respond_to :json
|
3
|
+
|
4
|
+
rescue_from 'Mongoid::Errors::DocumentNotFound' do |exception|
|
5
|
+
render json: {errors: [exception.message]}, status: 404
|
6
|
+
end
|
7
|
+
|
8
|
+
# GET /content_folder
|
9
|
+
# GET /content_folder.json
|
10
|
+
def index
|
11
|
+
content_folder = ContentFolder.last
|
12
|
+
if content_folder.nil?
|
13
|
+
render json: {}, status: :not_found
|
14
|
+
else
|
15
|
+
render json: content_folder
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# POST /content_folder
|
20
|
+
# POST /content_folder.json
|
21
|
+
def create
|
22
|
+
content_folder = ContentFolder.new(params[:content_folder])
|
23
|
+
ContentFolder.delete_all # TODO: need to validate prior to delete
|
24
|
+
if content_folder.save
|
25
|
+
render json: content_folder, status: :created
|
26
|
+
else
|
27
|
+
render json: content_folder.errors, status: :unprocessable_entity
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -48,12 +48,12 @@ class DigitalAssetsController < ApplicationController
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def updated_time
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
updated_time[id] = da[0].doc_changed_at if da.present?
|
51
|
+
if(params[:ids].present?)
|
52
|
+
assets = DigitalAsset.where(:digital_asset_id.in => params[:ids])
|
53
|
+
else
|
54
|
+
assets = DigitalAsset.all
|
56
55
|
end
|
56
|
+
updated_time = Hash[assets.map{|a| [a.digital_asset_id, a.doc_changed_at]}]
|
57
57
|
render json: updated_time.to_json, status: :ok
|
58
58
|
end
|
59
59
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
class ContentFolder
|
4
|
+
include Mongoid::Document
|
5
|
+
#include Mongoid::Timestamps
|
6
|
+
|
7
|
+
field :folder_id, type: String
|
8
|
+
field :label, type: String
|
9
|
+
field :document_ids, type: Array, default: []
|
10
|
+
|
11
|
+
#recursively_embeds_many
|
12
|
+
embeds_many :child_folders, :class_name => "ContentFolder", :cyclic => true
|
13
|
+
accepts_nested_attributes_for :child_folders
|
14
|
+
|
15
|
+
key :folder_id
|
16
|
+
|
17
|
+
validates_presence_of :folder_id, :label
|
18
|
+
validate :validate_has_content
|
19
|
+
|
20
|
+
def validate_has_content
|
21
|
+
if child_folders.empty? && (document_ids.nil? || document_ids.empty?)
|
22
|
+
errors[:base] << 'Either child_folders or document_ids are required'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.lit_center_folder
|
27
|
+
find_folder(FolderIds::LIT_CENTER)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.merrill_lynch_folder
|
31
|
+
find_folder(FolderIds::MERRILL_LYNCH)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.plan_529_folder
|
35
|
+
find_folder(FolderIds::PLANS_529)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.find_folder(id)
|
39
|
+
root = ContentFolder.last
|
40
|
+
child_folders = root.nil? ? [] : Array(root.child_folders)
|
41
|
+
child_folders.find { |folder| id == folder.folder_id } unless child_folders.nil?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class ContentFolder::FolderIds
|
46
|
+
LIT_CENTER = 'lit_center'
|
47
|
+
MERRILL_LYNCH = 'merrill_lynch'
|
48
|
+
PLANS_529 = '529'
|
49
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
resources :digital_assets, except: [:new, :edit], defaults: {format: 'json'} do
|
2
|
+
resources :digital_assets, except: [:new, :edit], defaults: {format: 'json'} do
|
3
3
|
collection do
|
4
4
|
get 'fund_docs'
|
5
5
|
get 'search', to: 'digital_assets#search'
|
@@ -7,4 +7,6 @@ Rails.application.routes.draw do
|
|
7
7
|
post 'updated_time'
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
resources :content_folder, only: [:index, :create], defaults: {format: 'json'}
|
10
12
|
end
|
data/lib/daengine/version.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec_api_documentation'
|
3
|
+
require 'rspec_api_documentation/dsl'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
resource 'Content Folder', :api => true do
|
7
|
+
get '/content_folder' do
|
8
|
+
context 'has a content folder' do
|
9
|
+
example 'returns the content folder' do
|
10
|
+
folder_id = 'folder id'
|
11
|
+
folder = ContentFolder.new(:folder_id => folder_id, :label => 'folder label', :document_ids => %w(id1 id2))
|
12
|
+
ContentFolder.stub(:last).and_return(folder)
|
13
|
+
|
14
|
+
do_request
|
15
|
+
expect(status).to eq(200)
|
16
|
+
result = JSON.parse(response_body)
|
17
|
+
expect(result).not_to be_nil
|
18
|
+
expect(result['folder_id']).to eq(folder_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
example 'returns 404 when the folder does not exist' do
|
22
|
+
ContentFolder.stub(:last).and_return(nil)
|
23
|
+
|
24
|
+
do_request
|
25
|
+
expect(status).to eq(404)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
post '/content_folder' do
|
31
|
+
parameter :folder_id, 'folder id', :require => true, :scope => 'content_folder'
|
32
|
+
parameter :label, 'folder label', :require => true, :scope => 'content_folder'
|
33
|
+
parameter :document_ids, 'array of document ids associated with folder', :require => true, :scope => 'content_folder'
|
34
|
+
parameter :child_folders, 'array of child folder hashes', :require => true, :scope => 'content_folder'
|
35
|
+
|
36
|
+
context 'successful' do
|
37
|
+
folder_id = 'folder id'
|
38
|
+
label = 'label'
|
39
|
+
document_ids = %w(id1 id2)
|
40
|
+
child_folders = nil
|
41
|
+
|
42
|
+
let(:folder_id) { folder_id }
|
43
|
+
let(:label) { label }
|
44
|
+
let(:document_ids) { document_ids }
|
45
|
+
let(:child_folders) { [{:folder_id => 'child folder id', :label => 'child label', :document_ids => document_ids}] }
|
46
|
+
|
47
|
+
example 'stores the content folder and returns the content folder instance' do
|
48
|
+
do_request
|
49
|
+
expect(status).to eq(201)
|
50
|
+
result = JSON.parse(response_body)
|
51
|
+
expect(result).not_to be_nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'missing required values' do
|
56
|
+
folder_id = 'folder id'
|
57
|
+
label = 'label'
|
58
|
+
document_ids = nil
|
59
|
+
child_folders = nil
|
60
|
+
|
61
|
+
let(:folder_id) { folder_id }
|
62
|
+
let(:label) { label }
|
63
|
+
let(:document_ids) { document_ids }
|
64
|
+
let(:child_folders) { child_folders }
|
65
|
+
|
66
|
+
example 'returns status 422 when missing document id and child_folders' do
|
67
|
+
do_request
|
68
|
+
expect(status).to eq(422)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/factories.rb
CHANGED
@@ -37,4 +37,22 @@ FactoryGirl.define do
|
|
37
37
|
fund_codes []
|
38
38
|
display_on_website true
|
39
39
|
end
|
40
|
+
|
41
|
+
factory :content_folder, aliases: [:child_folder] do
|
42
|
+
sequence(:folder_id) { |n| "id-content-folder-#{n}" }
|
43
|
+
label 'Folder Label'
|
44
|
+
|
45
|
+
trait :document_ids do
|
46
|
+
document_ids ['doc_id1', 'doc_id2']
|
47
|
+
end
|
48
|
+
|
49
|
+
factory :content_folder_with_child_folders do
|
50
|
+
sequence(:folder_id) { |n| "id-content-folder-#{n}" }
|
51
|
+
label 'Root Label'
|
52
|
+
|
53
|
+
child_folders { build_list(:content_folder, 1, document_ids: ['child_doc_id']) }
|
54
|
+
end
|
55
|
+
|
56
|
+
factory :content_folder_with_document_ids, traits: [:document_ids]
|
57
|
+
end
|
40
58
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ContentFolder do
|
4
|
+
|
5
|
+
context 'fields' do
|
6
|
+
subject { FactoryGirl.build :content_folder }
|
7
|
+
|
8
|
+
let(:defined_fields) {
|
9
|
+
[:folder_id, :label, :document_ids, :child_folders]
|
10
|
+
}
|
11
|
+
it 'has all defined fields' do
|
12
|
+
defined_fields.each { |f| should respond_to(f) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'validation' do
|
17
|
+
subject { FactoryGirl.build :content_folder_with_document_ids }
|
18
|
+
let(:basic_subject) { FactoryGirl.build :content_folder }
|
19
|
+
let(:subject_with_folders) { FactoryGirl.build :content_folder_with_child_folders }
|
20
|
+
|
21
|
+
required_fields = [:folder_id, :label]
|
22
|
+
required_fields.each do |f|
|
23
|
+
it "validates #{f} is required" do
|
24
|
+
should be_valid
|
25
|
+
subject.send("#{f}=", nil)
|
26
|
+
should be_invalid "should be invalid if #{f} is missing"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'cannot have empty child_folders AND document_ids' do
|
31
|
+
basic_subject.should be_invalid
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is valid when document_ids are present' do
|
35
|
+
subject.should be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'is valid when child_folders are present' do
|
39
|
+
subject_with_folders.should be_valid
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'selectors' do
|
44
|
+
subject { FactoryGirl.build :content_folder_with_document_ids }
|
45
|
+
|
46
|
+
# TODO: add tests for known ids
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'db operations' do
|
50
|
+
let(:subject_with_folders) { FactoryGirl.build :content_folder_with_child_folders }
|
51
|
+
|
52
|
+
it 'saves and can be retrieved' do
|
53
|
+
id = subject_with_folders.folder_id
|
54
|
+
subject_with_folders.save
|
55
|
+
found = ContentFolder.find(id)
|
56
|
+
found.should_not be_nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'folder retrieval' do
|
61
|
+
before do
|
62
|
+
ContentFolder.delete_all
|
63
|
+
root = FactoryGirl.build :content_folder_with_document_ids
|
64
|
+
lit_center = FactoryGirl.build :content_folder_with_document_ids, :folder_id => ContentFolder::FolderIds::LIT_CENTER
|
65
|
+
merrill_lynch = FactoryGirl.build :content_folder_with_document_ids, :folder_id => ContentFolder::FolderIds::MERRILL_LYNCH
|
66
|
+
plan_529 = FactoryGirl.build :content_folder_with_document_ids, :folder_id => ContentFolder::FolderIds::PLANS_529
|
67
|
+
other = FactoryGirl.build :content_folder_with_document_ids, :folder_id => 'abcdefg'
|
68
|
+
root.child_folders = [lit_center, merrill_lynch, plan_529, other]
|
69
|
+
root.save
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should return the lit center folder' do
|
73
|
+
result = ContentFolder.lit_center_folder
|
74
|
+
result.should_not be_nil
|
75
|
+
result.folder_id.should == ContentFolder::FolderIds::LIT_CENTER
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should return the merrill lynch folder' do
|
79
|
+
result = ContentFolder.merrill_lynch_folder
|
80
|
+
result.should_not be_nil
|
81
|
+
result.folder_id.should == ContentFolder::FolderIds::MERRILL_LYNCH
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return the 529 folder' do
|
85
|
+
result = ContentFolder.plan_529_folder
|
86
|
+
result.should_not be_nil
|
87
|
+
result.folder_id.should == ContentFolder::FolderIds::PLANS_529
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should return nil for an unknown folder' do
|
91
|
+
result = ContentFolder.find_folder('zyxw')
|
92
|
+
result.should be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daengine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sbhatia
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -147,8 +147,10 @@ executables:
|
|
147
147
|
extensions: []
|
148
148
|
extra_rdoc_files: []
|
149
149
|
files:
|
150
|
+
- app/controllers/content_folder_controller.rb
|
150
151
|
- app/controllers/digital_assets_controller.rb
|
151
152
|
- app/helpers/digital_assets_helper.rb
|
153
|
+
- app/models/content_folder.rb
|
152
154
|
- app/models/content_service_resource.rb
|
153
155
|
- app/models/digital_asset.rb
|
154
156
|
- app/models/service_digital_asset.rb
|
@@ -177,6 +179,7 @@ files:
|
|
177
179
|
- Gemfile
|
178
180
|
- spec/factories.rb
|
179
181
|
- spec/spec_helper.rb
|
182
|
+
- spec/acceptance/content_folder_controller_spec.rb
|
180
183
|
- spec/acceptance/digital_assets_spec.rb
|
181
184
|
- spec/controllers/digital_assets_controller_spec.rb
|
182
185
|
- spec/dummy/config.ru
|
@@ -236,6 +239,7 @@ files:
|
|
236
239
|
- spec/mock_data/digitalAssets/TEST_FINRA_DOC.doc
|
237
240
|
- spec/mock_data/taxonomy/taxonomy.xml
|
238
241
|
- spec/mock_data/taxonomy/taxonomyengine.yml
|
242
|
+
- spec/models/content_folder_spec.rb
|
239
243
|
- spec/models/digital_asset_spec.rb
|
240
244
|
- spec/models/service_digital_asset_spec.rb
|
241
245
|
- spec/service/digital_asset_lookup_service_spec.rb
|
@@ -268,6 +272,7 @@ summary: Daengine GEM.
|
|
268
272
|
test_files:
|
269
273
|
- spec/factories.rb
|
270
274
|
- spec/spec_helper.rb
|
275
|
+
- spec/acceptance/content_folder_controller_spec.rb
|
271
276
|
- spec/acceptance/digital_assets_spec.rb
|
272
277
|
- spec/controllers/digital_assets_controller_spec.rb
|
273
278
|
- spec/dummy/config.ru
|
@@ -327,6 +332,7 @@ test_files:
|
|
327
332
|
- spec/mock_data/digitalAssets/TEST_FINRA_DOC.doc
|
328
333
|
- spec/mock_data/taxonomy/taxonomy.xml
|
329
334
|
- spec/mock_data/taxonomy/taxonomyengine.yml
|
335
|
+
- spec/models/content_folder_spec.rb
|
330
336
|
- spec/models/digital_asset_spec.rb
|
331
337
|
- spec/models/service_digital_asset_spec.rb
|
332
338
|
- spec/service/digital_asset_lookup_service_spec.rb
|