diff --git a/.travis.yml b/.travis.yml index 673c01b..ee49a0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 2.2.1 + - 2.2.10 - 2.5.5 - 2.6.3 matrix: diff --git a/Gemfile b/Gemfile index d833204..0c8b775 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gemspec gem 'jruby-openssl', :platform => :jruby group :test do - gem 'activerecord', '~> 4.2.0' + gem 'activerecord', '~> 5.2.0' gem 'activerecord-jdbcsqlite3-adapter', :platform => [:jruby] gem 'libxml-ruby', :platform => [:ruby, :mswin] gem 'rake' @@ -13,7 +13,7 @@ group :test do gem 'redcarpet', :platform => :ruby # For fast, Github-like Markdown gem 'kramdown', :platform => :jruby # For Markdown without a C compiler gem 'test-unit' - # This version of sqlite3 required for activerecord 4.2, not more recent. - # When bumping AR, may have to/want to adjust this to more recent versions. - gem 'sqlite3', "~> 1.3.0", :platform => [:ruby, :mswin] + + # This version of sqlite3 oughta be good for activerecord 5.1+ hopefully + gem 'sqlite3', ">= 1.4.0", "< 2.0", :platform => [:ruby, :mswin] end diff --git a/lib/oai/provider/model/activerecord_caching_wrapper.rb b/lib/oai/provider/model/activerecord_caching_wrapper.rb index 5b1de80..4679f07 100755 --- a/lib/oai/provider/model/activerecord_caching_wrapper.rb +++ b/lib/oai/provider/model/activerecord_caching_wrapper.rb @@ -90,17 +90,16 @@ def next_set(token_string) # select a subset of the result set, and return it with a # resumption token to get the next subset def select_partial(token) - if 0 == token.last - oaitoken = OaiToken.find_or_create_by(token: token.to_s) - if oaitoken.new_record_before_save? - OaiToken.connection.execute("insert into " + - "#{OaiEntry.table_name} (oai_token_id, record_id) " + - "select #{oaitoken.id}, id from #{model.table_name} where " + - "#{OaiToken.sanitize_sql(token_conditions(token))}") - end + oaitoken = OaiToken.find_by(token: token.to_s) + + if 0 == token.last && oaitoken.nil? + oaitoken = OaiToken.create!(token: token.to_s) + OaiToken.connection.execute("insert into " + + "#{OaiEntry.table_name} (oai_token_id, record_id) " + + "select #{oaitoken.id}, id from #{model.table_name} where " + + "#{OaiToken.sanitize_sql(token_conditions(token))}") end - oaitoken = OaiToken.find_by_token(token.to_s) raise ResumptionTokenException.new unless oaitoken PartialResult.new( @@ -111,7 +110,7 @@ def select_partial(token) end def sweep_cache - OaiToken.destroy_all(["created_at < ?", Time.now - expire]) + OaiToken.where(["created_at < ?", Time.now - expire]).destroy_all end def hydrate_records(records) diff --git a/test/activerecord_provider/config/connection.rb b/test/activerecord_provider/config/connection.rb index 0849ff5..ed99721 100755 --- a/test/activerecord_provider/config/connection.rb +++ b/test/activerecord_provider/config/connection.rb @@ -12,4 +12,7 @@ ActiveRecord::Migration.verbose = false ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" -ActiveRecord::Migrator.up File.join(File.dirname(__FILE__), '..', 'database') + +ActiveRecord::MigrationContext.new(File.join(File.dirname(__FILE__), '..', 'database')).migrate + + diff --git a/test/activerecord_provider/database/0001_oaipmh_tables.rb b/test/activerecord_provider/database/0001_oaipmh_tables.rb index 0cbad06..ce85642 100755 --- a/test/activerecord_provider/database/0001_oaipmh_tables.rb +++ b/test/activerecord_provider/database/0001_oaipmh_tables.rb @@ -1,4 +1,4 @@ -class OaipmhTables < ActiveRecord::Migration +class OaipmhTables < ActiveRecord::Migration[4.2] def self.up create_table :oai_tokens do |t| t.column :token, :string, :null => false diff --git a/test/activerecord_provider/models/exclusive_set_dc_field.rb b/test/activerecord_provider/models/exclusive_set_dc_field.rb index 45f9079..31b5cc1 100644 --- a/test/activerecord_provider/models/exclusive_set_dc_field.rb +++ b/test/activerecord_provider/models/exclusive_set_dc_field.rb @@ -3,7 +3,7 @@ class ExclusiveSetDCField < ActiveRecord::Base def self.sets klass = Struct.new(:name, :spec) - self.uniq.pluck('`set`').compact.map do |spec| + self.distinct.pluck(:set).compact.map do |spec| klass.new("Set #{spec}", spec) end end