diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..aff5bb8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby: + - '2.6' + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ${{ matrix.ruby }} + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run tests + run: bundle exec rspec spec diff --git a/cursor_pagination.gemspec b/cursor_pagination.gemspec index 1c45ed2..6477c5c 100644 --- a/cursor_pagination.gemspec +++ b/cursor_pagination.gemspec @@ -17,8 +17,8 @@ Gem::Specification.new do |spec| spec.add_dependency "actionpack", ['>= 3.1'] spec.add_development_dependency "rspec-rails" spec.add_development_dependency "railties" - spec.add_development_dependency "capybara" - spec.add_development_dependency "sqlite3-ruby" + spec.add_development_dependency "capybara", '~> 2.18.0' + spec.add_development_dependency "sqlite3" spec.add_development_dependency "database_cleaner", ['< 1.1.0'] spec.files = `git ls-files`.split($/) @@ -26,6 +26,6 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "bundler" spec.add_development_dependency "rake" end diff --git a/lib/cursor_pagination/active_record_extension.rb b/lib/cursor_pagination/active_record_extension.rb index 1e0f2fd..3b85d18 100644 --- a/lib/cursor_pagination/active_record_extension.rb +++ b/lib/cursor_pagination/active_record_extension.rb @@ -12,7 +12,8 @@ def inherited_with_cursor_pagination(kls) #:nodoc: inherited_without_cursor_pagination kls kls.send(:include, CursorPagination::ActiveRecordModelExtension) if kls.superclass == ActiveRecord::Base end - alias_method_chain :inherited, :cursor_pagination + alias_method :inherited_without_cursor_pagination, :inherited + alias_method :inherited, :inherited_with_cursor_pagination end # Existing subclasses pick up the model extension as well diff --git a/spec/fake_app/active_record/config.rb b/spec/fake_app/active_record/config.rb deleted file mode 100644 index cf0ec88..0000000 --- a/spec/fake_app/active_record/config.rb +++ /dev/null @@ -1,3 +0,0 @@ -ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}} -ActiveRecord::Base.default_timezone = :utc -ActiveRecord::Base.establish_connection('test') diff --git a/spec/fake_app/active_record/database.yml b/spec/fake_app/active_record/database.yml new file mode 100644 index 0000000..1bc1088 --- /dev/null +++ b/spec/fake_app/active_record/database.yml @@ -0,0 +1,10 @@ +default: &default + adapter: sqlite3 + +development: + <<: *default + database: memory_development + +test: + <<: *default + database: memory_test diff --git a/spec/fake_app/active_record/models.rb b/spec/fake_app/active_record/models.rb index 77fefe7..9ef947b 100644 --- a/spec/fake_app/active_record/models.rb +++ b/spec/fake_app/active_record/models.rb @@ -4,8 +4,10 @@ class Entity < ActiveRecord::Base end #migrations -class CreateAllTables < ActiveRecord::Migration +class CreateAllTables < ActiveRecord::Migration[6.0] def self.up + return if ActiveRecord::Base.connection.table_exists? 'entities' + create_table :entities do |t| t.integer :custom t.datetime :custom_time diff --git a/spec/fake_app/rails.rb b/spec/fake_app/rails.rb index 5e1ef3d..3b18537 100644 --- a/spec/fake_app/rails.rb +++ b/spec/fake_app/rails.rb @@ -2,7 +2,15 @@ require 'action_controller/railtie' require 'action_view/railtie' -require 'fake_app/active_record/config' if defined? ActiveRecord +if defined? ActiveRecord + ActiveRecord::Base.establish_connection( + YAML.safe_load( + ERB.new( + File.read('spec/fake_app/active_record/database.yml') + ).result, [], [], true + )['test'] + ) +end # config app = Class.new(Rails::Application) diff --git a/spec/helpers/cursor_pagination_helper_spec.rb b/spec/helpers/cursor_pagination_helper_spec.rb index 2fab927..bbdfa86 100644 --- a/spec/helpers/cursor_pagination_helper_spec.rb +++ b/spec/helpers/cursor_pagination_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe CursorPagination::ActionViewHelper do +describe CursorPagination::ActionViewHelper, type: :helper do include_context "entities" diff --git a/spec/models/entity_spec.rb b/spec/models/entity_spec.rb index a1ecb84..c2cf207 100644 --- a/spec/models/entity_spec.rb +++ b/spec/models/entity_spec.rb @@ -159,7 +159,7 @@ context "with direct sql" do specify do - target_sql = "(\"entities\".\"id\" < 1 OR \"entities\".\"id\" = 1 AND (\"entities\".\"custom\" > 2 OR \"entities\".\"custom\" = 2 AND \"entities\".\"custom_time\" > '2013-09-02 14:32:42.000000'))" + target_sql = "(\"entities\".\"id\" < 1 OR \"entities\".\"id\" = 1 AND (\"entities\".\"custom\" > 2 OR \"entities\".\"custom\" = 2 AND \"entities\".\"custom_time\" > '2013-09-02 14:32:42'))" where = Entity.send(:_cursor_to_where, columns, cursor_value) where.to_sql.should eq target_sql end @@ -167,7 +167,7 @@ context "with reversed sql" do specify do - target_sql = "(\"entities\".\"id\" > 1 OR \"entities\".\"id\" = 1 AND (\"entities\".\"custom\" < 2 OR \"entities\".\"custom\" = 2 AND \"entities\".\"custom_time\" <= '2013-09-02 14:32:42.000000'))" + target_sql = "(\"entities\".\"id\" > 1 OR \"entities\".\"id\" = 1 AND (\"entities\".\"custom\" < 2 OR \"entities\".\"custom\" = 2 AND \"entities\".\"custom_time\" <= '2013-09-02 14:32:42'))" where = Entity.send(:_cursor_to_where, columns, cursor_value, true) where.to_sql.should eq target_sql end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0f52a11..5eda167 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,10 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + config.include Rails.application.routes.url_helpers + + config.include Capybara::DSL + config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus