Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Mongoid 3.0.0 compatibility #6

Merged
merged 1 commit into from

3 participants

@nightscape

Hi Kristian,

I've updated acts_as_list_mongoid to be compatible with Mongoid 3.0.0.
Unfortunately Mongoid 2.x compatibility is lost by that, that's why I've also bumped the version to 0.3.0.
I think with some hacking, one could make the gem and the tests compatible with both versions, but right now we're only using Mongoid 3.0.0 and I don't have too much time digging into this.

Best regards
Martin

@kristianmandrup kristianmandrup merged commit a88f2c3 into kristianmandrup:master
@brandonjmckay

Any examples on how to use this for Mongoid 3? The include mentioned in the docs looks wrong compared to other includes I've made in 3, and what do we put in the gemfile to get the number 3 compatability?

Cheers,
-Brandon

@brandonjmckay

PS. I'm trying:
gem 'acts_as_list_mongoid', '~> 0.3.0', :git => "git://github.com/kristianmandrup/acts_as_list_mongoid.git"

Seems to have installed, but I get an uninitialized constant error when defining it in my model.
Is the right way to define it in the model?

  include ActsAsList::Mongoid.default_position_column = :position
  include ActsAsList::Mongoid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 10, 2012
  1. Mongoid 3.0.0 compatible.

    Martin Mauch authored
This page is out of date. Refresh to see the latest.
View
3  .gitignore
@@ -3,4 +3,5 @@ pkg
.bundle
vendor
Gemfile.lock
-*/.DS_Store
+*/.DS_Store
+/coverage/
View
5 Gemfile
@@ -1,17 +1,16 @@
source :rubygems
-gem 'mongoid', '>= 2.0.1'
+gem 'mongoid', '>= 3.0.0'
gem "mongoid_embedded_helper", '>= 0.2.5'
group :test, :development do
gem "cutter", ">= 0"
gem "shoulda", ">= 0"
- gem 'bson_ext', '>= 1.5.1'
gem "rspec", ">= 2.5"
end
group :development do
gem "bundler", ">= 1.0.10"
gem "jeweler", ">= 1.6.4"
- gem "rcov", ">= 0"
+ gem "simplecov", ">= 0"
end
View
24 Rakefile
@@ -25,24 +25,20 @@ Jeweler::Tasks.new do |gem|
end
Jeweler::RubygemsDotOrgTasks.new
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
-end
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
- test.rcov_opts << '--exclude "gems/*"'
+desc "Run RSpec with code coverage"
+task :coverage do
+ ENV['COVERAGE'] = "true"
+ Rake::Task[:spec].execute
end
-task :default => :test
-require 'rake/rdoctask'
+require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
View
2  VERSION
@@ -1 +1 @@
-0.2.5.1
+0.3.0
View
36 acts_as_list_mongoid.gemspec
@@ -4,15 +4,14 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{acts_as_list_mongoid}
- s.version = "0.2.5.1"
+ s.name = "acts_as_list_mongoid"
+ s.version = "0.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{Kristian Mandrup}]
- s.date = %q{2012-01-19}
- s.description = %q{Make your Mongoid model acts as a list. This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list.
- The instances that take part in the list should have a +position+ field of type Integer.}
- s.email = %q{kmandrup@gmail.com}
+ s.authors = ["Kristian Mandrup"]
+ s.date = "2012-07-10"
+ s.description = "Make your Mongoid model acts as a list. This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list.\n The instances that take part in the list should have a +position+ field of type Integer."
+ s.email = "kmandrup@gmail.com"
s.extra_rdoc_files = [
"README.markdown"
]
@@ -35,45 +34,42 @@ Gem::Specification.new do |s|
"spec/acts_as_list/referenced_category_spec.rb",
"spec/spec_helper.rb"
]
- s.homepage = %q{http://github.com/rails/acts_as_list}
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{1.8.6}
- s.summary = %q{acts_as_list for Mongoid}
+ s.homepage = "http://github.com/rails/acts_as_list"
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.24"
+ s.summary = "acts_as_list for Mongoid"
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<mongoid>, [">= 2.0.1"])
+ s.add_runtime_dependency(%q<mongoid>, [">= 3.0.0"])
s.add_runtime_dependency(%q<mongoid_embedded_helper>, [">= 0.2.5"])
s.add_development_dependency(%q<cutter>, [">= 0"])
s.add_development_dependency(%q<shoulda>, [">= 0"])
- s.add_development_dependency(%q<bson_ext>, [">= 1.5.1"])
s.add_development_dependency(%q<rspec>, [">= 2.5"])
s.add_development_dependency(%q<bundler>, [">= 1.0.10"])
s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
- s.add_development_dependency(%q<rcov>, [">= 0"])
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
else
- s.add_dependency(%q<mongoid>, [">= 2.0.1"])
+ s.add_dependency(%q<mongoid>, [">= 3.0.0"])
s.add_dependency(%q<mongoid_embedded_helper>, [">= 0.2.5"])
s.add_dependency(%q<cutter>, [">= 0"])
s.add_dependency(%q<shoulda>, [">= 0"])
- s.add_dependency(%q<bson_ext>, [">= 1.5.1"])
s.add_dependency(%q<rspec>, [">= 2.5"])
s.add_dependency(%q<bundler>, [">= 1.0.10"])
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
- s.add_dependency(%q<rcov>, [">= 0"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
end
else
- s.add_dependency(%q<mongoid>, [">= 2.0.1"])
+ s.add_dependency(%q<mongoid>, [">= 3.0.0"])
s.add_dependency(%q<mongoid_embedded_helper>, [">= 0.2.5"])
s.add_dependency(%q<cutter>, [">= 0"])
s.add_dependency(%q<shoulda>, [">= 0"])
- s.add_dependency(%q<bson_ext>, [">= 1.5.1"])
s.add_dependency(%q<rspec>, [">= 2.5"])
s.add_dependency(%q<bundler>, [">= 1.0.10"])
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
- s.add_dependency(%q<rcov>, [">= 0"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
end
end
View
6 lib/mongoid/acts_as_list.rb
@@ -104,7 +104,11 @@ def move command
def order_by_position conditions, extras = []
sub_collection = in_collection.where(conditions)
sub_collection = if embedded?
- sub_collection.sort { |x,y| x.my_position <=> y.my_position }
+ if sub_collection.method(:sort).arity == 0
+ sub_collection.sort { |x,y| x.my_position <=> y.my_position }
+ else
+ sub_collection.sort(:my_position => 1)
+ end
else
sub_collection.order_by(position_key.to_sym.asc)
end
View
4 model/referenced_category.rb
@@ -11,8 +11,8 @@ class Category
#many should below in, or we will get:
#NoMethodError:
# undefined method `entries' for #<Category:0x9acbaa8>
- referenced_in :category
- references_many :categories
+ belongs_to :category
+ has_many :categories
def scope_condition
{:category_id => category.id, :pos.ne => nil}
View
9 mongoid.yml
@@ -0,0 +1,9 @@
+test:
+ sessions:
+ default:
+ hosts:
+ - localhost:27017
+ database: acts_as_list_test
+
+
+
View
4 spec/acts_as_list/embedded_item_spec.rb
@@ -17,9 +17,7 @@
end
after :each do
- Mongoid.database.collections.each do |coll|
- coll.remove
- end
+ List.mongo_session.drop
end
def get_positions list
View
4 spec/acts_as_list/referenced_category_spec.rb
@@ -17,9 +17,7 @@
end
after :each do
- Mongoid.database.collections.each do |coll|
- coll.remove
- end
+ Category.mongo_session.drop
end
def get_positions(category)
View
9 spec/spec_helper.rb
@@ -1,3 +1,8 @@
+if ENV['COVERAGE']
+ require 'simplecov'
+ SimpleCov.start
+end
+
require 'rspec'
require 'rspec/autorun'
require 'mongoid'
@@ -7,7 +12,7 @@
$:.unshift "#{File.dirname(__FILE__)}/../model/"
-
-Mongoid.configure.master = Mongo::Connection.new.db('acts_as_list-test')
+ENV["MONGOID_ENV"]="test"
+Mongoid.load! "#{File.dirname(__FILE__)}/../mongoid.yml"
Something went wrong with that request. Please try again.