Skip to content

Commit 5cf2baa

Browse files
authored
Merge pull request #64 from code4lib/update_tested_active_record
Have things working and tests passing on ActiveRecord 5.2
2 parents 36eab57 + ad05502 commit 5cf2baa

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: ruby
22
rvm:
3-
- 2.2.1
3+
- 2.2.10
44
- 2.5.5
55
- 2.6.3
66
matrix:

Gemfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ gemspec
55
gem 'jruby-openssl', :platform => :jruby
66

77
group :test do
8-
gem 'activerecord', '~> 4.2.0'
8+
gem 'activerecord', '~> 5.2.0'
99
gem 'activerecord-jdbcsqlite3-adapter', :platform => [:jruby]
1010
gem 'libxml-ruby', :platform => [:ruby, :mswin]
1111
gem 'rake'
1212
gem 'yard'
1313
gem 'redcarpet', :platform => :ruby # For fast, Github-like Markdown
1414
gem 'kramdown', :platform => :jruby # For Markdown without a C compiler
1515
gem 'test-unit'
16-
# This version of sqlite3 required for activerecord 4.2, not more recent.
17-
# When bumping AR, may have to/want to adjust this to more recent versions.
18-
gem 'sqlite3', "~> 1.3.0", :platform => [:ruby, :mswin]
16+
17+
# This version of sqlite3 oughta be good for activerecord 5.1+ hopefully
18+
gem 'sqlite3', ">= 1.4.0", "< 2.0", :platform => [:ruby, :mswin]
1919
end

lib/oai/provider/model/activerecord_caching_wrapper.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,16 @@ def next_set(token_string)
9090
# select a subset of the result set, and return it with a
9191
# resumption token to get the next subset
9292
def select_partial(token)
93-
if 0 == token.last
94-
oaitoken = OaiToken.find_or_create_by(token: token.to_s)
95-
if oaitoken.new_record_before_save?
96-
OaiToken.connection.execute("insert into " +
97-
"#{OaiEntry.table_name} (oai_token_id, record_id) " +
98-
"select #{oaitoken.id}, id from #{model.table_name} where " +
99-
"#{OaiToken.sanitize_sql(token_conditions(token))}")
100-
end
93+
oaitoken = OaiToken.find_by(token: token.to_s)
94+
95+
if 0 == token.last && oaitoken.nil?
96+
oaitoken = OaiToken.create!(token: token.to_s)
97+
OaiToken.connection.execute("insert into " +
98+
"#{OaiEntry.table_name} (oai_token_id, record_id) " +
99+
"select #{oaitoken.id}, id from #{model.table_name} where " +
100+
"#{OaiToken.sanitize_sql(token_conditions(token))}")
101101
end
102102

103-
oaitoken = OaiToken.find_by_token(token.to_s)
104103
raise ResumptionTokenException.new unless oaitoken
105104

106105
PartialResult.new(
@@ -111,7 +110,7 @@ def select_partial(token)
111110
end
112111

113112
def sweep_cache
114-
OaiToken.destroy_all(["created_at < ?", Time.now - expire])
113+
OaiToken.where(["created_at < ?", Time.now - expire]).destroy_all
115114
end
116115

117116
def hydrate_records(records)

test/activerecord_provider/config/connection.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
ActiveRecord::Migration.verbose = false
1313
ActiveRecord::Base.establish_connection :adapter => "sqlite3",
1414
:database => ":memory:"
15-
ActiveRecord::Migrator.up File.join(File.dirname(__FILE__), '..', 'database')
15+
16+
ActiveRecord::MigrationContext.new(File.join(File.dirname(__FILE__), '..', 'database')).migrate
17+
18+

test/activerecord_provider/database/0001_oaipmh_tables.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class OaipmhTables < ActiveRecord::Migration
1+
class OaipmhTables < ActiveRecord::Migration[4.2]
22
def self.up
33
create_table :oai_tokens do |t|
44
t.column :token, :string, :null => false

test/activerecord_provider/models/exclusive_set_dc_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class ExclusiveSetDCField < ActiveRecord::Base
33

44
def self.sets
55
klass = Struct.new(:name, :spec)
6-
self.uniq.pluck('`set`').compact.map do |spec|
6+
self.distinct.pluck(:set).compact.map do |spec|
77
klass.new("Set #{spec}", spec)
88
end
99
end

0 commit comments

Comments
 (0)