From 8d0e4116f25460367bcfd997bf23283923242d4f Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Mon, 2 Jan 2012 09:59:48 -0500 Subject: [PATCH] Test with ActiveRecord 3.2. --- .travis.yml | 5 ++++- Gemfile | 22 +------------------ Gemfile.rails-3.1 | 9 ++++++++ Gemfile.rails-3.2 | 9 ++++++++ Rakefile | 11 +++++----- grouped_scope.gemspec | 9 ++++++-- lib/grouped_scope.rb | 1 + .../associations/collection_association.rb | 14 +++++------- test/helper.rb | 4 ++-- 9 files changed, 43 insertions(+), 41 deletions(-) create mode 100644 Gemfile.rails-3.1 create mode 100644 Gemfile.rails-3.2 diff --git a/.travis.yml b/.travis.yml index 0d4604e..1738378 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,7 @@ rvm: - 1.8.7 - 1.9.2 - 1.9.3 - - ree \ No newline at end of file + - ree +gemfile: +- Gemfile.rails-3.1 +- Gemfile.rails-3.2 diff --git a/Gemfile b/Gemfile index 0cd8376..36d8810 100644 --- a/Gemfile +++ b/Gemfile @@ -1,21 +1 @@ - -source :rubygems -source 'http://gems.github.com/' - -spec = eval(File.read('grouped_scope.gemspec')) -ar_version = spec.dependencies.detect{ |d|d.name == 'activerecord' }.requirement.to_s -ar_version = ENV['RAILS_VERSION'] || ar_version - -gem 'sqlite3', '1.3.4' -gem 'activerecord', ar_version, :require => 'active_record' - -group :development do - gem 'rake', '~> 0.9.2' -end - -group :test do - gem 'minitest', '~> 2.8.1' - gem 'factory_girl', '~> 2.3.2' - gem 'mocha', '~> 0.10.0' -end - +eval File.read('Gemfile.rails-3.1') diff --git a/Gemfile.rails-3.1 b/Gemfile.rails-3.1 new file mode 100644 index 0000000..97d8ae3 --- /dev/null +++ b/Gemfile.rails-3.1 @@ -0,0 +1,9 @@ +source :rubygems + +spec = eval File.read('grouped_scope.gemspec') +deps = spec.dependencies.map { |dep| {:name => dep.name, :version => dep.requirement.to_s} } + +deps.reject! { |dep| dep[:name] =~ /activerecord/ } +deps.each { |dep| gem dep[:name], dep[:version] } + +gem 'activerecord', '~> 3.1.3' diff --git a/Gemfile.rails-3.2 b/Gemfile.rails-3.2 new file mode 100644 index 0000000..7d5fc38 --- /dev/null +++ b/Gemfile.rails-3.2 @@ -0,0 +1,9 @@ +source :rubygems + +spec = eval File.read('grouped_scope.gemspec') +deps = spec.dependencies.map { |dep| {:name => dep.name, :version => dep.requirement.to_s} } + +deps.reject! { |dep| dep[:name] =~ /activerecord/ } +deps.each { |dep| gem dep[:name], dep[:version] } + +gem 'activerecord', '3.2.0.rc1' diff --git a/Rakefile b/Rakefile index c1b299d..a49c913 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,13 @@ -require 'rake' +require 'bundler' require 'rake/testtask' -desc 'Default: run unit tests.' -task :default => :test +Bundler::GemHelper.install_tasks desc 'Test the GroupedScope plugin.' Rake::TestTask.new do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' + t.libs = ['lib','test'] + t.test_files = Dir.glob("test/**/*_test.rb").sort t.verbose = true end +task :default => [:test] diff --git a/grouped_scope.gemspec b/grouped_scope.gemspec index faf4d7d..6b7149e 100644 --- a/grouped_scope.gemspec +++ b/grouped_scope.gemspec @@ -9,12 +9,17 @@ Gem::Specification.new do |s| s.email = ['ken@metaskills.net'] s.homepage = 'http://github.com/metaskills/grouped_scope/' s.summary = 'Extends has_many associations to group scope.' - s.description = 'Extends has_many associations to group scope. For ActiveRecord 3.1!' + s.description = 'Extends has_many associations to group scope. For ActiveRecord!' s.files = `git ls-files`.split("\n") - ["grouped_scope.gemspec"] s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ['lib'] s.rdoc_options = ['--charset=UTF-8'] - s.add_dependency 'activerecord', '~> 3.1.0' + s.add_runtime_dependency 'activerecord', '~> 3.1' + s.add_development_dependency 'sqlite3', '~> 1.3' + s.add_development_dependency 'rake', '~> 0.9.2' + s.add_development_dependency 'minitest', '~> 2.8.1' + s.add_development_dependency 'factory_girl', '~> 2.3.2' + s.add_development_dependency 'mocha', '~> 0.10.0' end diff --git a/lib/grouped_scope.rb b/lib/grouped_scope.rb index 80bb055..ac99566 100644 --- a/lib/grouped_scope.rb +++ b/lib/grouped_scope.rb @@ -1,3 +1,4 @@ +require 'active_record' require 'active_record/version' require 'grouped_scope/errors' require 'grouped_scope/self_grouping' diff --git a/lib/grouped_scope/arish/associations/collection_association.rb b/lib/grouped_scope/arish/associations/collection_association.rb index e61db83..7e54a51 100644 --- a/lib/grouped_scope/arish/associations/collection_association.rb +++ b/lib/grouped_scope/arish/associations/collection_association.rb @@ -5,16 +5,12 @@ module CollectionAssociation extend ActiveSupport::Concern - module InstanceMethods - - def association_scope - if reflection.grouped_scope? - @association_scope ||= Associations::AssociationScope.new(self).scope if klass - else - super - end + def association_scope + if reflection.grouped_scope? + @association_scope ||= Associations::AssociationScope.new(self).scope if klass + else + super end - end end diff --git a/test/helper.rb b/test/helper.rb index d2a64e8..bb3b1fc 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,7 +1,7 @@ require 'rubygems' require 'bundler' require "bundler/setup" -Bundler.require(:default, :development, :test) +Bundler.require require 'grouped_scope' require 'minitest/autorun' require 'factories' @@ -156,7 +156,7 @@ class Employee < ActiveRecord::Base end class LegacyEmployee < ActiveRecord::Base - set_primary_key :email + self.primary_key = 'email' has_many :reports, :class_name => 'LegacyReport', :foreign_key => 'email' grouped_scope :reports end