sneaky-save 0.0.5 → 0.0.6
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/.travis.yml +5 -0
- data/VERSION +1 -1
- data/gemfiles/rails_3.2 +6 -0
- data/gemfiles/rails_4 +7 -0
- data/lib/sneaky-save.rb +21 -5
- data/sneaky-save.gemspec +1 -1
- data/spec/lib/sneaky_save_spec.rb +5 -5
- data/spec/spec_helper.rb +0 -2
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGRhZDliMTBiNWEwZDhlZThkYTIwMzdhMzNjNjQxMjYxZjM5Mzg1Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTcwMzBhNjJiOTY0ZjhiZDAyMTU4NTUzZWZlODRkYTVlOGIyZTlhNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmNiMmJlMzk2MTBjOTA1OTNhYmQwOWFlOTkyM2Y5YzhkYjQwNzVmMDY2M2Qw
|
10
|
+
YmYwMTk0YWQxMTY3OGMzOTEwMTliNjk5MDAzYTRlNWY2NjliNGU2Yzk4MWY5
|
11
|
+
YWUzOGZkYWMxMzQ3ZmU2OGFjOGZkNDljOWZhMGJkNGNjMjI2ZWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTk3OTBmMWE1ZTdiZTA0ZGVkNDU0NGY3OTgyNTBkODU2MTRiODM5MWU1YWIy
|
14
|
+
YmQzOThmNjFhY2E4ODZhNTZkM2IzYjlhMzM3OWNiMzljM2ZmNzI3OTBjMDkw
|
15
|
+
ZmQxMTE2ZmUyNmVkODI2MTBkMDQxMmFlMGYwMmU5YzU4ZjdhZDk=
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/gemfiles/rails_3.2
ADDED
data/gemfiles/rails_4
ADDED
data/lib/sneaky-save.rb
CHANGED
@@ -24,19 +24,19 @@ module SneakySave
|
|
24
24
|
# Makes INSERT query in database without running any callbacks
|
25
25
|
# @return [false, true]
|
26
26
|
def sneaky_create
|
27
|
-
if self.id.nil? &&
|
28
|
-
self.id =
|
27
|
+
if self.id.nil? && sneaky_connection.prefetch_primary_key?(self.class.table_name)
|
28
|
+
self.id = sneaky_connection.next_sequence_value(self.class.sequence_name)
|
29
29
|
end
|
30
30
|
|
31
|
-
attributes_values =
|
31
|
+
attributes_values = skeaky_attributes_values
|
32
32
|
|
33
33
|
# Remove the id field for databases like Postgres which will raise an error on id being NULL
|
34
|
-
if self.id.nil? && !
|
34
|
+
if self.id.nil? && !sneaky_connection.prefetch_primary_key?(self.class.table_name)
|
35
35
|
attributes_values.reject! { |key,_| key.name == 'id' }
|
36
36
|
end
|
37
37
|
|
38
38
|
new_id = if attributes_values.empty?
|
39
|
-
self.class.unscoped.insert
|
39
|
+
self.class.unscoped.insert sneaky_connection.empty_insert_statement_value
|
40
40
|
else
|
41
41
|
self.class.unscoped.insert attributes_values
|
42
42
|
end
|
@@ -57,6 +57,22 @@ module SneakySave
|
|
57
57
|
original_id = changed_attributes.has_key?(pk) ? changes[pk].first : send(pk)
|
58
58
|
!self.class.where(pk => original_id).update_all(attributes).zero?
|
59
59
|
end
|
60
|
+
|
61
|
+
def skeaky_attributes_values
|
62
|
+
if ActiveRecord::VERSION::STRING.split('.').first.to_i > 3
|
63
|
+
send :arel_attributes_with_values_for_create, attribute_names
|
64
|
+
else
|
65
|
+
send :arel_attributes_values
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def sneaky_connection
|
70
|
+
if ActiveRecord::VERSION::STRING.split('.').first.to_i > 3
|
71
|
+
self.class.connection
|
72
|
+
else
|
73
|
+
connection
|
74
|
+
end
|
75
|
+
end
|
60
76
|
end
|
61
77
|
|
62
78
|
ActiveRecord::Base.send :include, SneakySave
|
data/sneaky-save.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SneakySave, use_connection: true do
|
4
4
|
after :each do
|
5
|
-
subject.sneaky_save.
|
5
|
+
expect(subject.sneaky_save).to eq(true)
|
6
6
|
end
|
7
7
|
|
8
8
|
context 'new record' do
|
@@ -11,14 +11,14 @@ describe SneakySave, use_connection: true do
|
|
11
11
|
it('returns true if everything is good') {}
|
12
12
|
|
13
13
|
it 'does insert of the new record' do
|
14
|
-
subject.
|
14
|
+
allow(subject).to receive(:sneaky_create).once.and_return(true)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'stores attributes in database' do
|
18
18
|
subject.name = 'test'
|
19
19
|
subject.sneaky_save
|
20
20
|
subject.reload
|
21
|
-
subject.name.
|
21
|
+
expect(subject.name).to eq('test')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'does not call any callback' do
|
@@ -51,9 +51,9 @@ describe SneakySave, use_connection: true do
|
|
51
51
|
|
52
52
|
it 'stores attributes in database' do
|
53
53
|
subject.name = 'new name'
|
54
|
-
subject.sneaky_save.
|
54
|
+
expect(subject.sneaky_save).to eq(true)
|
55
55
|
subject.reload
|
56
|
-
subject.name.
|
56
|
+
expect(subject.name).to eq('new name')
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'does not call any callback' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sneaky-save
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Zinin (einzige)
|
@@ -52,6 +52,8 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- VERSION
|
55
|
+
- gemfiles/rails_3.2
|
56
|
+
- gemfiles/rails_4
|
55
57
|
- lib/sneaky-save.rb
|
56
58
|
- sneaky-save.gemspec
|
57
59
|
- spec/lib/sneaky_save_spec.rb
|