Skip to content

Commit

Permalink
* Major overhaul for Rails 2.3.14.
Browse files Browse the repository at this point in the history
- New gem layout using a Gemfile for development.
- Switch to MiniTest::Spec.
  • Loading branch information
metaskills committed Sep 11, 2011
1 parent 4a21726 commit f9827e7
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 303 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
test/debug.log
debug.log
autotest
.rbenv-version
.rbenv-version
Gemfile.lock
debug.log
23 changes: 16 additions & 7 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@

*master*
= master

*
= 0.6.0 (May 06, 2009)

* ActiveRecord 2.3.14 compatibility.

*0.5.1* (January 7th 2009)
* Refactored to use MiniTest::Spec and Bundler for development/testing.


= 0.6.0 (May 06, 2009)

* ActiveRecord 2.3.2 compatibility.


= 0.5.1 (January 7th 2009)

* Add rails 2.2.2 to test task and remove quite backtrace usage so 1.2.6 testing can run. [Ken Collins]


*0.4* (October 3rd 2008)
= 0.4 (October 3rd 2008)

* Use the #737f2bdabb of NamedScope plugin from http://github.com/metaskills/named_scope/tree/master


*0.3* (October 2nd 2008)
= 0.3 (October 2nd 2008)

* Add additional NamedScope patches for attribute_condition.
Also added GroupedScope::CoreExt to follow suite for GroupedScope::SelfGrouping attribute_conditions.


*0.2* (September 29th 2008)
= 0.2 (September 29th 2008)

* Add WillPaginate test and confirm grouped scope, named scope, and will paginate all play together. [Ken Collins]

* Stronger back port for named_scope in 1.2.6 and 2.0.4. Fixed bug where association proxy owner scope was after named_scope calls. [Ken Collins]


*0.1* (September 26th, 2008)
= 0.1 (September 26th, 2008)

* Initial public release. [Ken Collins]

Expand Down
22 changes: 22 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

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

gem 'sqlite3', '1.3.4'
gem 'activerecord', ar_version, :require => 'active_record'
gem 'mislav-will_paginate', '2.3.4', :require => 'will_paginate'

group :development do
gem 'rake', '0.8.7'
end

group :test do
gem 'minitest', '2.5.1'
gem 'mini_shoulda', '0.4.0'
gem 'factory_girl', '2.1.0'
gem 'mocha', '0.10.0'
end

2 changes: 1 addition & 1 deletion MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2008 Ken Collins, Decisiv Inc.
Copyright (c) 2008-2011 Ken Collins

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
33 changes: 2 additions & 31 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,43 +1,14 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

def reset_invoked
['test_rails','test'].each do |name|
Rake::Task[name].instance_variable_set '@already_invoked', false
end
end


desc 'Default: run unit tests.'
task :default => :test_rails
task :default => :test

desc 'Test the GroupedScope plugin.'
Rake::TestTask.new(:test) do |t|
Rake::TestTask.new do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Test the GroupedScope plugin with Rails 2.3.2, 2.2.2, and 2.1.1 gems'
task :test_rails do
test = Rake::Task['test']
versions = ['2.3.2','2.2.2','2.1.1']
versions.each do |version|
ENV['RAILS_VERSION'] = "#{version}"
test.invoke
reset_invoked unless version == versions.last
end
end

desc 'Generate documentation for the GroupedScope plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'GroupedScope'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end


55 changes: 18 additions & 37 deletions grouped_scope.gemspec
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
$:.push File.expand_path("../lib", __FILE__)
require "grouped_scope/version"

Gem::Specification.new do |s|
s.name = "grouped_scope"
s.version = "0.6.0"
s.date = "2009-05-06"
s.summary = "Extends has_many associations to group scope."
s.email = "[email protected]"
s.homepage = "http://github.com/metaskills/grouped_scope/"
s.description = "Extends has_many associations to group scope."
s.has_rdoc = true
s.authors = ["Ken Collins"]
s.files = [
"CHANGELOG",
"MIT-LICENSE",
"Rakefile",
"README.rdoc",
"init.rb",
"lib/grouped_scope.rb",
"lib/grouped_scope/association_reflection.rb",
"lib/grouped_scope/class_methods.rb",
"lib/grouped_scope/core_ext.rb",
"lib/grouped_scope/errors.rb",
"lib/grouped_scope/grouping.rb",
"lib/grouped_scope/has_many_association.rb",
"lib/grouped_scope/has_many_through_association.rb",
"lib/grouped_scope/instance_methods.rb",
"lib/grouped_scope/self_grouping.rb" ]
s.test_files = [
"test/factories.rb",
"test/grouped_scope/association_reflection_test.rb",
"test/grouped_scope/class_methods_test.rb",
"test/grouped_scope/has_many_association_test.rb",
"test/grouped_scope/has_many_through_association_test.rb",
"test/grouped_scope/self_grouping_test.rb",
"test/helper.rb",
"test/lib/boot.rb",
"test/lib/test_case.rb" ]
s.rdoc_options = ["--main", "README.rdoc"]
s.extra_rdoc_files = ["README.rdoc","CHANGELOG","MIT-LICENSE"]
s.name = 'grouped_scope'
s.version = GroupedScope::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Ken Collins']
s.email = ['[email protected]']
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 2.3.x!'
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', '~> 2.3.14'
end

2 changes: 0 additions & 2 deletions init.rb

This file was deleted.

7 changes: 1 addition & 6 deletions lib/grouped_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@
require 'grouped_scope/has_many_association'
require 'grouped_scope/has_many_through_association'
require 'grouped_scope/core_ext'

module GroupedScope

VERSION = '0.6.0'

end
require 'grouped_scope/version'

5 changes: 5 additions & 0 deletions lib/grouped_scope/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module GroupedScope

VERSION = '0.6.1'

end
81 changes: 38 additions & 43 deletions test/factories.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
FactoryGirl.define do

sequence(:id) { |n| n }
sequence(:email) { |n| "test_#{n}@domain.com" }
sequence(:title) { |n| "Report Title ##{n}" }

factory :report do
title { FactoryGirl.generate(:title) }
body 'Bla bla bla. Bla. Bla bla.'
end

factory :employee do
name { "Factory Employee ##{FactoryGirl.generate(:id)}" }
email { FactoryGirl.generate(:email) }
end

factory :employee_with_reports, :parent => :employee do
reports { |e| [e.association(:report), e.association(:report)] }
end

factory :employee_with_urgent_reports, :parent => :employee do
reports { |e| [e.association(:report), e.association(:report, :title=>'URGENT'),
e.association(:report), e.association(:report, :body=>'This is URGENT.')] }
end

factory :legacy_employee do
name { "Legacy Factory Employee ##{FactoryGirl.generate(:id)}" }
email { FactoryGirl.generate(:email) }
end

factory :legacy_report do |r|
r.title { FactoryGirl.generate(:title) }
r.body 'Legacy bla bla. Legacy. Legacy bla.'
end

factory :legacy_employee_with_reports, :parent => :legacy_employee do
reports { |e| [e.association(:legacy_report), e.association(:legacy_report)] }
end

Factory.sequence(:id) { |n| n }
Factory.sequence(:email) { |n| "test_#{n}@domain.com" }
Factory.sequence(:title) { |n| "Report Title ##{n}" }

Factory.define :employee do |e|
e.name { "Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
end

Factory.define :report do |r|
r.title { Factory.next(:title) }
r.body 'Bla bla bla. Bla. Bla bla.'
end

Factory.define :employee_with_reports, :class => 'Employee' do |e|
e.name { "Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
e.reports { |employee| [employee.association(:report),employee.association(:report)] }
end

Factory.define :employee_with_urgent_reports, :class => 'Employee' do |e|
e.name { "Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
e.reports { |employee| [employee.association(:report), employee.association(:report,:title=>'URGENT'),
employee.association(:report), employee.association(:report,:body=>'This is URGENT.')] }
end


Factory.define :legacy_employee do |e|
e.name { "Legacy Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
end

Factory.define :legacy_report do |r|
r.title { Factory.next(:title) }
r.body 'Legacy bla bla. Legacy. Legacy bla.'
end

Factory.define :legacy_employee_with_reports, :class => 'LegacyEmployee' do |e|
e.name { "Legacy Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
e.reports { |employee| [employee.association(:legacy_report),employee.association(:legacy_report)] }
end


14 changes: 6 additions & 8 deletions test/grouped_scope/association_reflection_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/../helper'
require 'helper'

class GroupedScope::AssociationReflectionTest < GroupedScope::TestCase

def setup
setup do
setup_environment
end

Expand All @@ -13,19 +13,18 @@ def setup
setup { @reflection_klass = GroupedScope::AssociationReflection }

should 'when a association does not exist' do
assert_raise(ArgumentError) { @reflection_klass.new(Employee,:foobars) }
lambda{ @reflection_klass.new(Employee,:doesnotexist) }.must_raise(ArgumentError)
end

should 'when the association is not a has_many or a has_and_belongs_to_many' do
Employee.class_eval { belongs_to(:foo) }
assert_raise(ArgumentError) { @reflection_klass.new(Employee,:foo) }
lambda{ @reflection_klass.new(Employee,:foo) }.must_raise(ArgumentError)
end

end

end


context 'For #ungrouped_reflection' do

setup do
Expand All @@ -47,8 +46,8 @@ def setup
end

should 'not delegate to #ungrouped_reflection for #options and #name' do
assert_not_equal @ungrouped_reflection.name, @grouped_reflection.name
assert_not_equal @ungrouped_reflection.options, @grouped_reflection.options
@ungrouped_reflection.name.wont_equal @grouped_reflection.name
@ungrouped_reflection.options.wont_equal @grouped_reflection.options
end

should 'derive class name to same as ungrouped reflection' do
Expand All @@ -71,5 +70,4 @@ def setup
end



end
6 changes: 3 additions & 3 deletions test/grouped_scope/class_methods_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/../helper'
require 'helper'

class GroupedScope::ClassMethodsTest < GroupedScope::TestCase

def setup
setup do
setup_environment
end

Expand Down Expand Up @@ -34,7 +34,7 @@ def setup
should 'create a has_many assoc named :grouped_scope_* using existing association as a suffix' do
grouped_reports_assoc = Employee.reflections[:grouped_scope_reports]
assert_instance_of GroupedScope::AssociationReflection, grouped_reports_assoc
assert Factory(:employee).respond_to?(:grouped_scope_reports)
assert FactoryGirl.create(:employee).respond_to?(:grouped_scope_reports)
end

should 'not add the :grouped_scope option to existing reflection' do
Expand Down
Loading

0 comments on commit f9827e7

Please sign in to comment.