task_helper 0.0.2 → 0.0.3
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/lib/task_helper/record.rb +6 -0
- data/lib/task_helper/version.rb +1 -1
- data/spec/lib/task_helper/record_spec.rb +15 -0
- data/spec/support/fake_mth.rb +25 -0
- data/spec/support/fixture_parser.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c59dfe71a9f1b81bd73a2a40f21a56a493f4eb
|
4
|
+
data.tar.gz: 78b39cbecd5425f38f7e679654b72217f87c1d8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 291b59c10fb4f99b7c18ad9fdedba1b87d62d8343e587fd1cfcf74a1cf42f9ab3e3a1dbcc02f0c30e9199b6f46e9b7dcbca0619f8a7cb48de9101fc4e57f48eb
|
7
|
+
data.tar.gz: 0cab071c5e705e6355513f08ac99865f6e784eed77137cf8b3056add007b534a935754f0d9e69dffabca7e17e2f2ca217c0958b1c9ff21ce10e7fa556664f11a
|
data/lib/task_helper/record.rb
CHANGED
@@ -2,6 +2,12 @@ module TaskHelper
|
|
2
2
|
class Record < Base
|
3
3
|
data_member :app_id, :entity_id, :approved, :values
|
4
4
|
|
5
|
+
def self.find(id, database_id:)
|
6
|
+
if response = get(route: "apps/#{database_id}/dtypes/#{id}.json")
|
7
|
+
new response['record'] if response['record']
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def initialize(args = {}, form: nil, **params)
|
6
12
|
@form = form
|
7
13
|
super(args.merge(params))
|
data/lib/task_helper/version.rb
CHANGED
@@ -6,6 +6,21 @@ describe TaskHelper::Record do
|
|
6
6
|
let(:data) { FixtureParser.pretty(:records, form.id, form.app_id).sample }
|
7
7
|
subject { described_class.new(data.to_h) }
|
8
8
|
|
9
|
+
describe '::find' do
|
10
|
+
it 'should find the record with the given ID' do
|
11
|
+
record = form.records.first
|
12
|
+
expect(described_class.find(record.id, database_id: form.app_id))
|
13
|
+
.to eq(record)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'database or record not found' do
|
17
|
+
it 'should return nil' do
|
18
|
+
expect(described_class.find('foobar', database_id: 'barfoo')).to be_nil
|
19
|
+
expect(described_class.find('foobar', database_id: form.app_id)).to be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
9
24
|
describe '.new' do
|
10
25
|
it 'should pass all params except form to super' do
|
11
26
|
form = TaskHelper::Form.all.first
|
data/spec/support/fake_mth.rb
CHANGED
@@ -4,11 +4,15 @@ class FakeMTH < Sinatra::Base
|
|
4
4
|
get '/apps/search.json' do
|
5
5
|
search = string_params
|
6
6
|
result = databases.find { |d| d.merge(search) == d }
|
7
|
+
content_type :json
|
8
|
+
status 200
|
7
9
|
{ 'database' => result }.to_json if result
|
8
10
|
end
|
9
11
|
|
10
12
|
get '/apps/:id.json' do
|
11
13
|
result = databases.find { |d| d['id'] == params[:id] }
|
14
|
+
content_type :json
|
15
|
+
status 200
|
12
16
|
{ 'database' => result }.to_json if result
|
13
17
|
end
|
14
18
|
|
@@ -17,6 +21,8 @@ class FakeMTH < Sinatra::Base
|
|
17
21
|
end
|
18
22
|
|
19
23
|
get '/apps/search/entities/search.json' do
|
24
|
+
content_type :json
|
25
|
+
status 200
|
20
26
|
if db = databases.find { |d| d['name'] == params[:database_name] }
|
21
27
|
result = forms(db['id']).find { |f| f['name'] == params[:form_name] }
|
22
28
|
{ 'form' => result }.to_json if result
|
@@ -25,11 +31,15 @@ class FakeMTH < Sinatra::Base
|
|
25
31
|
|
26
32
|
get '/apps/:db_id/entities/:form_id.json' do
|
27
33
|
result = forms(params[:db_id]).find { |f| f['id'] == params[:form_id] }
|
34
|
+
content_type :json
|
35
|
+
status 200
|
28
36
|
{ 'form' => result }.to_json if result
|
29
37
|
end
|
30
38
|
|
31
39
|
get '/apps/:db_id/entities.json' do
|
32
40
|
result = forms(params[:db_id])
|
41
|
+
content_type :json
|
42
|
+
status 200
|
33
43
|
{ 'forms' => result }.to_json if result
|
34
44
|
end
|
35
45
|
|
@@ -40,6 +50,21 @@ class FakeMTH < Sinatra::Base
|
|
40
50
|
{ 'fields' => result }.to_json if result
|
41
51
|
end
|
42
52
|
|
53
|
+
get '/apps/:db_id/dtypes/:id.json' do
|
54
|
+
forms = FixtureParser.forms(params[:db_id])
|
55
|
+
record = nil
|
56
|
+
forms.each do |form|
|
57
|
+
records = (1...Float::INFINITY).lazy
|
58
|
+
.map { |n| FixtureParser.records(form['id'], form['app_id'], n) }
|
59
|
+
.take_while { |r| !r.nil? }
|
60
|
+
.flat_map { |r| r }
|
61
|
+
break if (record = records.find { |r| r['id'] == params[:id] })
|
62
|
+
end
|
63
|
+
content_type :json
|
64
|
+
status 200
|
65
|
+
{ 'record' => record }.to_json if record
|
66
|
+
end
|
67
|
+
|
43
68
|
get '/apps/:db_id/dtypes/entity/:form_id.json' do
|
44
69
|
json_response(200, "databases/#{params[:db_id]}/forms/" \
|
45
70
|
"#{params[:form_id]}/records/#{params[:page]}")
|
@@ -61,7 +61,11 @@ module FixtureParser
|
|
61
61
|
module_function
|
62
62
|
|
63
63
|
def parse_file(file_name)
|
64
|
-
|
65
|
-
|
64
|
+
full_name = "#{File.dirname(__FILE__)}/fixtures/#{file_name}.json"
|
65
|
+
if File.exist?(full_name)
|
66
|
+
JSON.parse(File.open(full_name).read)
|
67
|
+
else
|
68
|
+
{}
|
69
|
+
end
|
66
70
|
end
|
67
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: task_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JC Wilcox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|