notifiable-rails 0.19.3 → 0.19.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28d39b459daed63027ffe36633510ce234f343d4
4
- data.tar.gz: 9617fab405a153ddd3b0df2ccdc7e33528f553cb
3
+ metadata.gz: 8a1e54e45f4a3b6bed44aee9c110e26d5c297f47
4
+ data.tar.gz: 1848c6bdb6b0f445d52517f41c07725933881d46
5
5
  SHA512:
6
- metadata.gz: c4e3b0c8f4cec9faa43f7295ab0dfed2328a2016900e2392c06e434893b3659aed97563e8647e5c22d01d9babeffec8cdfab3d3c86ac4ba33bfe6b3f1dca1b6d
7
- data.tar.gz: d2cea2b3879309b57056ea0cb1390818cf34de298f4ecdf3e3377380886d999625839a08b0ec0d7a623ae1028bc84dc0fd3010e56a8144c1629b8e97a845bdf1
6
+ metadata.gz: ca963fd3b6d4e46d12d37e4dd85b3c17f53b035dbc2b269b1a6c95b046f4c8ec206efe5021c3cd4269be314f2bbc1e53bdd81bfe44c36d1f0d44df6e0c29457e
7
+ data.tar.gz: ce3c2a2b9cc64155b92e0fa546c1e4a108ca4d3f40806f8592afa47d40f40b6e7a4351a64df8a13d0fee44e7c98159e2e288f7cc0ccaa892741af843efb61bf3
@@ -8,18 +8,17 @@ class ActiveRecord::Base
8
8
  when :mysql
9
9
  raise NotImplementedError, "Not implemented type '#{adapter_type}'"
10
10
  when :sqlite
11
- sqlite_bulk_insert(record_list)
11
+ self.create(record_list)
12
12
  when :postgresql
13
- postgresql_bulk_insert(record_list)
13
+ self.connection.execute(postgresql_bulk_insert_sql(record_list))
14
14
  when :oracleenhanced
15
- oracle_bulk_insert(record_list)
15
+ self.connection.execute(oracle_bulk_insert_sql(record_list))
16
16
  else
17
17
  raise NotImplementedError, "Unknown adapter type '#{adapter_type}' for ActiveRecord::Base.bulk_insert!"
18
18
  end
19
-
20
19
  end
21
20
 
22
- protected
21
+ protected
23
22
  def self.convert_record_list(record_list)
24
23
  key_list = record_list.map(&:keys).flatten.uniq.sort
25
24
 
@@ -32,20 +31,20 @@ class ActiveRecord::Base
32
31
  return [key_list, value_list]
33
32
  end
34
33
 
35
- def self.sqlite_bulk_insert(record_list)
36
- self.create record_list
37
- end
38
-
39
- def self.postgresql_bulk_insert(record_list)
34
+ def self.postgresql_bulk_insert_sql(record_list)
40
35
  key_list, value_list = convert_record_list(record_list)
41
- sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}"
42
- self.connection.insert_sql(sql)
36
+ "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}"
43
37
  end
44
38
 
45
- def self.oracle_bulk_insert(record_list)
46
- key_list, value_list = convert_record_list(record_list)
47
- sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES (bind variables #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")})"
48
- self.connection.execute(sql)
39
+ def self.oracle_bulk_insert_sql(record_list)
40
+ key_list, value_list = convert_record_list(record_list)
41
+
42
+ inserts = []
43
+ value_list.each do |rec|
44
+ inserts << "INTO #{self.table_name} (#{key_list.join(", ")}) VALUES (#{rec.join(", ")})"
45
+ end
46
+
47
+ "INSERT ALL #{inserts.join(' ')}"
49
48
  end
50
49
 
51
50
  end
@@ -1,3 +1,3 @@
1
1
  module Notifiable
2
- VERSION = "0.19.3"
2
+ VERSION = "0.19.4"
3
3
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveRecord::Base do
4
+
5
+ let(:notification_status) { FactoryGirl.build(:notification_status) }
6
+ let(:notification_status2) { FactoryGirl.build(:notification_status) }
7
+
8
+ it "generates correct Oracle Enchanced Bulk SQL" do
9
+ date = DateTime.now
10
+ sql = Notifiable::NotificationStatus.send(:oracle_bulk_insert_sql,
11
+ [{notification_id: notification_status.notification.id, device_token_id: notification_status.device_token.id, status: 0, created_at: date},
12
+ {notification_id: notification_status2.notification.id, device_token_id: notification_status2.device_token.id, status: 0, created_at: date}])
13
+
14
+ sql.should eql "INSERT ALL INTO notifiable_statuses (created_at, device_token_id, notification_id, status) VALUES (#{ActiveRecord::Base.connection.quote(date)}, 1, 1, 0) INTO notifiable_statuses (created_at, device_token_id, notification_id, status) VALUES (#{ActiveRecord::Base.connection.quote(date)}, 2, 2, 0)"
15
+ end
16
+ end
@@ -21,6 +21,7 @@ FactoryGirl.define do
21
21
  factory :notification_status, :class => Notifiable::NotificationStatus do
22
22
  notification
23
23
  status 0
24
+ association :device_token, factory: :mock_token
24
25
  end
25
26
 
26
27
  sequence(:email) {|n| "person-#{n}@example.com" }