filemaker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +17 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +116 -0
  9. data/Rakefile +6 -0
  10. data/diagram.png +0 -0
  11. data/filemaker.gemspec +30 -0
  12. data/lib/filemaker.rb +13 -0
  13. data/lib/filemaker/api.rb +13 -0
  14. data/lib/filemaker/api/query_commands/delete.rb +16 -0
  15. data/lib/filemaker/api/query_commands/dup.rb +22 -0
  16. data/lib/filemaker/api/query_commands/edit.rb +26 -0
  17. data/lib/filemaker/api/query_commands/find.rb +46 -0
  18. data/lib/filemaker/api/query_commands/findall.rb +34 -0
  19. data/lib/filemaker/api/query_commands/findany.rb +26 -0
  20. data/lib/filemaker/api/query_commands/findquery.rb +84 -0
  21. data/lib/filemaker/api/query_commands/new.rb +21 -0
  22. data/lib/filemaker/api/query_commands/view.rb +11 -0
  23. data/lib/filemaker/configuration.rb +28 -0
  24. data/lib/filemaker/core_ext/hash.rb +32 -0
  25. data/lib/filemaker/database.rb +29 -0
  26. data/lib/filemaker/error.rb +391 -0
  27. data/lib/filemaker/layout.rb +38 -0
  28. data/lib/filemaker/metadata/field.rb +71 -0
  29. data/lib/filemaker/record.rb +64 -0
  30. data/lib/filemaker/resultset.rb +124 -0
  31. data/lib/filemaker/script.rb +9 -0
  32. data/lib/filemaker/server.rb +197 -0
  33. data/lib/filemaker/store/database_store.rb +21 -0
  34. data/lib/filemaker/store/layout_store.rb +23 -0
  35. data/lib/filemaker/store/script_store.rb +23 -0
  36. data/lib/filemaker/version.rb +3 -0
  37. data/spec/filemaker/api/query_commands/compound_find_spec.rb +69 -0
  38. data/spec/filemaker/error_spec.rb +257 -0
  39. data/spec/filemaker/layout_spec.rb +229 -0
  40. data/spec/filemaker/metadata/field_spec.rb +62 -0
  41. data/spec/filemaker/record_spec.rb +47 -0
  42. data/spec/filemaker/resultset_spec.rb +65 -0
  43. data/spec/filemaker/server_spec.rb +106 -0
  44. data/spec/filemaker/store/database_store_spec.rb +34 -0
  45. data/spec/filemaker/store/layout_store_spec.rb +31 -0
  46. data/spec/filemaker/store/script_store_spec.rb +31 -0
  47. data/spec/spec_helper.rb +84 -0
  48. data/spec/support/responses/dbnames.xml +34 -0
  49. data/spec/support/responses/employment.xml +55 -0
  50. data/spec/support/responses/jobs.xml +199 -0
  51. data/spec/support/responses/layoutnames.xml +39 -0
  52. data/spec/support/responses/portal.xml +108 -0
  53. data/spec/support/responses/scriptnames.xml +29 -0
  54. data/spec/support/xml_loader.rb +29 -0
  55. metadata +227 -0
@@ -0,0 +1,62 @@
1
+ describe Filemaker::Metadata::Field do
2
+ let(:server) do
3
+ Filemaker::Server.new do |config|
4
+ config.host = 'https://host'
5
+ config.account_name = 'account_name'
6
+ config.password = 'password'
7
+ end
8
+ end
9
+ let(:xml) { import_xml_as_string('portal.xml') }
10
+ let(:resultset) { Filemaker::Resultset.new(server, xml) }
11
+ let(:field) { Filemaker::Metadata::Field.new({}, resultset) }
12
+
13
+ context 'coercion' do
14
+ it 'converts to nil for empty string' do
15
+ allow(field).to receive(:data_type).and_return 'text'
16
+ expect(field.coerce('')).to be_nil
17
+ end
18
+
19
+ it 'converts to nil for space string' do
20
+ allow(field).to receive(:data_type).and_return 'text'
21
+ expect(field.coerce(' ')).to be_nil
22
+ end
23
+
24
+ it 'converts to nil for nil' do
25
+ allow(field).to receive(:data_type).and_return 'text'
26
+ expect(field.coerce(nil)).to be_nil
27
+ end
28
+
29
+ it 'converts text to String' do
30
+ allow(field).to receive(:data_type).and_return 'text'
31
+ expect(field.coerce('some text value')).to be_a String
32
+ end
33
+
34
+ it 'converts number to BigDecimal' do
35
+ allow(field).to receive(:data_type).and_return 'number'
36
+ expect(field.coerce('100')).to be_a BigDecimal
37
+ end
38
+
39
+ it 'converts date to Date' do
40
+ allow(field).to receive(:data_type).and_return 'date'
41
+ expect(field.coerce('10/31/2014')).to be_a Date
42
+ end
43
+
44
+ it 'converts time to DateTime' do
45
+ allow(field).to receive(:data_type).and_return 'time'
46
+ expect(field.coerce('12:12:12')).to be_a DateTime
47
+ end
48
+
49
+ it 'converts timestamp to DateTime' do
50
+ allow(field).to receive(:data_type).and_return 'timestamp'
51
+ expect(field.coerce('10/31/2014 12:12:12')).to be_a DateTime
52
+ end
53
+
54
+ it 'converts container to URI' do
55
+ allow(field).to receive(:data_type).and_return 'container'
56
+ expect(field.coerce('/fmi/xml/cnt/1234jpg')).to be_a URI
57
+ expect(field.coerce('/fmi/xml/cnt/1234jpg').to_s).to eq \
58
+ 'https://host/fmi/xml/cnt/1234jpg'
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,47 @@
1
+ describe Filemaker::Record do
2
+ before do
3
+ server = Filemaker::Server.new do |config|
4
+ config.host = 'http://host'
5
+ config.account_name = 'account_name'
6
+ config.password = 'password'
7
+ end
8
+
9
+ xml = import_xml_as_string('portal.xml')
10
+ resultset = Filemaker::Resultset.new(server, xml)
11
+ records = Nokogiri::XML(xml).remove_namespaces!.xpath('/fmresultset/resultset/record')
12
+ @record = Filemaker::Record.new(records.first, resultset)
13
+ end
14
+
15
+ it 'acts as a Hash' do
16
+ expect(@record).to be_a Hash
17
+ end
18
+
19
+ it 'records mod-id and record-id' do
20
+ expect(@record.mod_id).to eq 'mod-id-1'
21
+ expect(@record.record_id).to eq 'record-id-1'
22
+ end
23
+
24
+ it 'has 5 fields' do
25
+ expect(@record.size).to eq 5
26
+ end
27
+
28
+ it 'empty <data/> should be nil' do
29
+ expect(@record['Insurance Amount']).to be_nil
30
+ end
31
+
32
+ it 'text should be String' do
33
+ expect(@record['PortalID']).to eq '1234'
34
+ end
35
+
36
+ it 'Salary should be an array of BigDecimal' do
37
+ expect(@record['Salary']).to be_an Array
38
+ expect(@record['SALARY']).to eq [BigDecimal.new(5000), BigDecimal.new(6000)]
39
+ end
40
+
41
+ it 'has 2 portals' do
42
+ expect(@record.portals.size).to eq 2
43
+ # Test for case insentive hash!
44
+ expect(@record.portals[:PORTAL_1]).to eq @record.portals['portal_1']
45
+ end
46
+
47
+ end
@@ -0,0 +1,65 @@
1
+ describe Filemaker::Resultset do
2
+ let(:server) do
3
+ Filemaker::Server.new do |config|
4
+ config.host = 'http://host'
5
+ config.account_name = 'account_name'
6
+ config.password = 'password'
7
+ end
8
+ end
9
+ let(:xml) { import_xml_as_string('portal.xml') }
10
+ let(:resultset) { Filemaker::Resultset.new(server, xml) }
11
+
12
+ it 'has an internal array to hold on to records' do
13
+ expect(resultset.list).to be_an Array
14
+ end
15
+
16
+ context 'parse XML record' do
17
+ it 'assigns count' do
18
+ expect(resultset.count).to eq 2
19
+ end
20
+
21
+ it 'assigns total_count' do
22
+ expect(resultset.total_count).to eq 5000
23
+ end
24
+
25
+ it 'date-format is %m/%d/%Y for MM/dd/yyyy' do
26
+ expect(resultset.date_format).to eq '%m/%d/%Y'
27
+ end
28
+
29
+ it 'time-format is %H:%M:%S for HH:mm::ss' do
30
+ expect(resultset.time_format).to eq '%H:%M:%S'
31
+ end
32
+
33
+ it 'timestamp-format is %m/%d/%Y %H:%M:%S for MM/dd/yyyy HH:mm::ss' do
34
+ expect(resultset.timestamp_format).to eq '%m/%d/%Y %H:%M:%S'
35
+ end
36
+ end
37
+
38
+ describe 'build metadata' do
39
+ it 'has 5 fields' do
40
+ expect(resultset.fields.size).to eq 5
41
+ expect(resultset.fields.keys).to eq \
42
+ ['PortalID', 'Year', 'Salary', 'Insurance Amount', 'Document']
43
+ end
44
+
45
+ it 'PortalID represented as Field object' do
46
+ expect(resultset.fields['PortalID'].name).to eq 'PortalID'
47
+ expect(resultset.fields['PortalID'].data_type).to eq 'text'
48
+ expect(resultset.fields['PortalID'].field_type).to eq 'normal'
49
+ expect(resultset.fields['PortalID'].global).to eq false
50
+ expect(resultset.fields['PortalID'].repeats).to eq 1
51
+ expect(resultset.fields['PortalID'].required).to eq true
52
+ end
53
+
54
+ it 'has 2 portals' do
55
+ expect(resultset.portal_fields.size).to eq 2
56
+ end
57
+ end
58
+
59
+ describe 'build records' do
60
+ it 'has 2 records' do
61
+ expect(resultset.list.size).to eq 2
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,106 @@
1
+ describe Filemaker::Server do
2
+
3
+ context 'initializing a server' do
4
+ it 'provides a host, account_name, and password' do
5
+ server = Filemaker::Server.new do |config|
6
+ config.host = 'host'
7
+ config.account_name = 'account_name'
8
+ config.password = 'password'
9
+ end
10
+
11
+ expect(server.host).to eq 'host'
12
+ expect(server.url).to eq 'http://host'
13
+ expect(server.account_name).to eq 'account_name'
14
+ expect(server.password).to eq 'password'
15
+ expect(server.connection).to be_a Faraday::Connection
16
+ expect(server.connection.headers[:user_agent]).to \
17
+ eq "filemaker-ruby-#{Filemaker::VERSION}"
18
+ expect(server.connection.headers[:authorization]).to \
19
+ eq 'Basic YWNjb3VudF9uYW1lOnBhc3N3b3Jk'
20
+ end
21
+
22
+ it 'specifically ask for no SSL' do
23
+ server = Filemaker::Server.new do |config|
24
+ config.host = 'host'
25
+ config.account_name = 'account_name'
26
+ config.password = 'password'
27
+ config.ssl = false
28
+ end
29
+
30
+ expect(server.url).to eq 'http://host'
31
+ end
32
+
33
+ it 'did not provide host, account_name, and password' do
34
+ expect do
35
+ Filemaker::Server.new
36
+ end.to raise_error ArgumentError
37
+
38
+ expect do
39
+ Filemaker::Server.new { |config| config.host = 'host' }
40
+ end.to raise_error ArgumentError
41
+ end
42
+ end
43
+
44
+ context 'initializing a server with SSL' do
45
+ it 'indicates secured connection' do
46
+ server = Filemaker::Server.new do |config|
47
+ config.host = 'host'
48
+ config.account_name = 'account_name'
49
+ config.password = 'password'
50
+ config.ssl = { verify: false }
51
+ end
52
+
53
+ expect(server.url).to eq 'https://host'
54
+ expect(server.connection.ssl[:verify]).to be false
55
+ end
56
+ end
57
+
58
+ describe 'databases is a store to track encountered -db' do
59
+ it 'stores database object and can be accessed with db and database' do
60
+ server = Filemaker::Server.new do |config|
61
+ config.host = 'host'
62
+ config.account_name = 'account_name'
63
+ config.password = 'password'
64
+ end
65
+
66
+ expect(server.databases['candidate']).to be_a Filemaker::Database
67
+ expect(server.database['candidate']).to eq server.databases['candidate']
68
+ expect(server.db['candidate']).to eq server.databases['candidate']
69
+ end
70
+ end
71
+
72
+ context 'HTTP errors' do
73
+ before do
74
+ @server = Filemaker::Server.new do |config|
75
+ config.host = 'host'
76
+ config.account_name = 'account_name'
77
+ config.password = 'password'
78
+ end
79
+ end
80
+
81
+ it 'raises Filemaker::Error::CommunicationError if status = 0' do
82
+ fake_error(@server, nil, 0)
83
+
84
+ expect do
85
+ @server.databases.all
86
+ end.to raise_error Filemaker::Error::CommunicationError
87
+ end
88
+
89
+ it 'raises Filemaker::Error::CommunicationError if status = 404' do
90
+ fake_error(@server, nil, 404)
91
+
92
+ expect do
93
+ @server.databases.all
94
+ end.to raise_error Filemaker::Error::CommunicationError
95
+ end
96
+
97
+ it 'raises Filemaker::Error::AuthenticationError if status = 401' do
98
+ fake_error(@server, nil, 401)
99
+
100
+ expect do
101
+ @server.databases.all
102
+ end.to raise_error Filemaker::Error::AuthenticationError
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,34 @@
1
+ describe Filemaker::Store::DatabaseStore do
2
+
3
+ it 'is a Hash' do
4
+ store = Filemaker::Store::DatabaseStore.new(double(:server))
5
+ expect(store).to be_a Hash
6
+ end
7
+
8
+ context 'storing a Database' do
9
+ it 'keeps track of a database' do
10
+ store = Filemaker::Store::DatabaseStore.new(double(:server))
11
+ expect(store['candidate']).to be_a Filemaker::Database
12
+ expect(store['candidate']).to equal store['candidate']
13
+ end
14
+ end
15
+
16
+ describe 'all' do
17
+ it 'returns all databases' do
18
+ server = Filemaker::Server.new do |config|
19
+ config.host = 'host'
20
+ config.account_name = 'account_name'
21
+ config.password = 'password'
22
+ end
23
+
24
+ fake_post_response(server, nil, 'dbnames.xml')
25
+
26
+ expected_result = %w(Billing Candidates Employee Jobs)
27
+
28
+ expect(server.databases.all).to eq expected_result
29
+ expect(server.database.all).to eq expected_result
30
+ expect(server.db.all).to eq expected_result
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,31 @@
1
+ describe Filemaker::Store::LayoutStore do
2
+
3
+ it 'is a Hash' do
4
+ store = Filemaker::Store::LayoutStore.new(double, double)
5
+ expect(store).to be_a Hash
6
+ end
7
+
8
+ context 'storing a layout' do
9
+ it 'keeps track of a layout' do
10
+ store = Filemaker::Store::LayoutStore.new(double, double)
11
+ expect(store['profile']).to be_a Filemaker::Layout
12
+ expect(store['profile']).to equal store['profile']
13
+ end
14
+ end
15
+
16
+ describe 'all' do
17
+ it 'returns all layouts for a database' do
18
+ server = Filemaker::Server.new do |config|
19
+ config.host = 'host'
20
+ config.account_name = 'account_name'
21
+ config.password = 'password'
22
+ end
23
+
24
+ fake_post_response(server, nil, 'layoutnames.xml')
25
+
26
+ expect(server.db['candidates'].layouts.all).to eq \
27
+ ['Dashboard', 'Calender', 'Profile', 'Resume', 'Job Application']
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ describe Filemaker::Store::ScriptStore do
2
+
3
+ it 'is a Hash' do
4
+ store = Filemaker::Store::ScriptStore.new(double, double)
5
+ expect(store).to be_a Hash
6
+ end
7
+
8
+ context 'storing a script' do
9
+ it 'keeps track of a script' do
10
+ store = Filemaker::Store::ScriptStore.new(double, double)
11
+ expect(store['print']).to be_a Filemaker::Script
12
+ expect(store['print']).to equal store['print']
13
+ end
14
+ end
15
+
16
+ describe 'all' do
17
+ it 'returns all scripts for a database' do
18
+ server = Filemaker::Server.new do |config|
19
+ config.host = 'host'
20
+ config.account_name = 'account_name'
21
+ config.password = 'password'
22
+ end
23
+
24
+ fake_post_response(server, nil, 'scriptnames.xml')
25
+
26
+ expect(server.db['candidates'].scripts.all).to eq \
27
+ ['library', 'open job', 'copy resume']
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,84 @@
1
+ require 'filemaker'
2
+ require_relative 'support/xml_loader'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, make a
14
+ # separate helper file that requires this one and then use it only in the specs
15
+ # that actually need it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ config.include XmlLoader
23
+
24
+ # The settings below are suggested to provide a good initial experience
25
+ # with RSpec, but feel free to customize to your heart's content.
26
+
27
+ # These two settings work together to allow you to limit a spec run
28
+ # to individual examples or groups you care about by tagging them with
29
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
30
+ # get run.
31
+ config.filter_run :focus
32
+ config.run_all_when_everything_filtered = true
33
+
34
+ # Many RSpec users commonly either run the entire suite or an individual
35
+ # file, and it's useful to allow more verbose output when running an
36
+ # individual spec file.
37
+ if config.files_to_run.one?
38
+ # Use the documentation formatter for detailed output,
39
+ # unless a formatter has already been configured
40
+ # (e.g. via a command-line flag).
41
+ config.default_formatter = 'doc'
42
+ end
43
+
44
+ # Print the 10 slowest examples and example groups at the
45
+ # end of the spec run, to help surface which specs are running
46
+ # particularly slow.
47
+ # config.profile_examples = 10
48
+
49
+ # Run specs in random order to surface order dependencies. If you find an
50
+ # order dependency and want to debug it, you can fix the order by providing
51
+ # the seed, which is printed after each run.
52
+ # --seed 1234
53
+ config.order = :random
54
+
55
+ # Seed global randomization in this process using the `--seed` CLI option.
56
+ # Setting this allows you to use `--seed` to deterministically reproduce
57
+ # test failures related to randomization by passing the same `--seed` value
58
+ # as the one that triggered the failure.
59
+ Kernel.srand config.seed
60
+
61
+ # rspec-expectations config goes here. You can use an alternate
62
+ # assertion/expectation library such as wrong or the stdlib/minitest
63
+ # assertions if you prefer.
64
+ config.expect_with :rspec do |expectations|
65
+ # Enable only the newer, non-monkey-patching expect syntax.
66
+ # For more details, see:
67
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
68
+ expectations.syntax = :expect
69
+ end
70
+
71
+ # rspec-mocks config goes here. You can use an alternate test double
72
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
73
+ config.mock_with :rspec do |mocks|
74
+ # Enable only the newer, non-monkey-patching expect syntax.
75
+ # For more details, see:
76
+ # http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77
+ mocks.syntax = :expect
78
+
79
+ # Prevents you from mocking or stubbing a method that does not exist on
80
+ # a real object. This is generally recommended.
81
+ mocks.verify_partial_doubles = true
82
+ end
83
+
84
+ end