Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

Added CI #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions cursor_pagination.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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
3 changes: 2 additions & 1 deletion lib/cursor_pagination/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions spec/fake_app/active_record/config.rb

This file was deleted.

10 changes: 10 additions & 0 deletions spec/fake_app/active_record/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
default: &default
adapter: sqlite3

development:
<<: *default
database: memory_development

test:
<<: *default
database: memory_test
4 changes: 3 additions & 1 deletion spec/fake_app/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/fake_app/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/cursor_pagination_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe CursorPagination::ActionViewHelper do
describe CursorPagination::ActionViewHelper, type: :helper do

include_context "entities"

Expand Down
4 changes: 2 additions & 2 deletions spec/models/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@

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
end

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
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down