columns_on_demand 5.1.0 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/columns_on_demand.rb +16 -2
- data/lib/columns_on_demand/version.rb +1 -1
- data/test/columns_on_demand_test.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11669dc2b1270745b3daf5f0b4edd68a711edc45
|
4
|
+
data.tar.gz: 7e221c815f656f81f225fe0052c1acb22d4346dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ce9b3fb616787002fa71b58c4dbc71a7d00795f2ac7c0cfd905326bcc32b0f444664b6e529488c8799d5054f5a78076f159f28b7b21130559cb8848dc92a58e
|
7
|
+
data.tar.gz: 31f75591d087e6e4e448c36ba99ebd8fd2ce186af13f7067f67bf2bef6fa5909d6b8b943214236f346ba36eff25f8708a9d772c066feb2006fcc05f142fafcc9
|
data/README.md
CHANGED
data/lib/columns_on_demand.rb
CHANGED
@@ -68,8 +68,6 @@ module ColumnsOnDemand
|
|
68
68
|
attr_names.each_with_index do |attr_name, i|
|
69
69
|
columns_loaded << attr_name
|
70
70
|
value = row[i]
|
71
|
-
|
72
|
-
# activerecord 4.2 or later, which make it easy to replicate the normal typecasting and deserialization logic
|
73
71
|
@attributes.write_from_database(attr_name, value)
|
74
72
|
end
|
75
73
|
end
|
@@ -138,3 +136,19 @@ end
|
|
138
136
|
|
139
137
|
ActiveRecord::Base.send(:extend, ColumnsOnDemand::BaseMethods)
|
140
138
|
ActiveRecord::Relation.send(:prepend, ColumnsOnDemand::RelationMethods)
|
139
|
+
|
140
|
+
# work around ActiveRecord 5.0 and 5.1 converting uninitialized attributes to value nil on save
|
141
|
+
# (due to dirty.rb mapping @attributes). this is not only a problem for columns_on_demand as it
|
142
|
+
# means that a MissingAttributeError will never be raised after save, but we suffer more.
|
143
|
+
# ActiveRecord 4.2's Attribute doesn't have forgetting_assignment (or this problem).
|
144
|
+
if ActiveRecord::Attribute.uninitialized(nil, nil).try(:forgetting_assignment).try(:initialized?)
|
145
|
+
module ActiveRecord
|
146
|
+
class Attribute # :nodoc:
|
147
|
+
class Uninitialized < Attribute # :nodoc:
|
148
|
+
def forgetting_assignment
|
149
|
+
dup
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -163,6 +163,26 @@ class ColumnsOnDemandTest < ActiveSupport::TestCase
|
|
163
163
|
assert_not_equal old_object_id, record.file_data.object_id
|
164
164
|
end
|
165
165
|
|
166
|
+
test "it does not think the column has been loaded if a reloaded instance that has not loaded the attribute is saved" do
|
167
|
+
record = Implicit.first
|
168
|
+
record.update_attributes!(:file_data => "New file data")
|
169
|
+
|
170
|
+
record.reload
|
171
|
+
record.save!
|
172
|
+
|
173
|
+
assert_equal "New file data", record.file_data
|
174
|
+
end
|
175
|
+
|
176
|
+
test "it does not think the column has been loaded if a fresh instance that has not loaded the attribute is saved" do
|
177
|
+
record = Implicit.first
|
178
|
+
record.update_attributes!(:file_data => "New file data")
|
179
|
+
|
180
|
+
record = Implicit.find(record.id)
|
181
|
+
record.save!
|
182
|
+
|
183
|
+
assert_equal "New file data", record.file_data
|
184
|
+
end
|
185
|
+
|
166
186
|
test "it doesn't override custom select() finds" do
|
167
187
|
record = Implicit.select("id, file_data").first
|
168
188
|
klass = ActiveRecord.const_defined?(:MissingAttributeError) ? ActiveRecord::MissingAttributeError : ActiveModel::MissingAttributeError
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: columns_on_demand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -185,3 +185,4 @@ test_files:
|
|
185
185
|
- test/fixtures/parents.yml
|
186
186
|
- test/schema.rb
|
187
187
|
- test/test_helper.rb
|
188
|
+
has_rdoc: false
|