diff --git a/.travis.yml b/.travis.yml index 87851f5..7577031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,12 @@ services: mongodb gemfile: - gemfiles/rails_3.2.gemfile - gemfiles/rails_4.0.gemfile - - gemfiles/rails_4.0_bson1.gemfile + - gemfiles/rails_4.0_mongo_mapper.gemfile - gemfiles/rails_4.1.gemfile - - gemfiles/rails_4.1_bson1.gemfile + - gemfiles/rails_4.1_mongo_mapper.gemfile - gemfiles/rails_4.2.gemfile - - gemfiles/rails_4.2_bson1.gemfile + - gemfiles/rails_4.2_mongoid_5.gemfile + - gemfiles/rails_4.2_mongo_mapper.gemfile matrix: allow_failures: diff --git a/gemfiles/rails_4.0_bson1.gemfile b/gemfiles/rails_4.0_mongo_mapper.gemfile similarity index 100% rename from gemfiles/rails_4.0_bson1.gemfile rename to gemfiles/rails_4.0_mongo_mapper.gemfile diff --git a/gemfiles/rails_4.1_bson1.gemfile b/gemfiles/rails_4.1_mongo_mapper.gemfile similarity index 100% rename from gemfiles/rails_4.1_bson1.gemfile rename to gemfiles/rails_4.1_mongo_mapper.gemfile diff --git a/gemfiles/rails_4.2_bson1.gemfile b/gemfiles/rails_4.2_mongo_mapper.gemfile similarity index 100% rename from gemfiles/rails_4.2_bson1.gemfile rename to gemfiles/rails_4.2_mongo_mapper.gemfile diff --git a/gemfiles/rails_4.2_mongoid_5.gemfile b/gemfiles/rails_4.2_mongoid_5.gemfile new file mode 100644 index 0000000..b555559 --- /dev/null +++ b/gemfiles/rails_4.2_mongoid_5.gemfile @@ -0,0 +1,12 @@ +source "https://rubygems.org" + +gem "sqlite3", :platforms => :ruby +gem 'rubysl', :platforms => :rbx +gem 'rubinius-developer_tools', :platforms => :rbx +gem "jruby-openssl", :platforms => :jruby +gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby +gem "rails", "4.2.0" +gem 'mongoid', '~>5.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3') +gem 'sequel' + +gemspec :path => "../" diff --git a/lib/aasm/persistence/base.rb b/lib/aasm/persistence/base.rb index 3833a9c..9070de9 100644 --- a/lib/aasm/persistence/base.rb +++ b/lib/aasm/persistence/base.rb @@ -56,8 +56,8 @@ module AASM def state_with_scope(name, *args) state_without_scope(name, *args) if @state_machine.config.create_scopes && !@klass.respond_to?(name) - if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base") + if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base") conditions = {"#{@klass.table_name}.#{@klass.aasm(@name).attribute_name}" => name.to_s} if ActiveRecord::VERSION::MAJOR >= 3 @klass.class_eval do @@ -69,12 +69,17 @@ module AASM end end elsif @klass.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document") - scope_options = lambda { @klass.send(:where, {@klass.aasm(@name).attribute_name.to_sym => name.to_s}) } + klass = @klass + state_machine_name = @name + scope_options = lambda { + klass.send(:where, {klass.aasm(state_machine_name).attribute_name.to_sym => name.to_s}) + } @klass.send(:scope, name, scope_options) elsif @klass.ancestors.map {|klass| klass.to_s}.include?("MongoMapper::Document") conditions = { @klass.aasm(@name).attribute_name.to_sym => name.to_s } @klass.scope(name, lambda { @klass.where(conditions) }) end + end end alias_method :state_without_scope, :state