filemaker 0.0.1 → 0.0.2
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/README.md +129 -17
- data/filemaker.gemspec +1 -0
- data/lib/filemaker.rb +47 -0
- data/lib/filemaker/api/query_commands/findquery.rb +20 -3
- data/lib/filemaker/configuration.rb +1 -1
- data/lib/filemaker/core_ext/hash.rb +19 -15
- data/lib/filemaker/error.rb +5 -0
- data/lib/filemaker/metadata/field.rb +21 -5
- data/lib/filemaker/model.rb +132 -0
- data/lib/filemaker/model/builder.rb +52 -0
- data/lib/filemaker/model/components.rb +25 -0
- data/lib/filemaker/model/criteria.rb +101 -0
- data/lib/filemaker/model/field.rb +38 -0
- data/lib/filemaker/model/fields.rb +80 -0
- data/lib/filemaker/model/findable.rb +35 -0
- data/lib/filemaker/model/optional.rb +69 -0
- data/lib/filemaker/model/pagination.rb +41 -0
- data/lib/filemaker/model/persistable.rb +96 -0
- data/lib/filemaker/model/relations.rb +72 -0
- data/lib/filemaker/model/relations/belongs_to.rb +30 -0
- data/lib/filemaker/model/relations/has_many.rb +79 -0
- data/lib/filemaker/model/relations/proxy.rb +35 -0
- data/lib/filemaker/model/selectable.rb +146 -0
- data/lib/filemaker/railtie.rb +17 -0
- data/lib/filemaker/record.rb +25 -0
- data/lib/filemaker/resultset.rb +12 -4
- data/lib/filemaker/server.rb +7 -5
- data/lib/filemaker/version.rb +1 -1
- data/spec/filemaker/api/query_commands/compound_find_spec.rb +13 -1
- data/spec/filemaker/configuration_spec.rb +23 -0
- data/spec/filemaker/layout_spec.rb +0 -1
- data/spec/filemaker/model/criteria_spec.rb +304 -0
- data/spec/filemaker/model/relations_spec.rb +85 -0
- data/spec/filemaker/model_spec.rb +73 -0
- data/spec/filemaker/record_spec.rb +12 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/filemaker.yml +13 -0
- data/spec/support/models.rb +38 -0
- metadata +44 -2
@@ -0,0 +1,85 @@
|
|
1
|
+
describe Filemaker::Model::Relations do
|
2
|
+
|
3
|
+
it 'every model has a relations hash' do
|
4
|
+
expect(MyModel.new.relations).to eq({})
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'belongs_to' do
|
8
|
+
context 'when using default reference_key' do
|
9
|
+
before do
|
10
|
+
@model = MyModel.new(candidate_id: '123')
|
11
|
+
allow(Candidate).to receive(:where).and_return([Candidate.new])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'appends _id to missing reference_key' do
|
15
|
+
expect(@model.candidate.reference_key).to eq 'candidate_id'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'target class should be Candidate' do
|
19
|
+
expect(@model.candidate.target_class).to eq Candidate
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'owner belongs to MyModel' do
|
23
|
+
expect(@model.candidate.owner).to eq @model
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'relations hash will be populated' do
|
27
|
+
@model.candidate
|
28
|
+
expect(@model.relations.fetch('candidate')).to eq \
|
29
|
+
@model.candidate.target
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when using supplied reference_key' do
|
34
|
+
before do
|
35
|
+
@model = MyModel.new(name: 'ABC')
|
36
|
+
allow(User).to receive(:where).and_return([User.new])
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'will use the supplied class_name' do
|
40
|
+
expect(@model.applicant.target_class).to eq User
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'will use the supplied reference_key' do
|
44
|
+
expect(@model.applicant.reference_key).to eq :name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'has_many' do
|
50
|
+
before do
|
51
|
+
@model = MyModel.new(candidate_id: '123')
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when using default reference_key' do
|
55
|
+
it 'will use owner identity name' do
|
56
|
+
expect(@model.posts.reference_key).to eq :candidate_id
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'target class should be Post' do
|
60
|
+
expect(@model.posts.target_class).to eq Post
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'owner belongs to MyModel' do
|
64
|
+
expect(@model.posts.owner).to eq @model
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns criteria instead of an array of model objects' do
|
68
|
+
expect(@model.posts).to be_a Filemaker::Model::Criteria
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when using supplied reference_key' do
|
73
|
+
it 'will use supplied class_name' do
|
74
|
+
expect(@model.posters.target_class).to eq User
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'will use the supplied reference_key' do
|
78
|
+
expect(@model.posters.reference_key).to eq :email
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'has_portal' do
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
describe Filemaker::Model do
|
2
|
+
|
3
|
+
let(:model) { MyModel.new }
|
4
|
+
|
5
|
+
it 'sets up -db and -lay' do
|
6
|
+
expect(MyModel.db).to eq :candidates
|
7
|
+
expect(MyModel.lay).to eq :profile
|
8
|
+
expect(model.db).to eq :candidates
|
9
|
+
expect(model.lay).to eq :profile
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sets up server and api' do
|
13
|
+
expect(MyModel.api.default_params).to eq \
|
14
|
+
({ '-db' => :candidates, '-lay' => :profile })
|
15
|
+
expect(MyModel.server.host).to eq 'host'
|
16
|
+
expect(model.api.default_params).to eq \
|
17
|
+
({ '-db' => :candidates, '-lay' => :profile })
|
18
|
+
expect(model.server.host).to eq 'host'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is a new record' do
|
22
|
+
expect(model.new_record).to be true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has identity' do
|
26
|
+
model.candidate_id = 'CA123'
|
27
|
+
expect(model.id).to eq 'CA123'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'name and email default to UNTITLED' do
|
31
|
+
expect(model.name).to eq 'UNTITLED'
|
32
|
+
expect(model.email).to eq 'UNTITLED'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'stores the real FileMaker name under fm_name' do
|
36
|
+
expect(model.fm_names).to eq \
|
37
|
+
[
|
38
|
+
'name',
|
39
|
+
'email',
|
40
|
+
'ca id',
|
41
|
+
'created_at',
|
42
|
+
'modifieddate',
|
43
|
+
'salary',
|
44
|
+
'passage of time'
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'salary is BigDecimal' do
|
49
|
+
model.salary = 100
|
50
|
+
expect(model.salary).to be_a BigDecimal
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'created_at is Date' do
|
54
|
+
model.created_at = '4/12/2014'
|
55
|
+
expect(model.created_at).to be_a Date
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'check for presence of name and salary' do
|
59
|
+
expect(model.name?).to be true
|
60
|
+
expect(model.salary?).to be false
|
61
|
+
model.salary = 100
|
62
|
+
expect(model.salary?).to be true
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'process_attributes' do
|
66
|
+
it 'accepts a hash of attributes' do
|
67
|
+
model = MyModel.new(name: 'Bob', email: 'bob@cern.org')
|
68
|
+
expect(model.name).to eq 'Bob'
|
69
|
+
expect(model.email).to eq 'bob@cern.org'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -40,8 +40,19 @@ describe Filemaker::Record do
|
|
40
40
|
|
41
41
|
it 'has 2 portals' do
|
42
42
|
expect(@record.portals.size).to eq 2
|
43
|
-
# Test for case
|
43
|
+
# Test for case insensitive hash!
|
44
44
|
expect(@record.portals[:PORTAL_1]).to eq @record.portals['portal_1']
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'key access as plain method' do
|
48
|
+
expect(@record.portalid).to eq '1234'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'dirty checking' do
|
52
|
+
it 'tracks changes if you modify any value' do
|
53
|
+
@record.year = 2014
|
54
|
+
expect(@record.dirty).to eq({ 'year' => 2014 })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
47
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
development:
|
2
|
+
default:
|
3
|
+
host: host.com
|
4
|
+
account_name: FILEMAKER_ACCOUNT_NAME
|
5
|
+
password: FILEMAKER_PASSWORD
|
6
|
+
ssl: { verify: false }
|
7
|
+
log: :curl
|
8
|
+
|
9
|
+
read_slave:
|
10
|
+
host: host.com
|
11
|
+
account_name: FILEMAKER_ACCOUNT_NAME
|
12
|
+
password: FILEMAKER_PASSWORD
|
13
|
+
ssl: true
|
@@ -0,0 +1,38 @@
|
|
1
|
+
Filemaker.registry['default'] = Filemaker::Server.new do |config|
|
2
|
+
config.host = 'host'
|
3
|
+
config.account_name = 'account_name'
|
4
|
+
config.password = 'password'
|
5
|
+
end
|
6
|
+
|
7
|
+
class Candidate
|
8
|
+
include Filemaker::Model
|
9
|
+
end
|
10
|
+
|
11
|
+
class User
|
12
|
+
include Filemaker::Model
|
13
|
+
end
|
14
|
+
|
15
|
+
class Post
|
16
|
+
include Filemaker::Model
|
17
|
+
|
18
|
+
string :candidate_id, :email
|
19
|
+
end
|
20
|
+
|
21
|
+
class MyModel
|
22
|
+
include Filemaker::Model
|
23
|
+
|
24
|
+
database :candidates
|
25
|
+
layout :profile
|
26
|
+
|
27
|
+
string :name, :email, default: 'UNTITLED'
|
28
|
+
string :candidate_id, fm_name: 'CA ID', identity: true
|
29
|
+
date :created_at
|
30
|
+
datetime :updated_at, fm_name: 'ModifiedDate'
|
31
|
+
money :salary
|
32
|
+
integer :age, fm_name: 'passage of time'
|
33
|
+
|
34
|
+
belongs_to :candidate
|
35
|
+
belongs_to :applicant, class_name: User, reference_key: :name
|
36
|
+
has_many :posts
|
37
|
+
has_many :posters, class_name: User, reference_key: :email
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filemaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activemodel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,6 +170,22 @@ files:
|
|
156
170
|
- lib/filemaker/error.rb
|
157
171
|
- lib/filemaker/layout.rb
|
158
172
|
- lib/filemaker/metadata/field.rb
|
173
|
+
- lib/filemaker/model.rb
|
174
|
+
- lib/filemaker/model/builder.rb
|
175
|
+
- lib/filemaker/model/components.rb
|
176
|
+
- lib/filemaker/model/criteria.rb
|
177
|
+
- lib/filemaker/model/field.rb
|
178
|
+
- lib/filemaker/model/fields.rb
|
179
|
+
- lib/filemaker/model/findable.rb
|
180
|
+
- lib/filemaker/model/optional.rb
|
181
|
+
- lib/filemaker/model/pagination.rb
|
182
|
+
- lib/filemaker/model/persistable.rb
|
183
|
+
- lib/filemaker/model/relations.rb
|
184
|
+
- lib/filemaker/model/relations/belongs_to.rb
|
185
|
+
- lib/filemaker/model/relations/has_many.rb
|
186
|
+
- lib/filemaker/model/relations/proxy.rb
|
187
|
+
- lib/filemaker/model/selectable.rb
|
188
|
+
- lib/filemaker/railtie.rb
|
159
189
|
- lib/filemaker/record.rb
|
160
190
|
- lib/filemaker/resultset.rb
|
161
191
|
- lib/filemaker/script.rb
|
@@ -165,9 +195,13 @@ files:
|
|
165
195
|
- lib/filemaker/store/script_store.rb
|
166
196
|
- lib/filemaker/version.rb
|
167
197
|
- spec/filemaker/api/query_commands/compound_find_spec.rb
|
198
|
+
- spec/filemaker/configuration_spec.rb
|
168
199
|
- spec/filemaker/error_spec.rb
|
169
200
|
- spec/filemaker/layout_spec.rb
|
170
201
|
- spec/filemaker/metadata/field_spec.rb
|
202
|
+
- spec/filemaker/model/criteria_spec.rb
|
203
|
+
- spec/filemaker/model/relations_spec.rb
|
204
|
+
- spec/filemaker/model_spec.rb
|
171
205
|
- spec/filemaker/record_spec.rb
|
172
206
|
- spec/filemaker/resultset_spec.rb
|
173
207
|
- spec/filemaker/server_spec.rb
|
@@ -175,6 +209,8 @@ files:
|
|
175
209
|
- spec/filemaker/store/layout_store_spec.rb
|
176
210
|
- spec/filemaker/store/script_store_spec.rb
|
177
211
|
- spec/spec_helper.rb
|
212
|
+
- spec/support/filemaker.yml
|
213
|
+
- spec/support/models.rb
|
178
214
|
- spec/support/responses/dbnames.xml
|
179
215
|
- spec/support/responses/employment.xml
|
180
216
|
- spec/support/responses/jobs.xml
|
@@ -208,9 +244,13 @@ specification_version: 4
|
|
208
244
|
summary: A Ruby wrapper to FileMaker XML API.
|
209
245
|
test_files:
|
210
246
|
- spec/filemaker/api/query_commands/compound_find_spec.rb
|
247
|
+
- spec/filemaker/configuration_spec.rb
|
211
248
|
- spec/filemaker/error_spec.rb
|
212
249
|
- spec/filemaker/layout_spec.rb
|
213
250
|
- spec/filemaker/metadata/field_spec.rb
|
251
|
+
- spec/filemaker/model/criteria_spec.rb
|
252
|
+
- spec/filemaker/model/relations_spec.rb
|
253
|
+
- spec/filemaker/model_spec.rb
|
214
254
|
- spec/filemaker/record_spec.rb
|
215
255
|
- spec/filemaker/resultset_spec.rb
|
216
256
|
- spec/filemaker/server_spec.rb
|
@@ -218,6 +258,8 @@ test_files:
|
|
218
258
|
- spec/filemaker/store/layout_store_spec.rb
|
219
259
|
- spec/filemaker/store/script_store_spec.rb
|
220
260
|
- spec/spec_helper.rb
|
261
|
+
- spec/support/filemaker.yml
|
262
|
+
- spec/support/models.rb
|
221
263
|
- spec/support/responses/dbnames.xml
|
222
264
|
- spec/support/responses/employment.xml
|
223
265
|
- spec/support/responses/jobs.xml
|