Remove DataMapper support that has been extracted to kaminari-data_mapper gem

This commit is contained in:
Akira Matsuda 2016-06-02 21:22:44 +09:00
parent 623a7d96b8
commit de208a31c8
10 changed files with 0 additions and 358 deletions

View File

@ -17,7 +17,6 @@ gemfile:
- gemfiles/active_record_41.gemfile
- gemfiles/active_record_42.gemfile
- gemfiles/active_record_edge.gemfile
- gemfiles/data_mapper_12.gemfile
sudo: false

View File

@ -19,7 +19,6 @@ namespace :spec do
active_record_41
active_record_40
active_record_32
data_mapper_12
)
mappers.each do |gemfile|

View File

@ -1,36 +0,0 @@
source 'https://rubygems.org'
gem 'railties', '~> 3.2.21'
gem 'dm-core', '~> 1.2.0'
gem 'dm-migrations', '~> 1.2.0'
gem 'dm-aggregates', '~> 1.2.0'
gem 'dm-transactions', '~> 1.2.0'
gem 'dm-active_model', '~> 1.2.1'
gem 'dm-sqlite-adapter', '~> 1.2.0'
gem 'rspec-rails', '~> 2.14.1'
gem 'test-unit'
# stick to versions that work under Ruby 1.8 for now
gem 'capybara', '< 2.1'
gem 'nokogiri', '< 1.6'
gem 'rubyzip', '< 1'
gem 'mime-types', '< 2'
platforms :ruby do
if RUBY_VERSION > "2.1.0"
gem 'sqlite3'
else
gem 'sqlite3', '1.3.8'
end
end
platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.2.0'
end
platforms :rbx do
gem 'rubysl', '~> 2.0'
gem 'racc'
gem 'rubysl-test-unit'
gem 'rubinius-developer_tools'
end
gemspec :path => '../'

View File

@ -8,21 +8,6 @@ module Kaminari
::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension
end
# data_mapper
begin
require 'kaminari/data_mapper'
rescue LoadError
begin; require 'data_mapper'; rescue LoadError; end
if defined? ::DataMapper
ActiveSupport::Deprecation.warn 'Kaminari DataMapper support has been extracted to a separate gem, and will be removed in the next 1.0 release. Please bundle kaminari-data_mapper gem.'
require 'dm-aggregates'
require 'kaminari/models/data_mapper_extension'
::DataMapper::Collection.send :include, Kaminari::DataMapperExtension::Collection
::DataMapper::Model.append_extensions Kaminari::DataMapperExtension::Model
# ::DataMapper::Model.send :extend, Kaminari::DataMapperExtension::Model
end
end
require 'kaminari/models/array_extension'
ActiveSupport.on_load(:action_view) do

View File

@ -1,19 +0,0 @@
module Kaminari
module DataMapperCollectionMethods
def entry_name
model.model_name.human.downcase
end
def limit_value #:nodoc:
query.options[:limit] || 0
end
def offset_value #:nodoc:
query.options[:offset] || 0
end
def total_count #:nodoc:
model.count(query.options.except(:limit, :offset, :order))
end
end
end

View File

@ -1,51 +0,0 @@
require 'kaminari/models/data_mapper_collection_methods'
module Kaminari
module DataMapperExtension
module Paginatable
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{Kaminari.config.page_method_name}(num = 1)
model = self
model = self.model if self.is_a? DataMapper::Collection
num = [num.to_i, 1].max - 1
all(:limit => model.default_per_page, :offset => model.default_per_page * num).extend Paginating
end
RUBY
end
module Paginating
include Kaminari::PageScopeMethods
def all(options={})
super.extend Paginating
end
def per(num)
super.extend Paginating
end
end
module Collection
extend ActiveSupport::Concern
included do
include Kaminari::DataMapperCollectionMethods
include Paginatable
delegate :default_per_page, :max_per_page, :max_pages, :to => :model
end
end
module Model
include Kaminari::ConfigurationMethods::ClassMethods
include Paginatable
def limit(val)
all(:limit => val)
end
def offset(val)
all(:offset => val)
end
end
end
end

View File

@ -1 +0,0 @@
DataMapper.setup(:default, 'sqlite::memory:')

View File

@ -1,27 +0,0 @@
class User
include ::DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :age, Integer
has n, :projects, :through => Resource
end
class User::Address
include ::DataMapper::Resource
property :id, Serial
end
class Project
include ::DataMapper::Resource
property :id, Serial
property :name, String, :required => true
has n, :users, :through => Resource
end
DataMapper.finalize
DataMapper.auto_migrate!

View File

@ -1,205 +0,0 @@
require 'spec_helper'
if defined?(DataMapper) && !defined?(Kaminari::DataMapper)
# tests for issue #203
describe Kaminari::DataMapperCollectionMethods do
before do
30.times do |i|
User.create(:name => "User#{i}", :age => i)
end
end
describe 'Model' do
subject { User }
it { User.all.count.should == 30 }
it { User.page(1).length.should == 25 }
it {
User.paginates_per(5)
User.page(1).length.should == 5
User.all.page(1).length.should == 5
User.paginates_per(nil) # reset to default
}
end
end
describe Kaminari::DataMapperExtension do
before do
90.times do |i|
User.create(:name => "User#{i}", :age => i)
end
end
describe 'Collection' do
subject{ User.all }
it { should respond_to(:page) }
it { should_not respond_to(:per) }
end
describe 'Model' do
subject{ User }
it { should respond_to(:page) }
it { should respond_to(:default_per_page) }
it { should_not respond_to(:per) }
end
describe '#page' do
context 'page 0' do
subject { User.all(:age.gte => 60).page 0 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == User.count(:age.gte => 60) }
its(:total_pages) { should == 2 }
end
context 'page 1' do
subject { User.all(:age.gte => 0).page 1 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 4 }
end
context 'page 2' do
subject { User.page 2 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should == 3 }
its(:limit_value) { should == 25 }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 4 }
end
context 'page "foobar"' do
subject { User.page 'foobar' }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 4 }
end
context 'with criteria before' do
subject { User.all(:age.gt => 60).page 2 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == User.count(:age.gt => 60) }
its(:total_pages) { should == 2 }
end
context 'with criteria after' do
subject { User.page(2).all(:age.gt => 60) }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == User.count(:age.gt => 60) }
its(:total_pages) { should == 2 }
end
end
describe '#per' do
context 'on simple query' do
subject { User.page(2).per(20) }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should == 3 }
its('query.limit') { should == 20 }
its(:limit_value) { should == 20 }
its('query.offset') { should == 20 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 5 }
end
context 'on query with condition' do
subject { User.page(5).all(:age.lte => 80).per(13) }
its(:current_page) { should == 5 }
its(:prev_page) { should == 4 }
its(:next_page) { should == 6 }
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
its(:total_count) { should == 81 }
its(:total_pages) { should == 7 }
end
context 'on query with order' do
subject { User.page(5).all(:age.lte => 80, :order => [:age.asc]).per(13) }
it('includes user with age 52') { should include(User.first(:age => 52)) }
it('does not include user with age 51') { should_not include(User.first(:age => 51)) }
it('includes user with age 52') { should include(User.first(:age => 64)) }
it('does not include user with age 51') { should_not include(User.first(:age => 65)) }
its(:current_page) { should == 5 }
its(:prev_page) { should == 4 }
its(:next_page) { should == 6 }
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
its(:total_count) { should == 81 }
its(:total_pages) { should == 7 }
end
context 'on chained queries' do
subject { User.all(:age.gte => 50).page(3).all(:age.lte => 80).per(13) }
its(:current_page) { should == 3 }
its(:prev_page) { should == 2 }
its(:next_page) { should be_nil }
its('query.limit') { should == 13 }
its('query.offset') { should == 26 }
its(:total_count) { should == 31 }
its(:total_pages) { should == 3 }
end
context 'for association' do
before do
worker0 = User[0]
30.times do |i|
worker0.projects << Project.create(:name => "Project#{i}")
end
worker0.projects.save
end
context 'on query' do
subject { User[0].projects.page(3).all(:name.like => 'Project%').per(5) }
its(:current_page) { should == 3 }
its(:prev_page) { should == 2 }
its(:next_page) { should == 4 }
its('query.limit') { should == 5 }
its('query.offset') { should == 10 }
its(:total_count) { should == 30 }
its(:total_pages) { should == 6 }
end
context 'after association conditions' do
subject { User.page(3).all(:projects => Project.all).per(5) }
its(:current_page) { should == 3 }
its(:prev_page) { should == 2 }
its(:next_page) { should == 4 }
its('query.limit') { should == 5 }
its('query.offset') { should == 10 }
its(:total_count) { should == 30 }
its(:total_pages) { should == 6 }
end
end
end
end
end

View File

@ -1,10 +1,8 @@
DatabaseCleaner[:active_record].strategy = :transaction if defined? ActiveRecord
DatabaseCleaner[:data_mapper].strategy = :truncation if defined? DataMapper
RSpec.configure do |config|
config.before :suite do
DatabaseCleaner.clean_with :truncation if defined? ActiveRecord
DatabaseCleaner.clean_with :truncation if defined? DataMapper
end
config.before :each do
DatabaseCleaner.start