Permalink
Browse files

switch to jeweler

  • Loading branch information...
1 parent 73cebb9 commit 8444769f741956cf59847962c4917051b630fc6a @ninjudd committed Apr 15, 2009
Showing with 280 additions and 276 deletions.
  1. +0 −6 History.txt
  2. +8 −10 License.txt → LICENSE
  3. +0 −7 Manifest.txt
  4. +7 −11 README.txt → README.rdoc
  5. +39 −8 Rakefile
  6. 0 bin/model_set
  7. +174 −181 test/model_set_test.rb
  8. +40 −41 test/multi_set_test.rb
  9. +12 −12 test/test_helper.rb
View
6 History.txt
@@ -1,6 +0,0 @@
-=== 1.0.0 / 2008-11-18
-
-* 1 major enhancement
-
- * Birthday!
-
View
18 License.txt → LICENSE
@@ -1,10 +1,8 @@
-(The MIT License)
-
-Copyright (c) 2008 Justin Balthrop, Geni.com
+Copyright (c) 2008 Justin Balthrop
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
+"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
@@ -13,10 +11,10 @@ the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
7 Manifest.txt
@@ -1,7 +0,0 @@
-History.txt
-Manifest.txt
-README.txt
-Rakefile
-bin/model_set
-lib/model_set.rb
-test/test_model_set.rb
View
18 README.txt → README.rdoc
@@ -7,11 +7,7 @@ the Solr search engine through a subclass, but I plan to abstract this out into
engine" class that will support SQL, Solr, Sphinx, and eventually, other query methods
(possibly raw RecordCache hashes and other search engines).
-== INSTALL:
-
- sudo gem install model_set
-
-== USAGE:
+== Usage:
class RobotSet < ModelSet
end
@@ -32,12 +28,12 @@ set3 << Robot.find(5)
set3.ids
# => [3,4,5]
-== REQUIREMENTS:
+== Install:
- * deep_clonable
- * ordered_set
- * active_record
+ sudo gem install ninjudd-deep_clonable -s http://gems.github.com
+ sudo gem install ninjudd-ordered_set -s http://gems.github.com
+ sudo gem install ninjudd-model_set -s http://gems.github.com
-== LICENSE:
+== License:
-Copyright (c) 2008 Justin Balthrop, Geni.com; Published under The MIT License, see License.txt
+Copyright (c) 2009 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE
View
47 Rakefile
@@ -1,12 +1,43 @@
-# -*- ruby -*-
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
-require 'rubygems'
-require 'hoe'
-require './lib/model_set.rb'
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = "model_set"
+ s.summary = %Q{Easy manipulation of sets of ActiveRecord models}
+ s.email = "code@justinbalthrop.com"
+ s.homepage = "http://github.com/ninjudd/model_set"
+ s.description = "Easy manipulation of sets of ActiveRecord models"
+ s.authors = ["Justin Balthrop"]
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
+Rake::TestTask.new do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'model_set'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
-Hoe.new('ModelSet', ModelSet::VERSION) do |p|
- # p.rubyforge_name = 'ModelSetx' # if different than lowercase project name
- p.developer('Justin Balthrop', 'code@justinbalthrop.com')
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |t|
+ t.libs << 'test'
+ t.test_files = FileList['test/**/*_test.rb']
+ t.verbose = true
+ end
+rescue LoadError
end
-# vim: syntax=Ruby
+task :default => :test
View
0 bin/model_set
No changes.
View
355 test/model_set_test.rb
@@ -85,206 +85,199 @@ def add_birthday!
end
end
- def setup
- CreateTables.verbose = false
- CreateTables.up
- end
+ context 'with a db connection' do
+ setup do
+ CreateTables.verbose = false
+ CreateTables.up
+ end
- def teardown
- CreateTables.down
- end
+ teardown do
+ CreateTables.down
+ end
- test "constructor" do
- captain = Hero.create(:name => 'Captain America', :universe => 'Marvel')
- spidey = Hero.create(:name => 'Spider Man', :universe => 'Marvel')
- batman = Hero.create(:name => 'Batman', :universe => 'D.C.' )
- superman = Hero.create(:name => 'Superman', :universe => 'D.C.' )
- ironman = Hero.create(:name => 'Iron Man', :universe => 'Marvel')
-
- set = HeroSet.with_universe('Marvel')
- assert_equal [captain.id, spidey.id, ironman.id], set.ids
- end
+ should "construct a model set" do
+ captain = Hero.create(:name => 'Captain America', :universe => 'Marvel')
+ spidey = Hero.create(:name => 'Spider Man', :universe => 'Marvel')
+ batman = Hero.create(:name => 'Batman', :universe => 'D.C.' )
+ superman = Hero.create(:name => 'Superman', :universe => 'D.C.' )
+ ironman = Hero.create(:name => 'Iron Man', :universe => 'Marvel')
+
+ set = HeroSet.with_universe('Marvel')
+ assert_equal [captain.id, spidey.id, ironman.id], set.ids
+ end
- test "missing_ids" do
- missing_id = 5555
- spidey = Hero.create(:name => 'Spider Man', :universe => 'Marvel')
- set = HeroSet.new([spidey.id, missing_id])
-
- # Iterate through the profiles so the missing ones will be detected.
- set.each {}
- assert_equal [missing_id], set.missing_ids
- end
+ should "have missing ids" do
+ missing_id = 5555
+ spidey = Hero.create(:name => 'Spider Man', :universe => 'Marvel')
+ set = HeroSet.new([spidey.id, missing_id])
+
+ # Iterate through the profiles so the missing ones will be detected.
+ set.each {}
+ assert_equal [missing_id], set.missing_ids
+ end
- test "missing_ids with add_fields" do
- missing_id = 5555
- spidey = Hero.create(:name => 'Spider Man', :universe => 'Marvel')
- set = HeroSet.new([spidey.id, missing_id]).add_birthday
-
- # Iterate through the profiles so the missing ones will be detected.
- set.each {}
- assert_equal [missing_id], set.missing_ids
- end
+ should "have missing ids with add_fields" do
+ missing_id = 5555
+ spidey = Hero.create(:name => 'Spider Man', :universe => 'Marvel')
+ set = HeroSet.new([spidey.id, missing_id]).add_birthday
+
+ # Iterate through the profiles so the missing ones will be detected.
+ set.each {}
+ assert_equal [missing_id], set.missing_ids
+ end
- test "has_set through" do
- hero = Hero.create(:name => 'Mr. Invisible')
- invisibility = Superpower.create(:name => 'Invisibility')
- flying = Superpower.create(:name => 'Flying')
- HeroSuperpower.create(:hero_id => hero.id, :power_id => invisibility.id)
- HeroSuperpower.create(:hero_id => hero.id, :power_id => flying.id)
+ should "support has_set" do
+ hero = Hero.create(:name => 'Mr. Invisible')
+ mighty_mouse = Superpet.create(:name => 'Mighty Mouse', :owner_id => hero.id)
+ underdog = Superpet.create(:name => 'Underdog', :owner_id => hero.id)
+
+ set = hero.pets
+ assert_equal SuperpetSet, set.class
+ assert_equal [mighty_mouse.id, underdog.id], set.ids
+ end
- set = hero.superpowers
- assert_equal SuperpowerSet, set.class
- assert_equal [invisibility.id, flying.id], set.ids
- end
+ should "support has_set with through" do
+ hero = Hero.create(:name => 'Mr. Invisible')
+ invisibility = Superpower.create(:name => 'Invisibility')
+ flying = Superpower.create(:name => 'Flying')
+ HeroSuperpower.create(:hero_id => hero.id, :power_id => invisibility.id)
+ HeroSuperpower.create(:hero_id => hero.id, :power_id => flying.id)
+
+ set = hero.superpowers
+ assert_equal SuperpowerSet, set.class
+ assert_equal [invisibility.id, flying.id], set.ids
+ end
- test "has_set" do
- hero = Hero.create(:name => 'Mr. Invisible')
- mighty_mouse = Superpet.create(:name => 'Mighty Mouse', :owner_id => hero.id)
- underdog = Superpet.create(:name => 'Underdog', :owner_id => hero.id)
-
- set = hero.pets
- assert_equal SuperpetSet, set.class
- assert_equal [mighty_mouse.id, underdog.id], set.ids
- end
- test "set extensions" do
- hero = Hero.create(:name => 'Mr. Invisible')
- mighty_mouse = Superpet.create(:name => 'Mighty Mouse', :owner_id => hero.id, :species => 'mouse')
- sammy = Superpet.create(:name => 'Sammy Davis Jr. Jr.', :owner_id => hero.id, :species => 'dog')
- underdog = Superpet.create(:name => 'Underdog', :owner_id => hero.id, :species => 'dog')
-
- set = hero.pets
- assert_equal ['mouse', 'dog', 'dog'], set.collect {|pet| pet.species}
-
- assert_equal [sammy.id, underdog.id], set.dogs!.ids
- end
-
- class Robot < ActiveRecord::Base
- end
-
- class RobotSet < ModelSet
- end
+ should "allow set extensions" do
+ hero = Hero.create(:name => 'Mr. Invisible')
+ mighty_mouse = Superpet.create(:name => 'Mighty Mouse', :owner_id => hero.id, :species => 'mouse')
+ sammy = Superpet.create(:name => 'Sammy Davis Jr. Jr.', :owner_id => hero.id, :species => 'dog')
+ underdog = Superpet.create(:name => 'Underdog', :owner_id => hero.id, :species => 'dog')
+
+ set = hero.pets
+ assert_equal ['mouse', 'dog', 'dog'], set.collect {|pet| pet.species}
+
+ assert_equal [sammy.id, underdog.id], set.dogs!.ids
+ end
- def setup_robots
- @bender = Robot.create(:name => 'Bender', :classification => :smart_ass )
- @r2d2 = Robot.create(:name => 'R2D2', :classification => :droid )
- @c3po = Robot.create(:name => 'C3PO', :classification => :droid )
- @rosie = Robot.create(:name => 'Rosie', :classification => :domestic )
- @small_wonder = Robot.create(:name => 'Vicki', :classification => :child )
- @t1000 = Robot.create(:name => 'Terminator', :classification => :assasin )
- @johnny5 = Robot.create(:name => 'Johnny 5', :classification => :miltary )
-
- @bot_set = RobotSet.new([@bender,@r2d2,@c3po,@rosie,@small_wonder,@t1000,@johnny5])
+ class Robot < ActiveRecord::Base
+ end
+
+ class RobotSet < ModelSet
+ end
- @data = Robot.create(:name => 'Data', :classification => :positronic)
- @number8 = Robot.create(:name => 'Boomer', :classification => :cylon )
- end
+ setup do
+ @bender = Robot.create(:name => 'Bender', :classification => :smart_ass )
+ @r2d2 = Robot.create(:name => 'R2D2', :classification => :droid )
+ @c3po = Robot.create(:name => 'C3PO', :classification => :droid )
+ @rosie = Robot.create(:name => 'Rosie', :classification => :domestic )
+ @small_wonder = Robot.create(:name => 'Vicki', :classification => :child )
+ @t1000 = Robot.create(:name => 'Terminator', :classification => :assasin )
+ @johnny5 = Robot.create(:name => 'Johnny 5', :classification => :miltary )
+
+ @bot_set = RobotSet.new([@bender,@r2d2,@c3po,@rosie,@small_wonder,@t1000,@johnny5])
+
+ @data = Robot.create(:name => 'Data', :classification => :positronic)
+ @number8 = Robot.create(:name => 'Boomer', :classification => :cylon )
+ end
- test "empty" do
- setup_robots
-
- set = RobotSet.empty
- assert_equal 0, set.size
- assert set.empty?
-
- set = RobotSet.new(@bender)
- assert !set.empty?
- end
-
- test "set with single model" do
- setup_robots
- set = RobotSet.new(@bender)
- assert_equal [@bender.id], set.ids
- end
+ should "be empty" do
+ set = RobotSet.empty
+ assert_equal 0, set.size
+ assert set.empty?
+
+ set = RobotSet.new(@bender)
+ assert !set.empty?
+ end
- test "include?" do
- setup_robots
- set = RobotSet.new([@bender, @r2d2.id, @c3po.id])
- assert set.include?(@bender)
- assert set.include?(@r2d2.id)
- end
+ should "create a set with single model" do
+ set = RobotSet.new(@bender)
+ assert_equal [@bender.id], set.ids
+ end
- test "delete" do
- setup_robots
- set = RobotSet.new([@rosie, @small_wonder, @c3po])
-
- set.delete(@c3po)
- assert_equal [@rosie.id, @small_wonder.id], set.ids
-
- set.delete(@rosie.id)
- assert_equal [@small_wonder.id], set.ids
+ should "include models" do
+ set = RobotSet.new([@bender, @r2d2.id, @c3po.id])
+ assert set.include?(@bender)
+ assert set.include?(@r2d2.id)
+ assert set.include?(@c3po)
+ end
- set.delete(@small_wonder)
- assert_equal [], set.ids
- assert set.empty?
- end
+ should "delete models from a set" do
+ set = RobotSet.new([@rosie, @small_wonder, @c3po])
+
+ set.delete(@c3po)
+ assert_equal [@rosie.id, @small_wonder.id], set.ids
+
+ set.delete(@rosie.id)
+ assert_equal [@small_wonder.id], set.ids
+
+ set.delete(@small_wonder)
+ assert_equal [], set.ids
+ assert set.empty?
+ end
- test "select" do
- setup_robots
- assert_equal [@r2d2, @c3po], @bot_set.select {|bot| bot.classification == :droid}.to_a
- assert_equal 7, @bot_set.size
+ should "select models from a set" do
+ assert_equal [@r2d2, @c3po], @bot_set.select {|bot| bot.classification == :droid}.to_a
+ assert_equal 7, @bot_set.size
+
+ @bot_set.select! {|bot| bot.classification == :miltary}
+ assert_equal [@johnny5], @bot_set.to_a
+ end
- @bot_set.select! {|bot| bot.classification == :miltary}
- assert_equal [@johnny5], @bot_set.to_a
- end
-
- test "sort" do
- setup_robots
- assert_equal [@bender,@c3po,@johnny5,@r2d2,@rosie,@t1000,@small_wonder], @bot_set.sort {|a,b| a.name <=> b.name}.to_a
- assert_equal @johnny5, @bot_set.last
-
- @bot_set.sort! {|a,b| b.name <=> a.name}
- assert_equal [@bender,@c3po,@johnny5,@r2d2,@rosie,@t1000,@small_wonder].reverse, @bot_set.to_a
- end
-
- test "sort_by" do
- setup_robots
- assert_equal [@bender,@c3po,@johnny5,@r2d2,@rosie,@t1000,@small_wonder], @bot_set.sort_by {|bot| bot.name}.to_a
- end
-
- test "reject" do
- setup_robots
- @bot_set.reject! {|bot| bot.classification == :domestic}
- assert !@bot_set.include?(@rosie)
- end
-
- test "set operators" do
- setup_robots
+ should "sort a set" do
+ assert_equal [@bender,@c3po,@johnny5,@r2d2,@rosie,@t1000,@small_wonder], @bot_set.sort {|a,b| a.name <=> b.name}.to_a
+ assert_equal @johnny5, @bot_set.last
+
+ @bot_set.sort! {|a,b| b.name <=> a.name}
+ assert_equal [@bender,@c3po,@johnny5,@r2d2,@rosie,@t1000,@small_wonder].reverse, @bot_set.to_a
+ end
- droids = RobotSet.new([@c3po, @r2d2])
- womanoids = RobotSet.new([@rosie, @small_wonder, @number8])
- humanoids = RobotSet.new([@small_wonder, @t1000, @data, @number8])
- metalics = RobotSet.new([@r2d2, @c3po, @johnny5])
- cartoons = RobotSet.new([@bender, @rosie])
-
- assert_equal ['C3PO', 'R2D2', 'Johnny 5'], (droids + metalics).collect {|bot| bot.name}
- assert_equal ['Bender', 'Rosie', 'C3PO', 'R2D2', 'Johnny 5'], (cartoons + droids + metalics).collect {|bot| bot.name}
- assert_equal 5, (cartoons + droids + metalics).size
- assert_equal 5, (cartoons + droids + metalics).count
+ should "sort a set by name" do
+ assert_equal [@bender,@c3po,@johnny5,@r2d2,@rosie,@t1000,@small_wonder], @bot_set.sort_by {|bot| bot.name}.to_a
+ end
- assert_equal [], (droids - metalics).collect {|bot| bot.name}
- assert_equal ['Johnny 5'], (metalics - droids).collect {|bot| bot.name}
- assert_equal ['Terminator', 'Data'], (humanoids - womanoids).collect {|bot| bot.name}
- assert_equal ['Bender'], (cartoons - womanoids).collect {|bot| bot.name}
- assert_equal 2, (humanoids - womanoids).size
- assert_equal 2, (humanoids - womanoids).count
-
- assert_equal ['C3PO', 'R2D2'], (droids & metalics).collect {|bot| bot.name}
- assert_equal ['R2D2', 'C3PO'], (metalics & droids).collect {|bot| bot.name}
- assert_equal ['Vicki', 'Boomer'], (humanoids & womanoids).collect {|bot| bot.name}
- assert_equal ['Rosie'], (cartoons & womanoids).collect {|bot| bot.name}
- assert_equal 2, (humanoids & womanoids).size
- assert_equal 2, (humanoids & womanoids).count
+ should "reject models from a set" do
+ @bot_set.reject! {|bot| bot.classification == :domestic}
+ assert !@bot_set.include?(@rosie)
+ end
- set = (droids + @johnny5)
- assert_equal ['C3PO', 'R2D2', 'Johnny 5'], set.collect {|bot| bot.name}
- set -= @r2d2
- assert_equal ['C3PO', 'Johnny 5'], set.collect {|bot| bot.name}
- end
+ should "do set arithmetic" do
+ droids = RobotSet.new([@c3po, @r2d2])
+ womanoids = RobotSet.new([@rosie, @small_wonder, @number8])
+ humanoids = RobotSet.new([@small_wonder, @t1000, @data, @number8])
+ metalics = RobotSet.new([@r2d2, @c3po, @johnny5])
+ cartoons = RobotSet.new([@bender, @rosie])
+
+ assert_equal ['C3PO', 'R2D2', 'Johnny 5'], (droids + metalics).collect {|bot| bot.name}
+ assert_equal ['Bender', 'Rosie', 'C3PO', 'R2D2', 'Johnny 5'], (cartoons + droids + metalics).collect {|bot| bot.name}
+ assert_equal 5, (cartoons + droids + metalics).size
+ assert_equal 5, (cartoons + droids + metalics).count
+
+ assert_equal [], (droids - metalics).collect {|bot| bot.name}
+ assert_equal ['Johnny 5'], (metalics - droids).collect {|bot| bot.name}
+ assert_equal ['Terminator', 'Data'], (humanoids - womanoids).collect {|bot| bot.name}
+ assert_equal ['Bender'], (cartoons - womanoids).collect {|bot| bot.name}
+ assert_equal 2, (humanoids - womanoids).size
+ assert_equal 2, (humanoids - womanoids).count
+
+ assert_equal ['C3PO', 'R2D2'], (droids & metalics).collect {|bot| bot.name}
+ assert_equal ['R2D2', 'C3PO'], (metalics & droids).collect {|bot| bot.name}
+ assert_equal ['Vicki', 'Boomer'], (humanoids & womanoids).collect {|bot| bot.name}
+ assert_equal ['Rosie'], (cartoons & womanoids).collect {|bot| bot.name}
+ assert_equal 2, (humanoids & womanoids).size
+ assert_equal 2, (humanoids & womanoids).count
+
+ set = (droids + @johnny5)
+ assert_equal ['C3PO', 'R2D2', 'Johnny 5'], set.collect {|bot| bot.name}
+ set -= @r2d2
+ assert_equal ['C3PO', 'Johnny 5'], set.collect {|bot| bot.name}
+ end
- test "clone" do
- set = RobotSet.new([1])
- new_set = set.clone
- assert new_set.object_id != set.object_id
+ should "clone a set" do
+ set = RobotSet.new([1])
+ new_set = set.clone
+ assert new_set.object_id != set.object_id
+ end
end
end
View
81 test/multi_set_test.rb
@@ -14,53 +14,52 @@ def self.down
end
end
- def setup
- CreateTables.verbose = false
- CreateTables.up
- end
-
- def teardown
- CreateTables.down
- end
-
class Robot < ActiveRecord::Base
end
class RobotSet < ModelSet
end
- def setup_robots
- @bender = Robot.create(:name => 'Bender', :classification => :smart_ass )
- @r2d2 = Robot.create(:name => 'R2D2', :classification => :droid )
- @c3po = Robot.create(:name => 'C3PO', :classification => :droid )
- @rosie = Robot.create(:name => 'Rosie', :classification => :domestic )
- @small_wonder = Robot.create(:name => 'Vicki', :classification => :child )
- @t1000 = Robot.create(:name => 'Terminator', :classification => :assasin )
- @johnny5 = Robot.create(:name => 'Johnny 5', :classification => :miltary )
- @data = Robot.create(:name => 'Data', :classification => :positronic)
- @number8 = Robot.create(:name => 'Boomer', :classification => :cylon )
- end
+ context 'with a db connection' do
+ setup do
+ CreateTables.verbose = false
+ CreateTables.up
+
+ @bender = Robot.create(:name => 'Bender', :classification => :smart_ass )
+ @r2d2 = Robot.create(:name => 'R2D2', :classification => :droid )
+ @c3po = Robot.create(:name => 'C3PO', :classification => :droid )
+ @rosie = Robot.create(:name => 'Rosie', :classification => :domestic )
+ @small_wonder = Robot.create(:name => 'Vicki', :classification => :child )
+ @t1000 = Robot.create(:name => 'Terminator', :classification => :assasin )
+ @johnny5 = Robot.create(:name => 'Johnny 5', :classification => :miltary )
+ @data = Robot.create(:name => 'Data', :classification => :positronic)
+ @number8 = Robot.create(:name => 'Boomer', :classification => :cylon )
+ end
- test "add, subtract, intersect" do
- setup_robots
- set = MultiSet.new
- set += RobotSet.new([@bender, @r2d2, @rosie])
- set += RobotSet.new([@c3po, @r2d2, @t1000])
- set += RobotSet.new([@data, @number8, @johnny5])
-
- assert_equal [3,3,3], set.size
- assert_equal [@bender,@r2d2,@rosie,@c3po,@t1000,@data,@number8,@johnny5].collect {|r| r.id}, set.ids
- assert_equal [@bender,@r2d2,@rosie,@c3po,@r2d2,@t1000,@data,@number8,@johnny5], set.to_a
-
- set -= RobotSet.new([@r2d2, @rosie, @t1000, @johnny5])
-
- assert_equal [1,1,2], set.size
- assert_equal [@bender,@c3po,@data,@number8].collect {|r| r.id}, set.ids
-
- other_set = MultiSet.new(RobotSet.new([@data]), RobotSet.new([@bender]))
-
- set &= other_set
- assert_equal [1,0,1], set.size
- assert_equal [@bender,@data].collect {|r| r.id}, set.ids
+ teardown do
+ CreateTables.down
+ end
+
+ should "add, subtract, intersect" do
+ set = MultiSet.new
+ set += RobotSet.new([@bender, @r2d2, @rosie])
+ set += RobotSet.new([@c3po, @r2d2, @t1000])
+ set += RobotSet.new([@data, @number8, @johnny5])
+
+ assert_equal [3,3,3], set.size
+ assert_equal [@bender,@r2d2,@rosie,@c3po,@t1000,@data,@number8,@johnny5].collect {|r| r.id}, set.ids
+ assert_equal [@bender,@r2d2,@rosie,@c3po,@r2d2,@t1000,@data,@number8,@johnny5], set.to_a
+
+ set -= RobotSet.new([@r2d2, @rosie, @t1000, @johnny5])
+
+ assert_equal [1,1,2], set.size
+ assert_equal [@bender,@c3po,@data,@number8].collect {|r| r.id}, set.ids
+
+ other_set = MultiSet.new(RobotSet.new([@data]), RobotSet.new([@bender]))
+
+ set &= other_set
+ assert_equal [1,0,1], set.size
+ assert_equal [@bender,@data].collect {|r| r.id}, set.ids
+ end
end
end
View
24 test/test_helper.rb
@@ -1,10 +1,16 @@
+require 'rubygems'
require 'test/unit'
+require 'shoulda'
+require 'mocha'
-$:.unshift(File.dirname(__FILE__) + '/../../deep_clonable/lib')
-
-require File.dirname(__FILE__) + '/../lib/model_set'
+$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
+['deep_clonable', 'ordered_set'].each do |dir|
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../#{dir}/lib"
+end
+require 'model_set'
-require 'pp'
+class Test::Unit::TestCase
+end
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
@@ -13,11 +19,5 @@
:password => "",
:database => "model_set_test"
)
-
-class << Test::Unit::TestCase
- def test(name, &block)
- test_name = "test_#{name.gsub(/[\s\W]/,'_')}"
- raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name
- define_method test_name, &block
- end
-end
+ActiveRecord::Migration.verbose = false
+ActiveRecord::Base.connection.client_min_messages = 'panic'

0 comments on commit 8444769

Please sign in to comment.