quickbase_record 0.3.2 → 0.3.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 +8 -8
- data/README.md +2 -2
- data/lib/quickbase_record/field_mapping.rb +0 -23
- data/lib/quickbase_record/model.rb +1 -0
- data/lib/quickbase_record/queries.rb +25 -11
- data/lib/quickbase_record/version.rb +1 -1
- data/spec/fakes/classroom_fake.rb +14 -0
- data/spec/fakes/student_fake.rb +8 -0
- data/spec/model_spec.rb +0 -15
- data/spec/queries_spec.rb +71 -34
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzM2ODllMjE5Y2VjZTcxNGYxZTc0MGJlOTZlZmMxZWY5YWE0YzZiZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODZkYjE3YjVmNWFhZjY2ZjUzYWEzYWZlYTUxN2FlZWEyYWM0NDRhNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWZmMjZlOWU0NjZmYjNlNDkxY2E2Yjk5YTgyNDQzOWZlZGQ5MDRmNTI5Nzc0
|
10
|
+
MDc0OWFiNmVmM2Q3MTBiY2YyMmU0ZTJiODY1MTFiNTU0YTkxNDhhNDdjMDMx
|
11
|
+
MTZhOWFmNTUzZjMzMGQ5Y2Y4ZjdhZjUzOWU2YThkNDVlNGI4Mjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDBlMjU4ZGIwN2MzYjkxMzkxMTE3NWVjMzY0ODhhZWY2ODI0ZDNlMTkzNWY1
|
14
|
+
MTE2MGVmMjM2MDMwNzMxNmYxMTFkZWMxNTZjZGZlZDU0ZDIyN2Q4NGE1Yjdi
|
15
|
+
YzBkODY4YTRmNDQ5OGNlY2U1NWY4NWRmMWZlMmNkMWU4ZmM2N2U=
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ Simply `include QuickbaseRecord::Model` in your class and use the `.define_field
|
|
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
|
+
**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). If your table does not use [Record ID] as it's primary key then you must supply a key/value pair for :record_id and assign :id to the primary key.
|
58
58
|
|
59
59
|
### What You Get
|
60
60
|
Classes that include QuickbaseRecord::Model and define their fields will have a handful of class and instance methods for interacting with your QuickBase application similar to ActiveRecord. The goal is to be able to use QuickBase as a database and treat your models the same way you would with a traditional database.
|
@@ -169,7 +169,7 @@ Database callbacks (i.e. `before_save :create_token!`) are not fully functional
|
|
169
169
|
|
170
170
|
* **#delete**
|
171
171
|
- Delete the corresponding record in QuickBase
|
172
|
-
- It returns the object
|
172
|
+
- It returns the object if successful or `false` if unsuccessful
|
173
173
|
```
|
174
174
|
@post = Post.find(1)
|
175
175
|
@post.delete
|
@@ -3,30 +3,7 @@ module QuickbaseRecord
|
|
3
3
|
attr_accessor :fields
|
4
4
|
|
5
5
|
def initialize(fields={})
|
6
|
-
# @fields = create_fields(fields)
|
7
6
|
@fields = fields
|
8
7
|
end
|
9
|
-
|
10
|
-
def create_fields(fields_hash)
|
11
|
-
converted_fields_hash = {}
|
12
|
-
fields_hash.each do |key, value|
|
13
|
-
converted_fields_hash[key] = Field.new(value)
|
14
|
-
end
|
15
|
-
return converted_fields_hash
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Field
|
20
|
-
attr_accessor :value
|
21
|
-
|
22
|
-
def initialize(value)
|
23
|
-
@value = format_value(value)
|
24
|
-
end
|
25
|
-
|
26
|
-
def format_value(value)
|
27
|
-
return value if value.is_a? Integer
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
8
|
end
|
32
9
|
end
|
@@ -5,7 +5,6 @@ module QuickbaseRecord
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
include QuickbaseRecord::Client
|
7
7
|
|
8
|
-
UNWRITABLE_FIELDS = ['dbid', 'id', 'date_created', 'date_modified', 'record_owner', 'last_modified_by']
|
9
8
|
|
10
9
|
module ClassMethods
|
11
10
|
def dbid
|
@@ -140,7 +139,7 @@ module QuickbaseRecord
|
|
140
139
|
self.fields[field_name.to_sym].to_s
|
141
140
|
end
|
142
141
|
|
143
|
-
def
|
142
|
+
def convert_fid_to_field_name(fid)
|
144
143
|
self.fields.invert[fid.to_i]
|
145
144
|
end
|
146
145
|
|
@@ -148,7 +147,7 @@ module QuickbaseRecord
|
|
148
147
|
result = {}
|
149
148
|
|
150
149
|
response.each do |fid, value|
|
151
|
-
field_name =
|
150
|
+
field_name = convert_fid_to_field_name(fid)
|
152
151
|
result[field_name] = value
|
153
152
|
end
|
154
153
|
|
@@ -182,38 +181,53 @@ module QuickbaseRecord
|
|
182
181
|
def save
|
183
182
|
current_object = {}
|
184
183
|
self.class.fields.each do |field_name, fid|
|
185
|
-
current_object[fid] = public_send(field_name)
|
184
|
+
current_object[fid.to_s] = public_send(field_name)
|
186
185
|
end
|
187
186
|
|
188
|
-
current_object
|
189
|
-
|
190
|
-
if self.id
|
187
|
+
if current_object['3'] #object has a record_id, so we'll edit it
|
188
|
+
remove_unwritable_fields(current_object)
|
191
189
|
qb_client.edit_record(self.class.dbid, self.id, current_object)
|
192
190
|
else
|
193
|
-
|
191
|
+
remove_unwritable_fields(current_object)
|
192
|
+
new_rid = qb_client.add_record(self.class.dbid, current_object)
|
193
|
+
id_field_name = self.class.fields.select { |field_name, fid| fid == 3 }.keys.first
|
194
|
+
public_send("#{id_field_name}=", new_rid)
|
194
195
|
end
|
195
196
|
|
196
197
|
return self
|
197
198
|
end
|
198
199
|
|
199
200
|
def delete
|
200
|
-
|
201
|
-
|
202
|
-
|
201
|
+
# we have to use [record id] because of the advantage_quickbase gem
|
202
|
+
id_field_name = self.class.fields.select { |field_name, fid| fid == 3 }.keys.first
|
203
|
+
rid = public_send(id_field_name)
|
204
|
+
return false unless rid
|
205
|
+
|
206
|
+
successful = qb_client.delete_record(self.class.dbid, rid)
|
207
|
+
return successful ? self : false
|
203
208
|
end
|
204
209
|
|
205
210
|
def update_attributes(attributes={})
|
206
211
|
return false if attributes.blank?
|
212
|
+
|
207
213
|
self.assign_attributes(attributes)
|
208
214
|
updated_attributes = {}
|
209
215
|
attributes.each { |field_name, value| updated_attributes[self.class.convert_field_name_to_fid(field_name)] = value }
|
210
216
|
updated_attributes.delete_if { |key, value| value.nil? }
|
217
|
+
|
211
218
|
if self.id
|
212
219
|
qb_client.edit_record(self.class.dbid, self.id, updated_attributes)
|
213
220
|
else
|
214
221
|
self.id = qb_client.add_record(self.class.dbid, updated_attributes)
|
215
222
|
end
|
223
|
+
|
216
224
|
return self
|
217
225
|
end
|
226
|
+
|
227
|
+
def remove_unwritable_fields(hash)
|
228
|
+
hash.delete_if do |key, value|
|
229
|
+
value.nil? || key.to_i <= 5 || key == :dbid
|
230
|
+
end
|
231
|
+
end
|
218
232
|
end
|
219
233
|
end
|
data/spec/fakes/student_fake.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -13,21 +13,6 @@ RSpec.describe QuickbaseRecord::Model do
|
|
13
13
|
|
14
14
|
expect(StudentFake.fields[:id]).to eq(3)
|
15
15
|
end
|
16
|
-
|
17
|
-
# it "formats fields as dates given a hash value" do
|
18
|
-
# StudentFake.define_fields ({
|
19
|
-
# :dbid => 'bjzrx8ckw',
|
20
|
-
# :date_created => {date: 1},
|
21
|
-
# :id => 3,
|
22
|
-
# :name => 6,
|
23
|
-
# :grade => 7,
|
24
|
-
# :email => 8
|
25
|
-
# })
|
26
|
-
|
27
|
-
# puts StudentFake.find(1).inspect
|
28
|
-
|
29
|
-
# expect(StudentFake.find(1).date_created).to eq('1/1/2015')
|
30
|
-
# end
|
31
16
|
end
|
32
17
|
|
33
18
|
describe 'initialize' do
|
data/spec/queries_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require './spec/fakes/teacher_fake'
|
2
|
+
require './spec/fakes/classroom_fake'
|
2
3
|
|
3
4
|
RSpec.describe QuickbaseRecord::Queries do
|
4
5
|
describe '.find' do
|
@@ -82,44 +83,80 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
82
83
|
end
|
83
84
|
|
84
85
|
describe '#save' do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
86
|
+
context "when record ID is the primary key" do
|
87
|
+
it "creates a new record in QuickBase for an object without an ID and sets it's new ID" do
|
88
|
+
cullen = TeacherFake.new(name: 'Cullen Jett', salary: '1,000,000.00')
|
89
|
+
cullen.save
|
90
|
+
expect(cullen.id).to be_truthy
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns the object on successful save" do
|
94
|
+
cullen = TeacherFake.where(name: 'Cullen Jett').first
|
95
|
+
expect(cullen.save).to be_a TeacherFake
|
96
|
+
end
|
97
|
+
|
98
|
+
it "edits an object that has an existing ID" do
|
99
|
+
cullen = TeacherFake.where(name: 'Cullen Jett').first
|
100
|
+
cullen.subject = 'Ruby on Rails'
|
101
|
+
cullen.name = "THE #{cullen.name}"
|
102
|
+
expect(cullen.save.id).to be_truthy
|
103
|
+
end
|
104
|
+
|
105
|
+
it "uploads files" do
|
106
|
+
cullen = TeacherFake.where(name: 'THE Cullen Jett').first
|
107
|
+
cullen.attachment = {name: 'Test Attachment', file: 'LICENSE.txt'}
|
108
|
+
cullen.save
|
109
|
+
cullen = TeacherFake.find(cullen.id)
|
110
|
+
expect(cullen.attachment[:filename]).to eq('Test Attachment')
|
111
|
+
cullen.delete
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when record ID is not the primary key" do
|
116
|
+
it "creates a new record if the object doesn't have a record ID" do
|
117
|
+
math = ClassroomFake.new(id: '1', subject: 'Math')
|
118
|
+
math.save
|
119
|
+
expect(ClassroomFake.find('1')).not_to be_nil
|
120
|
+
math.delete
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets the object's record id for new records" do
|
124
|
+
english = ClassroomFake.new(id: '2', subject: 'English', date_created: 'this should not save')
|
125
|
+
english.save
|
126
|
+
expect(english.record_id).to be_present
|
127
|
+
expect(english.record_id).not_to eq('2')
|
128
|
+
english.delete
|
129
|
+
end
|
130
|
+
|
131
|
+
it "edits a record if it has a record ID" do
|
132
|
+
science = ClassroomFake.find(101)
|
133
|
+
science.subject = 'SCIENCE!'
|
134
|
+
science.save
|
135
|
+
expect(science.subject).to eq('SCIENCE!')
|
136
|
+
science.update_attributes(subject: 'Science')
|
137
|
+
end
|
110
138
|
end
|
111
139
|
end
|
112
140
|
|
113
141
|
describe '#delete' do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
142
|
+
context "when record ID is the primary key" do
|
143
|
+
it "deletes an object from QuickBase" do
|
144
|
+
socrates = TeacherFake.new(name: 'Socrates')
|
145
|
+
socrates.save
|
146
|
+
expect(socrates.delete).to eq(socrates)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns false if the object doesn't yet have an ID" do
|
150
|
+
expect(TeacherFake.new(name: 'Socrates').delete).to be false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "when record ID is not the primary key" do
|
155
|
+
it "deletes the record from QuickBase" do
|
156
|
+
gym = ClassroomFake.new(id: '3', subject: 'Gym')
|
157
|
+
gym.save
|
158
|
+
expect(gym.delete).to eq(gym)
|
159
|
+
end
|
123
160
|
end
|
124
161
|
end
|
125
162
|
|
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.3.
|
4
|
+
version: 0.3.3
|
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-07-
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/quickbase_record/queries.rb
|
117
117
|
- lib/quickbase_record/version.rb
|
118
118
|
- quickbase_record.gemspec
|
119
|
+
- spec/fakes/classroom_fake.rb
|
119
120
|
- spec/fakes/student_fake.rb
|
120
121
|
- spec/fakes/teacher_fake.rb
|
121
122
|
- spec/field_spec.rb
|
@@ -147,6 +148,7 @@ signing_key:
|
|
147
148
|
specification_version: 4
|
148
149
|
summary: An ActiveRecord-style ORM for using Intuit QuickBase tables as models.
|
149
150
|
test_files:
|
151
|
+
- spec/fakes/classroom_fake.rb
|
150
152
|
- spec/fakes/student_fake.rb
|
151
153
|
- spec/fakes/teacher_fake.rb
|
152
154
|
- spec/field_spec.rb
|