dm-filemaker-adapter 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +2 -2
- data/README.md +31 -11
- data/Rakefile +1 -1
- data/lib/dm-filemaker-adapter/adapter.rb +30 -26
- data/lib/dm-filemaker-adapter/core_patches.rb +50 -8
- data/lib/dm-filemaker-adapter/dm-fmresultset.yml +11 -14
- data/lib/dm-filemaker-adapter/version.rb +1 -1
- data/spec/data/resultset_with_duplicate_portals.xml +1099 -0
- data/spec/data/resultset_with_portals.xml +866 -0
- data/spec/dm-filemaker-adapter/adapter_spec.rb +104 -31
- data/spec/spec_helper.rb +59 -0
- metadata +6 -2
@@ -24,36 +24,12 @@ require 'spec_helper'
|
|
24
24
|
# end
|
25
25
|
|
26
26
|
describe DataMapper do
|
27
|
-
before :each do
|
28
|
-
DataMapper.setup(:default, 'filemaker://user:pass@hostname.com/DatabaseName')
|
29
|
-
class ::User
|
30
|
-
include DataMapper::Resource
|
31
|
-
property :id, Serial
|
32
|
-
property :email, String
|
33
|
-
property :username, String
|
34
|
-
property :activated_at, DateTime
|
35
|
-
|
36
|
-
has n, :orders
|
37
|
-
end
|
38
|
-
class ::Order
|
39
|
-
include DataMapper::Resource
|
40
|
-
property :id, Serial
|
41
|
-
property :total, Decimal
|
42
|
-
|
43
|
-
belongs_to :user
|
44
|
-
end
|
45
|
-
DataMapper.finalize
|
46
|
-
end
|
47
27
|
|
48
28
|
describe DataMapper::Adapters::FilemakerAdapter do
|
49
29
|
|
50
30
|
it 'Has a version number' do
|
51
31
|
expect(DataMapper::Adapters::FilemakerAdapter::VERSION).not_to be nil
|
52
32
|
end
|
53
|
-
|
54
|
-
it 'Does something useful' do
|
55
|
-
expect(true).to eq(true)
|
56
|
-
end
|
57
33
|
|
58
34
|
it 'Supports model classes' do
|
59
35
|
expect(User.ancestors.include?(DataMapper::Adapters::FilemakerAdapter::ResourceMethods)).to eq(true)
|
@@ -78,13 +54,77 @@ describe DataMapper do
|
|
78
54
|
end.and_return(Rfm::Resultset.allocate)
|
79
55
|
User.all(:id=>1).inspect
|
80
56
|
end
|
57
|
+
|
58
|
+
# Fix this to work with current relationships (not portals).
|
59
|
+
# it 'returns related datasets?' do
|
60
|
+
# # allow(User.layout).to receive(:find).and_return({
|
61
|
+
# # 'users'=>[{'id'=>100, 'email'=>'abc@def.com', 'username'=>'abc', 'activated_at'=>DateTime.now}],
|
62
|
+
# # 'orders'=>[{'user_id'=>100, 'total'=>123, 'id'=>999}]
|
63
|
+
# # })
|
64
|
+
# allow(User.layout).to receive(:find).and_return([
|
65
|
+
# {'id'=>100, 'email'=>'abc@def.com', 'username'=>'abc', 'activated_at'=>DateTime.now, :@orders=>[{'id'=>999, 'user_id'=>100, 'todal'=>123}] }
|
66
|
+
# ])
|
67
|
+
# user = User.get(100)
|
68
|
+
# puts "USER"
|
69
|
+
# puts user.inspect
|
70
|
+
# puts "USER-ORDERS"
|
71
|
+
# puts user.instance_variable_get(:@orders).inspect
|
72
|
+
# puts user.instance_variables.inspect
|
73
|
+
# end
|
74
|
+
|
81
75
|
end
|
82
76
|
|
83
77
|
describe '#create' do; it 'does something essential'; end
|
84
78
|
describe '#update' do; it 'does something essential'; end
|
85
79
|
describe '#delete' do; it 'does something essential'; end
|
86
80
|
describe '#layout' do; it 'does something essential'; end
|
87
|
-
|
81
|
+
|
82
|
+
describe '#prepare_fmp_attributes' do
|
83
|
+
before(:each) {allow_any_instance_of(Rfm::Layout).to receive(:find).and_return(Rfm::Resultset.allocate)}
|
84
|
+
before(:each) {@original_method = DataMapper.repository.adapter.method(:prepare_fmp_attributes)}
|
85
|
+
|
86
|
+
it 'Converts dm attributes to fmp attributes' do
|
87
|
+
expect(DataMapper.repository.adapter).to receive(:prepare_fmp_attributes) do |attributes, *args|
|
88
|
+
expect(attributes.keys.first.class).to eq(DataMapper::Property::String)
|
89
|
+
expect(@original_method.call(attributes, *args)).to eq({"email"=>"==abc@def.com"})
|
90
|
+
{"email"=>"==abc@def.com"}
|
91
|
+
end
|
92
|
+
User.all(:email=>'abc@def.com').inspect
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'Converts dm relationship object to fmp attributes' do
|
96
|
+
allow(User.layout).to receive(:find).and_return([{'id'=>100, 'email'=>'abc@def.com', 'username'=>'abc', 'activated_at'=>DateTime.now}])
|
97
|
+
user = User.get(100)
|
98
|
+
expect(DataMapper.repository.adapter).to receive(:prepare_fmp_attributes) do |attributes, *args|
|
99
|
+
expect((attributes.keys.first.class.name)[/Relationship/]).to eq('Relationship')
|
100
|
+
expect(attributes.keys.first.parent_key.first.class).to eq(DataMapper::Property::Serial)
|
101
|
+
#puts 'RAW ATTRIBUTES'
|
102
|
+
#puts attributes.class
|
103
|
+
#puts attributes.to_yaml
|
104
|
+
original_method_result = @original_method.call(attributes, *args)
|
105
|
+
expect(original_method_result).to eq({"user_id"=>"==100"})
|
106
|
+
#puts "PROCESSED ATTRIBUTES"
|
107
|
+
#puts original_method_result.to_yaml
|
108
|
+
original_method_result
|
109
|
+
end
|
110
|
+
|
111
|
+
user_orders = user.orders.inspect
|
112
|
+
#puts "USER ORDERS INSPECT"
|
113
|
+
#puts user_orders
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'Applies comparison logic to operand value' do
|
117
|
+
expect(DataMapper.repository.adapter).to receive(:prepare_fmp_attributes) do |attributes, *args|
|
118
|
+
expect((attributes.keys.first.class.name)[/DateTime/]).to eq('DateTime')
|
119
|
+
expect((args.first.values.first)).to eq('>')
|
120
|
+
original_method_result = @original_method.call(attributes, *args)
|
121
|
+
expect(original_method_result.values.first[0] == '>').to eq(true)
|
122
|
+
original_method_result
|
123
|
+
end
|
124
|
+
User.all(:activated_at.gt=>DateTime.now).inspect
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
88
128
|
describe '#merge_fmp_response' do; it 'does something essential'; end
|
89
129
|
|
90
130
|
end # datamapper-adapters-filemaker
|
@@ -187,11 +227,44 @@ describe DataMapper do
|
|
187
227
|
end
|
188
228
|
end
|
189
229
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
230
|
+
# This is now obsolete. Redo these specs to handle Model#load monkey-patching.
|
231
|
+
# describe DataMapper::Model do
|
232
|
+
# describe '#finalize' do
|
233
|
+
# it 'Adds properties for :_record_id, :_mod_id to resource' do
|
234
|
+
# allow(User.layout).to receive(:find).and_return([{'id'=>100, 'email'=>'abc@def.com', 'username'=>'abc', 'activated_at'=>DateTime.now}])
|
235
|
+
# user = User.get(100)
|
236
|
+
# expect(user._record_id).to eq('something')
|
237
|
+
# expect(user._mod_id).to eq('something')
|
238
|
+
# end
|
239
|
+
#
|
240
|
+
# it 'Calls original #finalize method'
|
241
|
+
# end
|
242
|
+
# end
|
196
243
|
|
197
244
|
end # datamapper
|
245
|
+
|
246
|
+
|
247
|
+
describe Rfm::Resultset do
|
248
|
+
describe '#map' do
|
249
|
+
it 'Adds properties for :_record_id, :_mod_id to resource' do
|
250
|
+
expect_any_instance_of(Rfm::Connection).to receive(:http_fetch).and_return(RESULT_SET_WITH_PORTALS)
|
251
|
+
project = Project.first
|
252
|
+
expect(project.instance_variable_get(:@_record_id)).to eq('499')
|
253
|
+
expect(project.instance_variable_get(:@_mod_id)).to eq('86')
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'Adds properties for :_record_id, :_mod_id to nested (portal) resource' do
|
257
|
+
expect_any_instance_of(Rfm::Connection).to receive(:http_fetch).and_return(RESULT_SET_WITH_PORTALS)
|
258
|
+
project = Project.first
|
259
|
+
#puts project.items.inspect
|
260
|
+
#puts Project.instance_variable_get(:@record).inspect
|
261
|
+
expect(project.items[1].instance_variable_get(:@_record_id)).to eq('2470')
|
262
|
+
expect(project.items[1].instance_variable_get(:@_mod_id)).to eq('137')
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,61 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
require 'dm-filemaker-adapter'
|
3
|
+
|
4
|
+
DB_CONFIG = {
|
5
|
+
adapter: 'filemaker',
|
6
|
+
host: 'my.host.com',
|
7
|
+
account_name: 'developer',
|
8
|
+
password: '12345',
|
9
|
+
database: 'my_database',
|
10
|
+
ssl: 'true',
|
11
|
+
port: 443,
|
12
|
+
root_cert: false,
|
13
|
+
log_actions: false,
|
14
|
+
log_responses: false,
|
15
|
+
log_parser: false
|
16
|
+
}
|
17
|
+
|
18
|
+
RESULT_SET_WITH_PORTALS = File.read(File.expand_path('../data/resultset_with_portals.xml', __FILE__)).tap do |dat|
|
19
|
+
dat.define_singleton_method(:body){self}
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
DataMapper.setup(:default, DB_CONFIG)
|
24
|
+
|
25
|
+
class User
|
26
|
+
include DataMapper::Resource
|
27
|
+
property :id, Serial
|
28
|
+
property :email, String
|
29
|
+
property :username, String
|
30
|
+
property :activated_at, DateTime
|
31
|
+
|
32
|
+
has n, :orders
|
33
|
+
end
|
34
|
+
|
35
|
+
class Order
|
36
|
+
include DataMapper::Resource
|
37
|
+
property :id, Serial
|
38
|
+
property :total, Decimal
|
39
|
+
property :user_id, Integer
|
40
|
+
|
41
|
+
belongs_to :user
|
42
|
+
end
|
43
|
+
|
44
|
+
class Project
|
45
|
+
include DataMapper::Resource
|
46
|
+
storage_names[:default] = 'Project Data Entry New'
|
47
|
+
property :id, String, :key=>true, :field=>'ClientPO'
|
48
|
+
|
49
|
+
has n, :items
|
50
|
+
end
|
51
|
+
|
52
|
+
class Item
|
53
|
+
include DataMapper::Resource
|
54
|
+
storage_names[:default] = 'projectlineitems'
|
55
|
+
property :id, String, :key=>true, :field=>'ItemNumber'
|
56
|
+
property :project_id, String
|
57
|
+
|
58
|
+
belongs_to :project
|
59
|
+
end
|
60
|
+
|
61
|
+
DataMapper.finalize
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-filemaker-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Richardson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: data_mapper
|
@@ -99,6 +99,8 @@ files:
|
|
99
99
|
- lib/dm-filemaker-adapter/core_patches.rb
|
100
100
|
- lib/dm-filemaker-adapter/dm-fmresultset.yml
|
101
101
|
- lib/dm-filemaker-adapter/version.rb
|
102
|
+
- spec/data/resultset_with_duplicate_portals.xml
|
103
|
+
- spec/data/resultset_with_portals.xml
|
102
104
|
- spec/dm-filemaker-adapter/adapter_spec.rb
|
103
105
|
- spec/spec_helper.rb
|
104
106
|
homepage: ''
|
@@ -126,5 +128,7 @@ signing_key:
|
|
126
128
|
specification_version: 4
|
127
129
|
summary: Filemaker adapter for DataMapper
|
128
130
|
test_files:
|
131
|
+
- spec/data/resultset_with_duplicate_portals.xml
|
132
|
+
- spec/data/resultset_with_portals.xml
|
129
133
|
- spec/dm-filemaker-adapter/adapter_spec.rb
|
130
134
|
- spec/spec_helper.rb
|