activerecord-import 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4b90003ff135e948989e264283865779bd79024
4
- data.tar.gz: 30ef6b7700896f504f1dd99444d99b7ff712c62d
3
+ metadata.gz: 5d8742c99d2600b0f4e4c425ef0a427f46f5f220
4
+ data.tar.gz: 2c421e2f980400b03efc42f087bd68179edd5f78
5
5
  SHA512:
6
- metadata.gz: 840e755ed27b5f2831c0340cbc7ceeced5ad674b79ea916c5d4b405c7608cf4f8791cae7b557aa513660addb94d9dfaf037d3d981b0fd84ec2a45ddeb048e02e
7
- data.tar.gz: cec3b8e8f94af62a68a72ba99c64404a920c11112a1cd21308ac350efb289cf4a2d7120ea5d5cc203f6b2533106d5be09ccf69765932f23ecec0137adc967724
6
+ metadata.gz: 092393e90fe7bebb3eed9a5c51aca467afe5b64d664d5b1888b25cc6b9c5e2cfdcdbd04505c736e22a4e8d40d9be0a5bd26f2c7f709213927d530f575b81d115
7
+ data.tar.gz: d130c2a565701477b2344599b267f0bc45f0f2e99f0bc88ac81e54f35b152993558d06340888a12a8245db963e51249b9885ba68d7532d01760c3c626e1f662f
data/.gitignore CHANGED
@@ -25,6 +25,7 @@ log/*.log
25
25
  test.db
26
26
  test/database.yml
27
27
 
28
+ .ruby-*
28
29
  .bundle/
29
30
  .redcar/
30
31
  .rvmrc
data/Gemfile CHANGED
@@ -13,7 +13,9 @@ end
13
13
 
14
14
  platforms :jruby do
15
15
  gem "jdbc-mysql"
16
+ gem "jdbc-postgres"
16
17
  gem "activerecord-jdbcmysql-adapter"
18
+ gem "activerecord-jdbcpostgresql-adapter"
17
19
  end
18
20
 
19
21
  # Support libs
data/LICENSE ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -18,6 +18,44 @@ Use activerecord-import 0.2.11. As of activerecord-import 0.3.0 we are relying o
18
18
 
19
19
  For more information on activerecord-import please see its wiki: https://github.com/zdennis/activerecord-import/wiki
20
20
 
21
+ ## Additional Adapters
22
+ Additional adapters can be provided by gems external to activerecord-import by providing an adapter that matches the naming convention setup by activerecord-import (and subsequently activerecord) for dynamically loading adapters. This involves also providing a folder on the load path that follows the activerecord-import naming convention to allow activerecord-import to dynamically load the file.
23
+
24
+ When `ActiveRecord::Import.require_adapter("fake_name")` is called the require will be:
25
+
26
+ ```ruby
27
+ require 'activerecord-import/active_record/adapters/fake_name_adapter'
28
+ ```
29
+
30
+ This allows an external gem to dyanmically add an adapter without the need to add any file/code to the core activerecord-import gem.
31
+
32
+ ### Load Path Setup
33
+ To understand how rubygems loads code you can reference the following:
34
+
35
+ http://guides.rubygems.org/patterns/#loading_code
36
+
37
+ And an example of how active_record dynamically load adapters:
38
+ https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/connection_specification.rb
39
+
40
+ In summary, when a gem is loaded rubygems adds the `lib` folder of the gem to the global load path `$LOAD_PATH` so that all `require` lookups will not propegate through all of the folders on the load path. When a `require` is issued each folder on the `$LOAD_PATH` is checked for the file and/or folder referenced. This allows a gem (like activerecord-import) to define push the activerecord-import folder (or namespace) on the `$LOAD_PATH` and any adapters provided by activerecord-import will be found by rubygems when the require is issued.
41
+
42
+ If `fake_name` adapter is needed by a gem (potentially called `activerecord-import-fake_name`) then the folder structure should look as follows:
43
+
44
+ ```bash
45
+ activerecord-import-fake_name/
46
+ |-- activerecord-import-fake_name.gemspec
47
+ |-- lib
48
+ | |-- activerecord-import-fake_name
49
+ | | |-- version.rb
50
+ | |-- activerecord-import
51
+ | | |-- active_record
52
+ | | | |-- adapters
53
+ | | | |-- fake_name_adapter.rb
54
+ |--activerecord-import-fake_name.rb
55
+ ```
56
+
57
+ When rubygems pushes the `lib` folder onto the load path a `require` will now find `activerecord-import/active_record/adapters/fake_name_adapter` as it runs through the lookup process for a ruby file under that path in `$LOAD_PATH`
58
+
21
59
  # License
22
60
 
23
61
  This is licensed under the ruby license.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ namespace :display do
13
13
  end
14
14
  task :default => ["display:notice"]
15
15
 
16
- ADAPTERS = %w(mysql mysql2 em_mysql2 jdbcmysql postgresql sqlite3 seamless_database_pool mysqlspatial mysql2spatial spatialite postgis)
16
+ ADAPTERS = %w(mysql mysql2 em_mysql2 jdbcmysql jdbcpostgresql postgresql sqlite3 seamless_database_pool mysqlspatial mysql2spatial spatialite postgis)
17
17
  ADAPTERS.each do |adapter|
18
18
  namespace :test do
19
19
  desc "Runs #{adapter} database tests."
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.summary = "Bulk-loading extension for ActiveRecord"
8
8
  gem.description = "Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyond"
9
9
  gem.homepage = "http://github.com/zdennis/activerecord-import"
10
+ gem.license = "Ruby"
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -10,7 +10,8 @@ end
10
10
 
11
11
  ActiveSupport.on_load(:active_record_connection_established) do |connection_pool|
12
12
  if !ActiveRecord.const_defined?(:Import) || !ActiveRecord::Import.respond_to?(:load_from_connection_pool)
13
- require File.join File.dirname(__FILE__), "activerecord-import/base"
13
+ require "activerecord-import/base"
14
14
  end
15
+
15
16
  ActiveRecord::Import.load_from_connection_pool connection_pool
16
17
  end
@@ -0,0 +1,6 @@
1
+ require "active_record/connection_adapters/postgresql_adapter"
2
+ require "activerecord-import/adapters/postgresql_adapter"
3
+
4
+ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
5
+ include ActiveRecord::Import::PostgreSQLAdapter
6
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/mysql_adapter"
1
+ require "activerecord-import/adapters/mysql_adapter"
2
2
 
3
3
  module ActiveRecord::Import::EMMysql2Adapter
4
4
  include ActiveRecord::Import::MysqlAdapter
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + "/mysql_adapter"
1
+ require "activerecord-import/adapters/mysql_adapter"
2
2
 
3
3
  module ActiveRecord::Import::Mysql2Adapter
4
4
  include ActiveRecord::Import::MysqlAdapter
5
- end
5
+ end
@@ -3,7 +3,7 @@ require "active_record"
3
3
  require "active_record/version"
4
4
 
5
5
  module ActiveRecord::Import
6
- AdapterPath = File.join File.expand_path(File.dirname(__FILE__)), "/active_record/adapters"
6
+ AdapterPath = "activerecord-import/active_record/adapters"
7
7
 
8
8
  def self.base_adapter(adapter)
9
9
  case adapter
@@ -18,7 +18,11 @@ module ActiveRecord::Import
18
18
  # Loads the import functionality for a specific database adapter
19
19
  def self.require_adapter(adapter)
20
20
  require File.join(AdapterPath,"/abstract_adapter")
21
- require File.join(AdapterPath,"/#{base_adapter(adapter)}_adapter")
21
+ begin
22
+ require File.join(AdapterPath,"/#{base_adapter(adapter)}_adapter")
23
+ rescue LoadError
24
+ # fallback
25
+ end
22
26
  end
23
27
 
24
28
  # Loads the import functionality for the passed in ActiveRecord connection
@@ -27,9 +31,7 @@ module ActiveRecord::Import
27
31
  end
28
32
  end
29
33
 
30
-
31
- this_dir = Pathname.new File.dirname(__FILE__)
32
- require this_dir.join("import").to_s
33
- require this_dir.join("active_record/adapters/abstract_adapter").to_s
34
- require this_dir.join("synchronize").to_s
35
- require this_dir.join("value_sets_parser").to_s
34
+ require 'activerecord-import/import'
35
+ require 'activerecord-import/active_record/adapters/abstract_adapter'
36
+ require 'activerecord-import/synchronize'
37
+ require 'activerecord-import/value_sets_parser'
@@ -4,4 +4,4 @@ warn <<-MSG
4
4
  http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
5
5
  MSG
6
6
 
7
- require File.expand_path(File.join(File.dirname(__FILE__), "/../activerecord-import"))
7
+ require "activerecord-import"
@@ -370,7 +370,7 @@ class ActiveRecord::Base
370
370
 
371
371
  if supports_on_duplicate_key_update?
372
372
  if options[:on_duplicate_key_update]
373
- options[:on_duplicate_key_update] << key.to_sym if options[:on_duplicate_key_update].is_a?(Array)
373
+ options[:on_duplicate_key_update] << key.to_sym if options[:on_duplicate_key_update].is_a?(Array) && !options[:on_duplicate_key_update].include?(key.to_sym)
374
374
  options[:on_duplicate_key_update][key.to_sym] = key.to_sym if options[:on_duplicate_key_update].is_a?(Hash)
375
375
  else
376
376
  options[:on_duplicate_key_update] = [ key.to_sym ]
@@ -4,5 +4,4 @@ warn <<-MSG
4
4
  http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
5
5
  MSG
6
6
 
7
- require File.expand_path(File.join(File.dirname(__FILE__), "/../activerecord-import"))
8
-
7
+ require "activerecord-import"
@@ -4,5 +4,4 @@ warn <<-MSG
4
4
  http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
5
5
  MSG
6
6
 
7
- require File.expand_path(File.join(File.dirname(__FILE__), "/../activerecord-import"))
8
-
7
+ require "activerecord-import"
@@ -4,5 +4,4 @@ warn <<-MSG
4
4
  http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
5
5
  MSG
6
6
 
7
- require File.expand_path(File.join(File.dirname(__FILE__), "/../activerecord-import"))
8
-
7
+ require "activerecord-import"
@@ -4,5 +4,4 @@ warn <<-MSG
4
4
  http://github.com/zdennis/activerecord-import/wiki/Requiring for more information
5
5
  MSG
6
6
 
7
- require File.expand_path(File.join(File.dirname(__FILE__), "/../activerecord-import"))
8
-
7
+ require "activerecord-import"
@@ -44,6 +44,7 @@ module ActiveRecord # :nodoc:
44
44
  instance.clear_association_cache
45
45
  instance.instance_variable_set '@attributes', matched_instance.attributes
46
46
  instance.instance_variable_set '@attributes_cache', {}
47
+ instance.changed_attributes.clear
47
48
  # Since the instance now accurately reflects the record in
48
49
  # the database, ensure that instance.persisted? is true.
49
50
  instance.instance_variable_set '@new_record', false
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ ENV["ARE_DB"] = "jdbcpostgresql"
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ #require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/assertions')
4
+ require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/import_examples')
5
+
6
+ should_support_postgresql_import_functionality
@@ -47,10 +47,10 @@ class ActiveSupport::TestCase
47
47
  alias_method :context, :describe
48
48
 
49
49
  def let(name, &blk)
50
- values = {}
51
50
  define_method(name) do
52
- return values[name] if values.has_key?(name)
53
- values[name] = instance_eval(&blk)
51
+ instance_variable_name = "@__let_#{name}"
52
+ return instance_variable_get(instance_variable_name) if instance_variable_defined?(instance_variable_name)
53
+ instance_variable_set(instance_variable_name, instance_eval(&blk))
54
54
  end
55
55
  end
56
56
 
@@ -12,11 +12,22 @@ describe ".synchronize" do
12
12
  end
13
13
 
14
14
  it "reloads data for the specified records" do
15
- Book.synchronize topics
15
+ Topic.synchronize topics
16
16
 
17
17
  actual_titles = topics.map(&:title)
18
18
  assert_equal "#{titles[0]}_haha", actual_titles[0], "the first record was not correctly updated"
19
19
  assert_equal "#{titles[1]}_haha", actual_titles[1], "the second record was not correctly updated"
20
20
  assert_equal "#{titles[2]}_haha", actual_titles[2], "the third record was not correctly updated"
21
21
  end
22
+
23
+ it "the synchronized records aren't dirty" do
24
+ # Update the in memory records so they're dirty
25
+ topics.each { |topic| topic.title = 'dirty title' }
26
+
27
+ Topic.synchronize topics
28
+
29
+ assert_equal false, topics[0].changed?, "the first record was dirty"
30
+ assert_equal false, topics[1].changed?, "the second record was dirty"
31
+ assert_equal false, topics[2].changed?, "the third record was dirty"
32
+ end
22
33
  end
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
 
6
6
  require "fileutils"
7
7
 
8
- ENV["AR_ENV"] = "test"
8
+ ENV["RAILS_ENV"] = "test"
9
9
 
10
10
  require "bundler"
11
11
  Bundler.setup
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: 0.4.1
4
+ version: 0.5.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: 2013-07-22 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -49,6 +49,7 @@ files:
49
49
  - .gitignore
50
50
  - Brewfile
51
51
  - Gemfile
52
+ - LICENSE
52
53
  - README.markdown
53
54
  - Rakefile
54
55
  - activerecord-import.gemspec
@@ -72,6 +73,7 @@ files:
72
73
  - lib/activerecord-import/active_record/adapters/abstract_adapter.rb
73
74
  - lib/activerecord-import/active_record/adapters/em_mysql2_adapter.rb
74
75
  - lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb
76
+ - lib/activerecord-import/active_record/adapters/jdbcpostgresql_adapter.rb
75
77
  - lib/activerecord-import/active_record/adapters/mysql2_adapter.rb
76
78
  - lib/activerecord-import/active_record/adapters/mysql_adapter.rb
77
79
  - lib/activerecord-import/active_record/adapters/postgresql_adapter.rb
@@ -95,6 +97,7 @@ files:
95
97
  - lib/activerecord-import/version.rb
96
98
  - test/adapters/em_mysql2.rb
97
99
  - test/adapters/jdbcmysql.rb
100
+ - test/adapters/jdbcpostgresql.rb
98
101
  - test/adapters/mysql.rb
99
102
  - test/adapters/mysql2.rb
100
103
  - test/adapters/mysql2spatial.rb
@@ -108,6 +111,7 @@ files:
108
111
  - test/em_mysql2/import_test.rb
109
112
  - test/import_test.rb
110
113
  - test/jdbcmysql/import_test.rb
114
+ - test/jdbcpostgresql/import_test.rb
111
115
  - test/models/book.rb
112
116
  - test/models/group.rb
113
117
  - test/models/topic.rb
@@ -133,7 +137,8 @@ files:
133
137
  - test/value_sets_bytes_parser_test.rb
134
138
  - test/value_sets_records_parser_test.rb
135
139
  homepage: http://github.com/zdennis/activerecord-import
136
- licenses: []
140
+ licenses:
141
+ - Ruby
137
142
  metadata: {}
138
143
  post_install_message:
139
144
  rdoc_options: []
@@ -151,13 +156,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
156
  version: '0'
152
157
  requirements: []
153
158
  rubyforge_project:
154
- rubygems_version: 2.0.3
159
+ rubygems_version: 2.2.1
155
160
  signing_key:
156
161
  specification_version: 4
157
162
  summary: Bulk-loading extension for ActiveRecord
158
163
  test_files:
159
164
  - test/adapters/em_mysql2.rb
160
165
  - test/adapters/jdbcmysql.rb
166
+ - test/adapters/jdbcpostgresql.rb
161
167
  - test/adapters/mysql.rb
162
168
  - test/adapters/mysql2.rb
163
169
  - test/adapters/mysql2spatial.rb
@@ -171,6 +177,7 @@ test_files:
171
177
  - test/em_mysql2/import_test.rb
172
178
  - test/import_test.rb
173
179
  - test/jdbcmysql/import_test.rb
180
+ - test/jdbcpostgresql/import_test.rb
174
181
  - test/models/book.rb
175
182
  - test/models/group.rb
176
183
  - test/models/topic.rb