notifiable-rails 0.19.3 → 0.19.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notifiable/active_record.rb +15 -16
- data/lib/notifiable/version.rb +1 -1
- data/spec/active_record_spec.rb +16 -0
- data/spec/support/factories.rb +1 -0
- data/spec/test_app/log/test.log +2730 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a1e54e45f4a3b6bed44aee9c110e26d5c297f47
|
4
|
+
data.tar.gz: 1848c6bdb6b0f445d52517f41c07725933881d46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
11
|
+
self.create(record_list)
|
12
12
|
when :postgresql
|
13
|
-
|
13
|
+
self.connection.execute(postgresql_bulk_insert_sql(record_list))
|
14
14
|
when :oracleenhanced
|
15
|
-
|
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.
|
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
|
-
|
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.
|
46
|
-
key_list, value_list = convert_record_list(record_list)
|
47
|
-
|
48
|
-
|
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
|
data/lib/notifiable/version.rb
CHANGED
@@ -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
|
data/spec/support/factories.rb
CHANGED