quickbase_record 0.2.3 → 0.2.4

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTFlNzllN2NmODI1M2U5OWFlMTQyZTliOGQ3YTdhMDExMTA4OGM2Zg==
4
+ NTBiNzE5ZDE5ZmE1NjNiZGNkZDIyNzhkMmNjOTY5NTkxNzYzM2M0Zg==
5
5
  data.tar.gz: !binary |-
6
- YTA1NjViZjNjYWQyODZhYWY0YmVjNDU2OTc2YTVkODBkOTZjNWNkYQ==
6
+ NzEyMDE4ZjdmOTNiN2M0YWZhZjYwMjAyZjMyZmRmNTBjM2MxYThkZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzNkMDE4ZDdmZDllMjYxMDQ3N2ViNTYzM2ZmNDJjYjVkYzA2MTIxZDBlZjM2
10
- NDM4NzIwZDk2OTVmNWYxMDRhZGFlNDUwNzI4Y2RhOTMyMDc4NzhkYWM5OGEy
11
- NDUzZDA3YjlhMDc5MDgzMmVkNzVkMTFlNDRmZDQ4MDQyMDdjMzI=
9
+ MGY2MGU0YTNlNGZjNmU0OWFjNGE2MDJkYmVkZmY2ODFlYjI5NDhiZmMwNDk0
10
+ YzE1NmVmYmFkZDU3YWIwYjQyMzQ0OGZmZGY5MmQ4Mzk4Zjc0YTcyMzYxYzgy
11
+ YzJmZDg0ZmVhYWZiNjQ5MGZmZGNhMWJhNzUwZWE5YjVjZmQzMWE=
12
12
  data.tar.gz: !binary |-
13
- NDVlYzNlYjhkMjU0NmIwMzMzNGUyOWU2YjI1Y2YzNTQzYmU0NjM0YjA3OTY3
14
- ZDM2Mzc5ZjBlMTYxNGE2ZTc4NTlkZWYyODY3ZjhlNGQzMjQwNzZlYjRkNjVk
15
- ZDU0YTVmNzA1ZTczNmEwY2FmMjI3YzAzZTA4ODEyZTFiN2ZmMjY=
13
+ YmUyZjJiM2M5YTU4N2NmNjI0ZDJhYTVkN2YwYzRiNzZjZTJiNDM3YWFlNmRk
14
+ YWY4MjNkMGFjMjMwMzU3MGRiNDQwNzkwZGNjMzc4YTFlMWU2NDA2MGY2NjJl
15
+ ZTQ0Zjc5OWQ3YTQ3ZWU0NDFmYmUzYjE2MGE0YWJjZWNiMGNlMjY=
data/.gitignore CHANGED
@@ -12,5 +12,6 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
- /spec/quickbase_record_config
15
+ /spec/quickbase_record_config.rb
16
+ /spec/config.yml
16
17
  .DS_Store
data/README.md CHANGED
@@ -53,6 +53,7 @@ Simply `include QuickbaseRecord::Model` in your class and use the `.define_field
53
53
  # code...
54
54
  end
55
55
  ```
56
+
56
57
  **IMPORTANT:** You must supply a key/value pair for :dbid and :id (QuickbaseRecord uses :id instead of :record_id to look more like standard ActiveRecord models)
57
58
 
58
59
  ### What You Get
@@ -114,8 +115,11 @@ Database callbacks (i.e. `before_save :create_token!`) are not fully functional
114
115
 
115
116
  - Values in an array are joined with 'OR'
116
117
  ```
117
- Post.where(author: ['Cullen Jett', 'Socrates')
118
- # {'8'.EX.'Socrates'}OR{'8'.EX.'Socrates'}
118
+ Post.where(author: ['Cullen Jett', 'Socrates'])
119
+ # {'8'.EX.'Cullen Jett'}OR{'8'.EX.'Socrates'}
120
+
121
+ Post.where({ [author: 'Cullen Jett', id: 123] })
122
+ # {'8'.EX.'Cullen Jett'}OR{'3'.EX.'123'}
119
123
  ```
120
124
 
121
125
  - To use a comparator other than 'EX' pass the value as another hash with the key as the comparator
@@ -188,6 +192,15 @@ Database callbacks (i.e. `before_save :create_token!`) are not fully functional
188
192
  * **.qb_client and #qb_client**
189
193
  - Access the quickbase API client (advantage_quickbase gem) directly
190
194
 
195
+ ## File Attachments
196
+ When ***creating*** an object with a field of type 'file attachment', you must assign it as hash with :name and :file as keys.
197
+ After the object is ***saved*** that field will then become a new hash with :filename and :url as keys.
198
+ ```
199
+ @post = Post.new(attachment: {name: 'Test File Name', file: 'path/to/your/file OR file contents'})
200
+ @post.save
201
+ @post.attachment => {filename: 'Test File Name', url: 'https://realm.quickbase.com/up/abcdefg/Test%20File%20Name'}
202
+ ```
203
+
191
204
  ## Testing
192
205
  Unfortunately you will not be able to run the test suite unless you have access to the QuickBase application used as the test database *or* you create your own QuickBase app to test against that mimics the test fakes. Eventually the test calls will be stubbed out so anyone can test it, but I've got stuff to do -- pull requests are welcome :)
193
206
 
@@ -55,6 +55,13 @@ module QuickbaseRecord
55
55
  return convert_query_string(query_hash) if query_hash.is_a? String
56
56
 
57
57
  query_hash.map do |field_name, values|
58
+ if field_name.is_a? Hash
59
+ return field_name.map do |field_name, value|
60
+ fid = convert_field_name_to_fid(field_name)
61
+ join_with_or(fid, [value])
62
+ end.join('OR')
63
+ end
64
+
58
65
  fid = convert_field_name_to_fid(field_name)
59
66
  if values.is_a? Array
60
67
  join_with_or(fid, values)
@@ -146,9 +153,19 @@ module QuickbaseRecord
146
153
  current_object = {}
147
154
  self.class.fields.each do |field_name, fid|
148
155
  current_object[fid] = public_send(field_name) unless UNWRITABLE_FIELDS.include?(field_name.to_s)
156
+ end
157
+
158
+ if has_file_attachment?(current_object)
159
+ if self.id
160
+ qb_client.edit_record(self.class.dbid, self.id, current_object)
161
+ else
162
+ self.id = qb_client.add_record(self.class.dbid, current_object)
163
+ end
164
+ else
149
165
  current_object[self.class.fields[:id]] = self.id if self.id
166
+ self.id = qb_client.import_from_csv(self.class.dbid, [current_object]).first
150
167
  end
151
- self.id = qb_client.import_from_csv(self.class.dbid, [current_object]).first
168
+
152
169
  return self
153
170
  end
154
171
 
@@ -164,5 +181,11 @@ module QuickbaseRecord
164
181
  self.save
165
182
  return self
166
183
  end
184
+
185
+ private
186
+
187
+ def has_file_attachment?(current_object)
188
+ current_object.values.any? { |value| value.is_a? Hash }
189
+ end
167
190
  end
168
191
  end
@@ -1,3 +1,3 @@
1
1
  module QuickbaseRecord
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
Binary file
@@ -8,6 +8,7 @@ class TeacherFake
8
8
  :id => 3,
9
9
  :name => 6,
10
10
  :subject => 7,
11
- :salary => 8
11
+ :salary => 8,
12
+ :attachment => 9
12
13
  })
13
14
  end
data/spec/queries_spec.rb CHANGED
@@ -86,6 +86,14 @@ RSpec.describe QuickbaseRecord::Queries do
86
86
  cullen.subject = 'Ruby on Rails'
87
87
  cullen.name = "THE #{cullen.name}"
88
88
  expect(cullen.save.id).to be_truthy
89
+ end
90
+
91
+ it "uploads files" do
92
+ cullen = TeacherFake.where(name: 'THE Cullen Jett').first
93
+ cullen.attachment = {name: 'Test Attachment', file: 'LICENSE.txt'}
94
+ cullen.save
95
+ cullen = TeacherFake.find(cullen.id)
96
+ expect(cullen.attachment[:filename]).to eq('Test Attachment')
89
97
  cullen.delete
90
98
  end
91
99
  end
@@ -159,6 +167,11 @@ RSpec.describe QuickbaseRecord::Queries do
159
167
  expect(TeacherFake.build_query(hash)).to eq("{'3'.EX.'1'}OR{'3'.EX.'2'}")
160
168
  end
161
169
 
170
+ it "combines an all array query with OR" do
171
+ hash = [{id: 1, name: 'Cullen Jett'}]
172
+ expect(TeacherFake.build_query(hash)).to eq("{'3'.EX.'1'}OR{'6'.EX.'Cullen Jett'}")
173
+ end
174
+
162
175
  it "accepts custom comparators via a nested hash" do
163
176
  hash = {id: {XEX: 1}}
164
177
  expect(TeacherFake.build_query(hash)).to eq("{'3'.XEX.'1'}")
@@ -1,5 +1,8 @@
1
+ require 'yaml'
2
+ creds = YAML.load_file("spec/config.yml")
3
+
1
4
  QuickbaseRecord.configure do |config|
2
5
  config.realm = "ais"
3
- config.username = ENV["QB_USERNAME"]
4
- config.password = ENV["QB_PASSWORD"]
6
+ config.username = creds["username"]
7
+ config.password = creds["password"]
5
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickbase_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cullen Jett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-15 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - quickbase_record-0.2.0.gem
120
120
  - quickbase_record-0.2.1.gem
121
121
  - quickbase_record-0.2.2.gem
122
+ - quickbase_record-0.2.3.gem
122
123
  - quickbase_record.gemspec
123
124
  - spec/fakes/student_fake.rb
124
125
  - spec/fakes/teacher_fake.rb