activerecord-import 1.3.0 → 1.4.0

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
  SHA256:
3
- metadata.gz: 815280c3b17a8ee84e54defd450a68fa532719dc8760ac001883f3df0156d689
4
- data.tar.gz: d34ee8c4c186b172259ea4f3427a75379d08b7ae41ee67128fd870e489d2f78d
3
+ metadata.gz: 71623b61f085adce5254fc92ae524f595594cb5a960bb4bf0cb46d961ca9d203
4
+ data.tar.gz: ce2200678685afd85dc0a887d967bae7e2e4220942ab2f8fc34bb949b8f5a31b
5
5
  SHA512:
6
- metadata.gz: 49c6d78cbcdc342db44497ec66f0dfe466b08124dc233996688c9443b0c455328e6d7ebc80d011c8732f7ae5b5468bd3c4f57f4abe2bb20bc26a118183cea402
7
- data.tar.gz: 9f602bb4423fb3cc5169727d150df7eef5396954f0576f1ecf8cb168179adc625f5ef5927a4655eb8271e37d845d9e5c6b6a6a597a83cb1c268958b4f2f65375
6
+ metadata.gz: 71bdd79b977164223d77c77ec796ac3914124318bb377c8aa044bc8085d0f7ba9536e35b99b6a670b0a4c825e4dfe49aef5a10626b92109b2ce7dd8cd529dbb1
7
+ data.tar.gz: 89db7ca7f321a473391d2083a2dc6cb4fe8614069441c2a16601a0a3e4ab848e889eafba67b53fc2042d60b7095aab50926f4795d07930c0c90820527f07c28c
@@ -20,12 +20,28 @@ jobs:
20
20
  fail-fast: false
21
21
  matrix:
22
22
  ruby:
23
- - 2.7
23
+ - 3.1
24
24
  env:
25
- - AR_VERSION: 7.0
25
+ - AR_VERSION: '7.0'
26
+ RUBYOPT: --enable-frozen-string-literal
26
27
  - AR_VERSION: 6.1
27
- - AR_VERSION: 6.0
28
+ RUBYOPT: --enable-frozen-string-literal
28
29
  include:
30
+ - ruby: '3.0'
31
+ env:
32
+ AR_VERSION: '7.0'
33
+ - ruby: '3.0'
34
+ env:
35
+ AR_VERSION: 6.1
36
+ - ruby: 2.7
37
+ env:
38
+ AR_VERSION: '7.0'
39
+ - ruby: 2.7
40
+ env:
41
+ AR_VERSION: 6.1
42
+ - ruby: 2.7
43
+ env:
44
+ AR_VERSION: '6.0'
29
45
  - ruby: 2.6
30
46
  env:
31
47
  AR_VERSION: 5.2
@@ -34,7 +50,7 @@ jobs:
34
50
  AR_VERSION: 5.1
35
51
  - ruby: 2.4
36
52
  env:
37
- AR_VERSION: 5.0
53
+ AR_VERSION: '5.0'
38
54
  - ruby: 2.4
39
55
  env:
40
56
  AR_VERSION: 4.2
@@ -47,9 +63,7 @@ jobs:
47
63
  - uses: ruby/setup-ruby@v1
48
64
  with:
49
65
  ruby-version: ${{ matrix.ruby }}
50
- - name: Setup Bundler 1.x for Ruby 2.3
51
- if: ${{ matrix.ruby == '2.3' }}
52
- run: echo "BUNDLER_VERSION=1.17.3" >> $GITHUB_ENV
66
+ bundler-cache: true
53
67
  - name: Set up databases
54
68
  run: |
55
69
  sudo /etc/init.d/mysql start
@@ -61,18 +75,33 @@ jobs:
61
75
  cp test/github/database.yml test/database.yml
62
76
  env:
63
77
  PGPASSWORD: postgres
64
- - name: Install dependencies
65
- run : AR_VERSION=${{ env.AR_VERSION }} bundle install
66
- - name: Run tests
78
+ - name: Run tests with mysql2
67
79
  run: |
68
80
  bundle exec rake test:mysql2
69
81
  bundle exec rake test:mysql2_makara
70
82
  bundle exec rake test:mysql2spatial
83
+ - name: Run tests with postgresql
84
+ run: |
71
85
  bundle exec rake test:postgis
72
86
  bundle exec rake test:postgresql
73
87
  bundle exec rake test:postgresql_makara
88
+ - name: Run tests with seamless_database_pool
89
+ run: |
74
90
  bundle exec rake test:seamless_database_pool
91
+ if: ${{ matrix.ruby < '3.0' }}
92
+ - name: Run tests with sqlite
93
+ run: |
75
94
  bundle exec rake test:spatialite
76
95
  bundle exec rake test:sqlite3
96
+ lint:
97
+ runs-on: ubuntu-latest
98
+ env:
99
+ AR_VERSION: '7.0'
100
+ steps:
101
+ - uses: actions/checkout@v2
102
+ - uses: ruby/setup-ruby@v1
103
+ with:
104
+ ruby-version: 2.7
105
+ bundler-cache: true
77
106
  - name: Run Rubocop
78
107
  run: bundle exec rubocop
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Changes in 1.4.0
2
+
3
+ ### New Features
4
+
5
+ * Enable compatibility with frozen string literals. Thanks to @desheikh via \##760.
6
+
1
7
  ## Changes in 1.3.0
2
8
 
3
9
  ### Fixes
data/Gemfile CHANGED
@@ -22,7 +22,8 @@ platforms :ruby do
22
22
  gem "mysql2", "~> #{mysql2_version}"
23
23
  gem "pg", "~> #{pg_version}"
24
24
  gem "sqlite3", "~> #{sqlite3_version}"
25
- gem "seamless_database_pool", "~> 1.0.20"
25
+ # seamless_database_pool requires Ruby ~> 2.0
26
+ gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
26
27
  end
27
28
 
28
29
  platforms :jruby do
@@ -44,14 +45,9 @@ platforms :jruby do
44
45
  gem "ruby-debug", "= 0.10.4"
45
46
  end
46
47
 
47
- platforms :mri_19 do
48
- gem "debugger"
49
- end
50
-
51
48
  platforms :ruby do
52
49
  gem "pry-byebug"
53
50
  gem "pry", "~> 0.12.0"
54
- gem "rb-readline"
55
51
  end
56
52
 
57
53
  if version >= 4.0
data/README.markdown CHANGED
@@ -433,7 +433,8 @@ Should you wish to specify those columns, you may use the option `timestamps: fa
433
433
 
434
434
  However, it is also possible to set just `:created_at` in specific records. In this case despite using `timestamps: true`, `:created_at` will be updated only in records where that field is `nil`. Same rule applies for record associations when enabling the option `recursive: true`.
435
435
 
436
- If you are using custom time zones, these will be respected when performing imports as well as long as `ActiveRecord::Base.default_timezone` is set, which for practically all Rails apps it is
436
+ If you are using custom time zones, these will be respected when performing imports as well as long as `ActiveRecord::Base.default_timezone` is set, which for practically all Rails apps it is.
437
+ NOTE: If you are using ActiveRecord 7.0 or later, please use `ActiveRecord.default_timezone` instead.
437
438
 
438
439
  ### Callbacks
439
440
 
@@ -572,7 +573,7 @@ When rubygems pushes the `lib` folder onto the load path a `require` will now fi
572
573
 
573
574
  Activerecord-Import adds the `.import` method onto `ActiveRecord::Base`. There are other gems, such as `elasticsearch-rails`, that do the same thing. In conflicts such as this, there is an aliased method named `.bulk_import` that can be used interchangeably.
574
575
 
575
- If you are using the `apartment` gem, there is a weird triple interaction between that gem, `activerecord-import`, and `activerecord` involving caching of the `sequence_name` of a model. This can be worked around by explcitly setting this value within the model. For example:
576
+ If you are using the `apartment` gem, there is a weird triple interaction between that gem, `activerecord-import`, and `activerecord` involving caching of the `sequence_name` of a model. This can be worked around by explicitly setting this value within the model. For example:
576
577
 
577
578
  ```ruby
578
579
  class Post < ActiveRecord::Base
@@ -615,13 +616,13 @@ After that, you can run the tests. They run against multiple tests and ActiveRec
615
616
 
616
617
  This is one example of how to run the tests:
617
618
 
618
- ```ruby
619
+ ```bash
619
620
  rm Gemfile.lock
620
- AR_VERSION=4.2 bundle install
621
- AR_VERSION=4.2 bundle exec rake test:postgresql test:sqlite3 test:mysql2
621
+ AR_VERSION=7.0 bundle install
622
+ AR_VERSION=7.0 bundle exec rake test:postgresql test:sqlite3 test:mysql2
622
623
  ```
623
624
 
624
- Once you have pushed up your changes, you can find your CI results [here](https://travis-ci.org/zdennis/activerecord-import/).
625
+ Once you have pushed up your changes, you can find your CI results [here](https://github.com/zdennis/activerecord-import/actions).
625
626
 
626
627
  ## Issue Triage [![Open Source Helpers](https://www.codetriage.com/zdennis/activerecord-import/badges/users.svg)](https://www.codetriage.com/zdennis/activerecord-import)
627
628
 
@@ -20,7 +20,11 @@ FileUtils.mkdir_p 'log'
20
20
  ActiveRecord::Base.configurations["test"] = YAML.load_file(File.join(benchmark_dir, "../test/database.yml"))[options.adapter]
21
21
  ActiveRecord::Base.logger = Logger.new("log/test.log")
22
22
  ActiveRecord::Base.logger.level = Logger::DEBUG
23
- ActiveRecord::Base.default_timezone = :utc
23
+ if ActiveRecord.respond_to?(:default_timezone)
24
+ ActiveRecord.default_timezone = :utc
25
+ else
26
+ ActiveRecord::Base.default_timezone = :utc
27
+ end
24
28
 
25
29
  require "activerecord-import"
26
30
  ActiveRecord::Base.establish_connection(:test)
data/gemfiles/7.0.gemfile CHANGED
@@ -1 +1 @@
1
- gem 'activerecord', '~> 7.0.0.alpha2'
1
+ gem 'activerecord', '~> 7.0.0'
@@ -82,7 +82,7 @@ module ActiveRecord::Import::MysqlAdapter
82
82
  # Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
83
83
  # in +args+.
84
84
  def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
85
- sql = ' ON DUPLICATE KEY UPDATE '
85
+ sql = ' ON DUPLICATE KEY UPDATE '.dup
86
86
  arg = args.first
87
87
  locking_column = args.last
88
88
  if arg.is_a?( Array )
@@ -123,7 +123,7 @@ module ActiveRecord::Import::PostgreSQLAdapter
123
123
  arg = { columns: arg } if arg.is_a?( Array ) || arg.is_a?( String )
124
124
  return unless arg.is_a?( Hash )
125
125
 
126
- sql = ' ON CONFLICT '
126
+ sql = ' ON CONFLICT '.dup
127
127
  conflict_target = sql_for_conflict_target( arg )
128
128
 
129
129
  columns = arg.fetch( :columns, [] )
@@ -179,9 +179,9 @@ module ActiveRecord::Import::PostgreSQLAdapter
179
179
  if constraint_name.present?
180
180
  "ON CONSTRAINT #{constraint_name} "
181
181
  elsif conflict_target.present?
182
- '(' << Array( conflict_target ).reject( &:blank? ).join( ', ' ) << ') '.tap do |sql|
183
- sql << "WHERE #{index_predicate} " if index_predicate
184
- end
182
+ sql = '(' + Array( conflict_target ).reject( &:blank? ).join( ', ' ) + ') '
183
+ sql += "WHERE #{index_predicate} " if index_predicate
184
+ sql
185
185
  end
186
186
  end
187
187
 
@@ -97,7 +97,7 @@ module ActiveRecord::Import::SQLite3Adapter
97
97
  arg = { columns: arg } if arg.is_a?( Array ) || arg.is_a?( String )
98
98
  return unless arg.is_a?( Hash )
99
99
 
100
- sql = ' ON CONFLICT '
100
+ sql = ' ON CONFLICT '.dup
101
101
  conflict_target = sql_for_conflict_target( arg )
102
102
 
103
103
  columns = arg.fetch( :columns, [] )
@@ -150,9 +150,9 @@ module ActiveRecord::Import::SQLite3Adapter
150
150
  conflict_target = args[:conflict_target]
151
151
  index_predicate = args[:index_predicate]
152
152
  if conflict_target.present?
153
- '(' << Array( conflict_target ).reject( &:blank? ).join( ', ' ) << ') '.tap do |sql|
154
- sql << "WHERE #{index_predicate} " if index_predicate
155
- end
153
+ sql = '(' + Array( conflict_target ).reject( &:blank? ).join( ', ' ) + ') '
154
+ sql += "WHERE #{index_predicate} " if index_predicate
155
+ sql
156
156
  end
157
157
  end
158
158
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "1.3.0".freeze
3
+ VERSION = "1.4.0".freeze
4
4
  end
5
5
  end
data/test/import_test.rb CHANGED
@@ -555,7 +555,11 @@ describe "#import" do
555
555
  context "when the timestamps columns are present" do
556
556
  setup do
557
557
  @existing_book = Book.create(title: "Fell", author_name: "Curry", publisher: "Bayer", created_at: 2.years.ago.utc, created_on: 2.years.ago.utc, updated_at: 2.years.ago.utc, updated_on: 2.years.ago.utc)
558
- ActiveRecord::Base.default_timezone = :utc
558
+ if ActiveRecord.respond_to?(:default_timezone)
559
+ ActiveRecord.default_timezone = :utc
560
+ else
561
+ ActiveRecord::Base.default_timezone = :utc
562
+ end
559
563
  Timecop.freeze(time) do
560
564
  assert_difference "Book.count", +2 do
561
565
  Book.import %w(title author_name publisher created_at created_on updated_at updated_on), [["LDAP", "Big Bird", "Del Rey", nil, nil, nil, nil], [@existing_book.title, @existing_book.author_name, @existing_book.publisher, @existing_book.created_at, @existing_book.created_on, @existing_book.updated_at, @existing_book.updated_on]]
@@ -281,7 +281,7 @@ def should_support_postgresql_import_functionality
281
281
  end
282
282
 
283
283
  describe "with binary field" do
284
- let(:binary_value) { "\xE0'c\xB2\xB0\xB3Bh\\\xC2M\xB1m\\I\xC4r".force_encoding('ASCII-8BIT') }
284
+ let(:binary_value) { "\xE0'c\xB2\xB0\xB3Bh\\\xC2M\xB1m\\I\xC4r".dup.force_encoding('ASCII-8BIT') }
285
285
  it "imports the correct values for binary fields" do
286
286
  alarms = [Alarm.new(device_id: 1, alarm_type: 1, status: 1, secret_key: binary_value)]
287
287
  assert_difference "Alarm.count", +1 do
data/test/test_helper.rb CHANGED
@@ -51,14 +51,22 @@ ActiveRecord::Base.logger = Logger.new("log/test.log")
51
51
  ActiveRecord::Base.logger.level = Logger::DEBUG
52
52
 
53
53
  if ENV['AR_VERSION'].to_f >= 6.0
54
- yaml_config = YAML.load_file(test_dir.join("database.yml"))[adapter]
54
+ yaml_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.2.1')
55
+ YAML.safe_load_file(test_dir.join("database.yml"), aliases: true)[adapter]
56
+ else
57
+ YAML.load_file(test_dir.join("database.yml"))[adapter]
58
+ end
55
59
  config = ActiveRecord::DatabaseConfigurations::HashConfig.new("test", adapter, yaml_config)
56
60
  ActiveRecord::Base.configurations.configurations << config
57
61
  else
58
62
  ActiveRecord::Base.configurations["test"] = YAML.load_file(test_dir.join("database.yml"))[adapter]
59
63
  end
60
64
 
61
- ActiveRecord::Base.default_timezone = :utc
65
+ if ActiveRecord.respond_to?(:default_timezone)
66
+ ActiveRecord.default_timezone = :utc
67
+ else
68
+ ActiveRecord::Base.default_timezone = :utc
69
+ end
62
70
 
63
71
  require "activerecord-import"
64
72
  ActiveRecord::Base.establish_connection :test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-17 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord