sneaky-save 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODk3MmJjYTNiNTEzZWRhOTNkZjQ2NDUzNGUxZjQyNTIzY2Q2NzUzMg==
4
+ MGRhZDliMTBiNWEwZDhlZThkYTIwMzdhMzNjNjQxMjYxZjM5Mzg1Mw==
5
5
  data.tar.gz: !binary |-
6
- ZGVlZTc2ZWE2MTljNzU5ZDEzZWY0ZTRhNmY2ODRkYTcwYjI0Yjc1Yw==
6
+ YTcwMzBhNjJiOTY0ZjhiZDAyMTU4NTUzZWZlODRkYTVlOGIyZTlhNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjg0MTRkOTZmNDk1YzhiZWEwOGM4MmJlNThmNGUwZjUzNDNjZDJhNzhhZTg2
10
- ZTdhNmIyYjEzODJiN2U4ZjEwMjNmYWZjZWNhOGM5NmEwNDQyMTEzMjZjMzcw
11
- Y2UwNjlmZmI5YjUzYTVlYjllMGVmMTJkMTYwMGRlZjEzOTk5ZTc=
9
+ MmNiMmJlMzk2MTBjOTA1OTNhYmQwOWFlOTkyM2Y5YzhkYjQwNzVmMDY2M2Qw
10
+ YmYwMTk0YWQxMTY3OGMzOTEwMTliNjk5MDAzYTRlNWY2NjliNGU2Yzk4MWY5
11
+ YWUzOGZkYWMxMzQ3ZmU2OGFjOGZkNDljOWZhMGJkNGNjMjI2ZWY=
12
12
  data.tar.gz: !binary |-
13
- OGNjZWI0ZmJlZjM5ZTllZWMzMmUyOGQ4YTg4MjY1MTRlMDlmZThlYTcyN2Yx
14
- MGIxZjBmOGRiNDRlZmMxMDFmMTgzMmFhNjNmNjFlZGRhOGM5OTU1ZDNjMjI5
15
- Zjk0MTYzZDkwNThjNDI1MDA2NmI0YzkxODI0MTI2NTAwMTJjNjA=
13
+ YTk3OTBmMWE1ZTdiZTA0ZGVkNDU0NGY3OTgyNTBkODU2MTRiODM5MWU1YWIy
14
+ YmQzOThmNjFhY2E4ODZhNTZkM2IzYjlhMzM3OWNiMzljM2ZmNzI3OTBjMDkw
15
+ ZmQxMTE2ZmUyNmVkODI2MTBkMDQxMmFlMGYwMmU5YzU4ZjdhZDk=
@@ -2,3 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
+ - "2.1.2"
6
+ gemfile:
7
+ - Gemfile
8
+ - gemfiles/rails_4
9
+ - gemfiles/rails_3.2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.2.0'
4
+ gem 'rake'
5
+ gem 'rspec'
6
+ gem 'sqlite3'
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 4.0.0'
4
+ gem 'rake'
5
+ gem 'rspec'
6
+ gem 'sqlite3'
7
+
@@ -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? && self.class.connection.prefetch_primary_key?(self.class.table_name)
28
- self.id = self.class.connection.next_sequence_value(self.class.sequence_name)
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 = send :arel_attributes_with_values_for_create, attribute_names
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? && !self.class.connection.prefetch_primary_key?(self.class.table_name)
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 self.class.connection.empty_insert_statement_value
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sneaky-save}
5
- s.version = '0.0.5'
5
+ s.version = '0.0.6'
6
6
 
7
7
  s.date = %q{2013-12-09}
8
8
  s.authors = ["Sergei Zinin (einzige)"]
@@ -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.should be_true
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.should_receive(:sneaky_create).once.and_return true
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.should == 'test'
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.should be_true
54
+ expect(subject.sneaky_save).to eq(true)
55
55
  subject.reload
56
- subject.name.should == 'new name'
56
+ expect(subject.name).to eq('new name')
57
57
  end
58
58
 
59
59
  it 'does not call any callback' do
@@ -25,6 +25,4 @@ end
25
25
 
26
26
  RSpec.configure do |config|
27
27
  config.mock_with :rspec
28
- config.color_enabled = true
29
- config.formatter = :documentation
30
28
  end
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.5
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