Skip to content
This repository
Browse code

use factory girl, lose shoulda

  • Loading branch information...
commit badcc79ed4498772aee3dc6d80cbbc46db863a10 1 parent 5d9edc0
Matt Jankowski authored

Showing 32 changed files with 520 additions and 730 deletions. Show diff stats Hide diff stats

  1. 4  Gemfile
  2. 90  Gemfile.lock
  3. 3  gemfiles/rails-3.0.3-database-mysql.gemfile
  4. 33  gemfiles/rails-3.0.3-database-mysql.gemfile.lock
  5. 3  gemfiles/rails-3.0.3-database-mysql2.gemfile
  6. 33  gemfiles/rails-3.0.3-database-mysql2.gemfile.lock
  7. 3  gemfiles/rails-3.0.3-database-pg.gemfile
  8. 33  gemfiles/rails-3.0.3-database-pg.gemfile.lock
  9. 3  gemfiles/rails-3.0.3-database-sqlite3-ruby.gemfile
  10. 33  gemfiles/rails-3.0.3-database-sqlite3-ruby.gemfile.lock
  11. 8  lib/pacecar/datetime.rb
  12. 6  lib/pacecar/duration.rb
  13. 4  lib/pacecar/ranking.rb
  14. 8  lib/pacecar/search.rb
  15. 52  test/associations_test.rb
  16. 59  test/boolean_test.rb
  17. 175  test/datetime_test.rb
  18. 2  test/dummy/app/models/mammal.rb
  19. 2  test/dummy/app/models/user.rb
  20. 44  test/duration_test.rb
  21. 17  test/factories.rb
  22. 86  test/helpers_test.rb
  23. 45  test/limit_test.rb
  24. 93  test/numeric_test.rb
  25. 41  test/order_test.rb
  26. 31  test/polymorph_test.rb
  27. 40  test/presence_test.rb
  28. 34  test/ranking_test.rb
  29. 124  test/search_test.rb
  30. 122  test/state_test.rb
  31. 4  test/support/integration_case.rb
  32. 15  test/test_helper.rb
4  Gemfile
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
2 2
 
3 3
 gem 'appraisal'
4 4
 
5  
-gem 'shoulda'
6 5
 gem 'mocha'
7 6
 gem 'redgreen'
8  
-gem 'capybara', '>= 0.4.0'
  7
+
  8
+gem 'factory_girl_rails'
90  Gemfile.lock
... ...
@@ -1,50 +1,84 @@
1 1
 GEM
2 2
   remote: http://rubygems.org/
3 3
   specs:
  4
+    abstract (1.0.0)
  5
+    actionmailer (3.0.3)
  6
+      actionpack (= 3.0.3)
  7
+      mail (~> 2.2.9)
  8
+    actionpack (3.0.3)
  9
+      activemodel (= 3.0.3)
  10
+      activesupport (= 3.0.3)
  11
+      builder (~> 2.1.2)
  12
+      erubis (~> 2.6.6)
  13
+      i18n (~> 0.4)
  14
+      rack (~> 1.2.1)
  15
+      rack-mount (~> 0.6.13)
  16
+      rack-test (~> 0.5.6)
  17
+      tzinfo (~> 0.3.23)
  18
+    activemodel (3.0.3)
  19
+      activesupport (= 3.0.3)
  20
+      builder (~> 2.1.2)
  21
+      i18n (~> 0.4)
  22
+    activerecord (3.0.3)
  23
+      activemodel (= 3.0.3)
  24
+      activesupport (= 3.0.3)
  25
+      arel (~> 2.0.2)
  26
+      tzinfo (~> 0.3.23)
  27
+    activeresource (3.0.3)
  28
+      activemodel (= 3.0.3)
  29
+      activesupport (= 3.0.3)
  30
+    activesupport (3.0.3)
4 31
     appraisal (0.1)
5 32
       bundler
6 33
       rake
7  
-    capybara (0.4.0)
8  
-      celerity (>= 0.7.9)
9  
-      culerity (>= 0.2.4)
10  
-      mime-types (>= 1.16)
11  
-      nokogiri (>= 1.3.3)
12  
-      rack (>= 1.0.0)
13  
-      rack-test (>= 0.5.4)
14  
-      selenium-webdriver (>= 0.0.27)
15  
-      xpath (~> 0.1.2)
16  
-    celerity (0.8.4)
17  
-    childprocess (0.1.4)
18  
-      ffi (~> 0.6.3)
19  
-    culerity (0.2.12)
20  
-    ffi (0.6.3)
21  
-      rake (>= 0.8.7)
22  
-    json_pure (1.4.6)
  34
+    arel (2.0.6)
  35
+    builder (2.1.2)
  36
+    erubis (2.6.6)
  37
+      abstract (>= 1.0.0)
  38
+    factory_girl (1.3.2)
  39
+    factory_girl_rails (1.0)
  40
+      factory_girl (~> 1.3)
  41
+      rails (>= 3.0.0.beta4)
  42
+    i18n (0.5.0)
  43
+    mail (2.2.12)
  44
+      activesupport (>= 2.3.6)
  45
+      i18n (>= 0.4.0)
  46
+      mime-types (~> 1.16)
  47
+      treetop (~> 1.4.8)
23 48
     mime-types (1.16)
24 49
     mocha (0.9.10)
25 50
       rake
26  
-    nokogiri (1.4.4)
  51
+    polyglot (0.3.1)
27 52
     rack (1.2.1)
  53
+    rack-mount (0.6.13)
  54
+      rack (>= 1.0.0)
28 55
     rack-test (0.5.6)
29 56
       rack (>= 1.0)
  57
+    rails (3.0.3)
  58
+      actionmailer (= 3.0.3)
  59
+      actionpack (= 3.0.3)
  60
+      activerecord (= 3.0.3)
  61
+      activeresource (= 3.0.3)
  62
+      activesupport (= 3.0.3)
  63
+      bundler (~> 1.0)
  64
+      railties (= 3.0.3)
  65
+    railties (3.0.3)
  66
+      actionpack (= 3.0.3)
  67
+      activesupport (= 3.0.3)
  68
+      rake (>= 0.8.7)
  69
+      thor (~> 0.14.4)
30 70
     rake (0.8.7)
31 71
     redgreen (1.2.2)
32  
-    rubyzip (0.9.4)
33  
-    selenium-webdriver (0.1.1)
34  
-      childprocess (= 0.1.4)
35  
-      ffi (~> 0.6.3)
36  
-      json_pure
37  
-      rubyzip
38  
-    shoulda (2.11.3)
39  
-    xpath (0.1.2)
40  
-      nokogiri (~> 1.3)
  72
+    thor (0.14.6)
  73
+    treetop (1.4.9)
  74
+      polyglot (>= 0.3.1)
  75
+    tzinfo (0.3.23)
41 76
 
42 77
 PLATFORMS
43 78
   ruby
44 79
 
45 80
 DEPENDENCIES
46 81
   appraisal
47  
-  capybara (>= 0.4.0)
  82
+  factory_girl_rails
48 83
   mocha
49 84
   redgreen
50  
-  shoulda
3  gemfiles/rails-3.0.3-database-mysql.gemfile
@@ -3,8 +3,7 @@
3 3
 source "http://rubygems.org"
4 4
 gem "rails", "3.0.3"
5 5
 gem "mysql"
6  
-gem "shoulda"
7 6
 gem "mocha"
8 7
 gem "redgreen"
9 8
 gem "appraisal"
10  
-gem "capybara", ">= 0.4.0"
  9
+gem "factory_girl_rails"
33  gemfiles/rails-3.0.3-database-mysql.gemfile.lock
@@ -33,25 +33,13 @@ GEM
33 33
       rake
34 34
     arel (2.0.6)
35 35
     builder (2.1.2)
36  
-    capybara (0.4.0)
37  
-      celerity (>= 0.7.9)
38  
-      culerity (>= 0.2.4)
39  
-      mime-types (>= 1.16)
40  
-      nokogiri (>= 1.3.3)
41  
-      rack (>= 1.0.0)
42  
-      rack-test (>= 0.5.4)
43  
-      selenium-webdriver (>= 0.0.27)
44  
-      xpath (~> 0.1.2)
45  
-    celerity (0.8.4)
46  
-    childprocess (0.1.4)
47  
-      ffi (~> 0.6.3)
48  
-    culerity (0.2.12)
49 36
     erubis (2.6.6)
50 37
       abstract (>= 1.0.0)
51  
-    ffi (0.6.3)
52  
-      rake (>= 0.8.7)
  38
+    factory_girl (1.3.2)
  39
+    factory_girl_rails (1.0)
  40
+      factory_girl (~> 1.3)
  41
+      rails (>= 3.0.0.beta4)
53 42
     i18n (0.5.0)
54  
-    json_pure (1.4.6)
55 43
     mail (2.2.12)
56 44
       activesupport (>= 2.3.6)
57 45
       i18n (>= 0.4.0)
@@ -61,7 +49,6 @@ GEM
61 49
     mocha (0.9.10)
62 50
       rake
63 51
     mysql (2.8.1)
64  
-    nokogiri (1.4.4)
65 52
     polyglot (0.3.1)
66 53
     rack (1.2.1)
67 54
     rack-mount (0.6.13)
@@ -83,28 +70,18 @@ GEM
83 70
       thor (~> 0.14.4)
84 71
     rake (0.8.7)
85 72
     redgreen (1.2.2)
86  
-    rubyzip (0.9.4)
87  
-    selenium-webdriver (0.1.1)
88  
-      childprocess (= 0.1.4)
89  
-      ffi (~> 0.6.3)
90  
-      json_pure
91  
-      rubyzip
92  
-    shoulda (2.11.3)
93 73
     thor (0.14.6)
94 74
     treetop (1.4.9)
95 75
       polyglot (>= 0.3.1)
96 76
     tzinfo (0.3.23)
97  
-    xpath (0.1.2)
98  
-      nokogiri (~> 1.3)
99 77
 
100 78
 PLATFORMS
101 79
   ruby
102 80
 
103 81
 DEPENDENCIES
104 82
   appraisal
105  
-  capybara (>= 0.4.0)
  83
+  factory_girl_rails
106 84
   mocha
107 85
   mysql
108 86
   rails (= 3.0.3)
109 87
   redgreen
110  
-  shoulda
3  gemfiles/rails-3.0.3-database-mysql2.gemfile
@@ -2,9 +2,8 @@
2 2
 
3 3
 source "http://rubygems.org"
4 4
 gem "rails", "3.0.3"
5  
-gem "shoulda"
6 5
 gem "mocha"
7 6
 gem "mysql2"
8 7
 gem "redgreen"
9 8
 gem "appraisal"
10  
-gem "capybara", ">= 0.4.0"
  9
+gem "factory_girl_rails"
33  gemfiles/rails-3.0.3-database-mysql2.gemfile.lock
@@ -33,25 +33,13 @@ GEM
33 33
       rake
34 34
     arel (2.0.6)
35 35
     builder (2.1.2)
36  
-    capybara (0.4.0)
37  
-      celerity (>= 0.7.9)
38  
-      culerity (>= 0.2.4)
39  
-      mime-types (>= 1.16)
40  
-      nokogiri (>= 1.3.3)
41  
-      rack (>= 1.0.0)
42  
-      rack-test (>= 0.5.4)
43  
-      selenium-webdriver (>= 0.0.27)
44  
-      xpath (~> 0.1.2)
45  
-    celerity (0.8.4)
46  
-    childprocess (0.1.4)
47  
-      ffi (~> 0.6.3)
48  
-    culerity (0.2.12)
49 36
     erubis (2.6.6)
50 37
       abstract (>= 1.0.0)
51  
-    ffi (0.6.3)
52  
-      rake (>= 0.8.7)
  38
+    factory_girl (1.3.2)
  39
+    factory_girl_rails (1.0)
  40
+      factory_girl (~> 1.3)
  41
+      rails (>= 3.0.0.beta4)
53 42
     i18n (0.5.0)
54  
-    json_pure (1.4.6)
55 43
     mail (2.2.12)
56 44
       activesupport (>= 2.3.6)
57 45
       i18n (>= 0.4.0)
@@ -61,7 +49,6 @@ GEM
61 49
     mocha (0.9.10)
62 50
       rake
63 51
     mysql2 (0.2.6)
64  
-    nokogiri (1.4.4)
65 52
     polyglot (0.3.1)
66 53
     rack (1.2.1)
67 54
     rack-mount (0.6.13)
@@ -83,28 +70,18 @@ GEM
83 70
       thor (~> 0.14.4)
84 71
     rake (0.8.7)
85 72
     redgreen (1.2.2)
86  
-    rubyzip (0.9.4)
87  
-    selenium-webdriver (0.1.1)
88  
-      childprocess (= 0.1.4)
89  
-      ffi (~> 0.6.3)
90  
-      json_pure
91  
-      rubyzip
92  
-    shoulda (2.11.3)
93 73
     thor (0.14.6)
94 74
     treetop (1.4.9)
95 75
       polyglot (>= 0.3.1)
96 76
     tzinfo (0.3.23)
97  
-    xpath (0.1.2)
98  
-      nokogiri (~> 1.3)
99 77
 
100 78
 PLATFORMS
101 79
   ruby
102 80
 
103 81
 DEPENDENCIES
104 82
   appraisal
105  
-  capybara (>= 0.4.0)
  83
+  factory_girl_rails
106 84
   mocha
107 85
   mysql2
108 86
   rails (= 3.0.3)
109 87
   redgreen
110  
-  shoulda
3  gemfiles/rails-3.0.3-database-pg.gemfile
@@ -3,8 +3,7 @@
3 3
 source "http://rubygems.org"
4 4
 gem "pg"
5 5
 gem "rails", "3.0.3"
6  
-gem "shoulda"
7 6
 gem "mocha"
8 7
 gem "redgreen"
9 8
 gem "appraisal"
10  
-gem "capybara", ">= 0.4.0"
  9
+gem "factory_girl_rails"
33  gemfiles/rails-3.0.3-database-pg.gemfile.lock
@@ -33,25 +33,13 @@ GEM
33 33
       rake
34 34
     arel (2.0.6)
35 35
     builder (2.1.2)
36  
-    capybara (0.4.0)
37  
-      celerity (>= 0.7.9)
38  
-      culerity (>= 0.2.4)
39  
-      mime-types (>= 1.16)
40  
-      nokogiri (>= 1.3.3)
41  
-      rack (>= 1.0.0)
42  
-      rack-test (>= 0.5.4)
43  
-      selenium-webdriver (>= 0.0.27)
44  
-      xpath (~> 0.1.2)
45  
-    celerity (0.8.4)
46  
-    childprocess (0.1.4)
47  
-      ffi (~> 0.6.3)
48  
-    culerity (0.2.12)
49 36
     erubis (2.6.6)
50 37
       abstract (>= 1.0.0)
51  
-    ffi (0.6.3)
52  
-      rake (>= 0.8.7)
  38
+    factory_girl (1.3.2)
  39
+    factory_girl_rails (1.0)
  40
+      factory_girl (~> 1.3)
  41
+      rails (>= 3.0.0.beta4)
53 42
     i18n (0.5.0)
54  
-    json_pure (1.4.6)
55 43
     mail (2.2.12)
56 44
       activesupport (>= 2.3.6)
57 45
       i18n (>= 0.4.0)
@@ -60,7 +48,6 @@ GEM
60 48
     mime-types (1.16)
61 49
     mocha (0.9.10)
62 50
       rake
63  
-    nokogiri (1.4.4)
64 51
     pg (0.10.0)
65 52
     polyglot (0.3.1)
66 53
     rack (1.2.1)
@@ -83,28 +70,18 @@ GEM
83 70
       thor (~> 0.14.4)
84 71
     rake (0.8.7)
85 72
     redgreen (1.2.2)
86  
-    rubyzip (0.9.4)
87  
-    selenium-webdriver (0.1.1)
88  
-      childprocess (= 0.1.4)
89  
-      ffi (~> 0.6.3)
90  
-      json_pure
91  
-      rubyzip
92  
-    shoulda (2.11.3)
93 73
     thor (0.14.6)
94 74
     treetop (1.4.9)
95 75
       polyglot (>= 0.3.1)
96 76
     tzinfo (0.3.23)
97  
-    xpath (0.1.2)
98  
-      nokogiri (~> 1.3)
99 77
 
100 78
 PLATFORMS
101 79
   ruby
102 80
 
103 81
 DEPENDENCIES
104 82
   appraisal
105  
-  capybara (>= 0.4.0)
  83
+  factory_girl_rails
106 84
   mocha
107 85
   pg
108 86
   rails (= 3.0.3)
109 87
   redgreen
110  
-  shoulda
3  gemfiles/rails-3.0.3-database-sqlite3-ruby.gemfile
@@ -3,8 +3,7 @@
3 3
 source "http://rubygems.org"
4 4
 gem "rails", "3.0.3"
5 5
 gem "sqlite3-ruby"
6  
-gem "shoulda"
7 6
 gem "mocha"
8 7
 gem "redgreen"
9 8
 gem "appraisal"
10  
-gem "capybara", ">= 0.4.0"
  9
+gem "factory_girl_rails"
33  gemfiles/rails-3.0.3-database-sqlite3-ruby.gemfile.lock
@@ -33,25 +33,13 @@ GEM
33 33
       rake
34 34
     arel (2.0.6)
35 35
     builder (2.1.2)
36  
-    capybara (0.4.0)
37  
-      celerity (>= 0.7.9)
38  
-      culerity (>= 0.2.4)
39  
-      mime-types (>= 1.16)
40  
-      nokogiri (>= 1.3.3)
41  
-      rack (>= 1.0.0)
42  
-      rack-test (>= 0.5.4)
43  
-      selenium-webdriver (>= 0.0.27)
44  
-      xpath (~> 0.1.2)
45  
-    celerity (0.8.4)
46  
-    childprocess (0.1.4)
47  
-      ffi (~> 0.6.3)
48  
-    culerity (0.2.12)
49 36
     erubis (2.6.6)
50 37
       abstract (>= 1.0.0)
51  
-    ffi (0.6.3)
52  
-      rake (>= 0.8.7)
  38
+    factory_girl (1.3.2)
  39
+    factory_girl_rails (1.0)
  40
+      factory_girl (~> 1.3)
  41
+      rails (>= 3.0.0.beta4)
53 42
     i18n (0.5.0)
54  
-    json_pure (1.4.6)
55 43
     mail (2.2.12)
56 44
       activesupport (>= 2.3.6)
57 45
       i18n (>= 0.4.0)
@@ -60,7 +48,6 @@ GEM
60 48
     mime-types (1.16)
61 49
     mocha (0.9.10)
62 50
       rake
63  
-    nokogiri (1.4.4)
64 51
     polyglot (0.3.1)
65 52
     rack (1.2.1)
66 53
     rack-mount (0.6.13)
@@ -82,29 +69,19 @@ GEM
82 69
       thor (~> 0.14.4)
83 70
     rake (0.8.7)
84 71
     redgreen (1.2.2)
85  
-    rubyzip (0.9.4)
86  
-    selenium-webdriver (0.1.1)
87  
-      childprocess (= 0.1.4)
88  
-      ffi (~> 0.6.3)
89  
-      json_pure
90  
-      rubyzip
91  
-    shoulda (2.11.3)
92 72
     sqlite3-ruby (1.3.2)
93 73
     thor (0.14.6)
94 74
     treetop (1.4.9)
95 75
       polyglot (>= 0.3.1)
96 76
     tzinfo (0.3.23)
97  
-    xpath (0.1.2)
98  
-      nokogiri (~> 1.3)
99 77
 
100 78
 PLATFORMS
101 79
   ruby
102 80
 
103 81
 DEPENDENCIES
104 82
   appraisal
105  
-  capybara (>= 0.4.0)
  83
+  factory_girl_rails
106 84
   mocha
107 85
   rails (= 3.0.3)
108 86
   redgreen
109  
-  shoulda
110 87
   sqlite3-ruby
8  lib/pacecar/datetime.rb
@@ -43,19 +43,19 @@ def define_inside_outside_scopes(name)
43 43
           { :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} >= ? and #{quoted_table_name}.#{connection.quote_column_name name} <= ?", start, stop] }
44 44
         }
45 45
         scope "#{name}_outside".to_sym, lambda { |start, stop|
46  
-          { :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} <= ? and #{quoted_table_name}.#{connection.quote_column_name name} >= ?", start, stop] }
  46
+          { :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} <= ? or #{quoted_table_name}.#{connection.quote_column_name name} >= ?", start, stop] }
47 47
         }
48 48
       end
49 49
 
50 50
       def define_in_date_scopes(name)
51 51
         scope "#{name}_in_year".to_sym, lambda { |year|
52  
-          { :conditions => ["year(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", year] }
  52
+          { :conditions => ["year(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", year.to_i] }
53 53
         }
54 54
         scope "#{name}_in_month".to_sym, lambda { |month|
55  
-          { :conditions => ["month(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", month] }
  55
+          { :conditions => ["month(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", month.to_i] }
56 56
         }
57 57
         scope "#{name}_in_day".to_sym, lambda { |day|
58  
-          { :conditions => ["day(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", day] }
  58
+          { :conditions => ["day(#{quoted_table_name}.#{connection.quote_column_name name}) = ?", day.to_i] }
59 59
         }
60 60
       end
61 61
 
6  lib/pacecar/duration.rb
@@ -13,13 +13,13 @@ def self.extended(base)
13 13
 
14 14
       def define_duration_scopes
15 15
         scope :with_duration_of, lambda { |duration, start, stop|
16  
-          { :conditions => ["datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop}) = ?", duration] }
  16
+          { :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) = ?", duration] }
17 17
         }
18 18
         scope :with_duration_over, lambda { |duration, start, stop|
19  
-          { :conditions => ["datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop}) > ?", duration] }
  19
+          { :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) > ?", duration] }
20 20
         }
21 21
         scope :with_duration_under, lambda { |duration, start, stop|
22  
-          { :conditions => ["datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop}) < ?", duration] }
  22
+          { :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) < ?", duration] }
23 23
         }
24 24
       end
25 25
 
4  lib/pacecar/ranking.rb
@@ -16,8 +16,8 @@ def has_ranking(association)
16 16
       def define_ranking_scope(association, name, direction)
17 17
         scope "#{name}_#{association}",
18 18
         :joins => "inner join #{association} on #{association}.#{reflections[association].primary_key_name} = #{quoted_table_name}.#{connection.quote_column_name primary_key}",
19  
-        :select => "#{quoted_table_name}.*, count(#{quoted_table_name}.#{connection.quote_column_name primary_key}) as #{association}_count",
20  
-        :group => "#{association}.#{reflections[association].primary_key_name}",
  19
+        :select => "#{quoted_table_name}.*, count(#{reflections[association].quoted_table_name}.#{connection.quote_column_name reflections[association].primary_key_name}) as #{association}_count",
  20
+        :group => "#{quoted_table_name}.#{connection.quote_column_name primary_key}",
21 21
         :order => "#{association}_count #{direction}"
22 22
       end
23 23
 
8  lib/pacecar/search.rb
@@ -20,13 +20,13 @@ def define_search_scopes
20 20
         end
21 21
         text_and_string_column_names.each do |name|
22 22
           scope "#{name}_matches".to_sym, lambda { |query|
23  
-            { :conditions => ["#{quoted_table_name}.#{connection.quote_column_name(name)} LIKE :query", { :query => "%#{query}%" }] }
  23
+            { :conditions => ["lower(#{quoted_table_name}.#{connection.quote_column_name(name)}) LIKE lower(:query)", { :query => "%#{query}%" }] }
24 24
           }
25 25
           scope "#{name}_starts_with".to_sym, lambda { |query|
26  
-            { :conditions => ["#{quoted_table_name}.#{connection.quote_column_name(name)} LIKE :query", { :query => "#{query}%" }] }
  26
+            { :conditions => ["lower(#{quoted_table_name}.#{connection.quote_column_name(name)}) LIKE lower(:query)", { :query => "#{query}%" }] }
27 27
           }
28 28
           scope "#{name}_ends_with".to_sym, lambda { |query|
29  
-            { :conditions => ["#{quoted_table_name}.#{connection.quote_column_name(name)} LIKE :query", { :query => "%#{query}" }] }
  29
+            { :conditions => ["lower(#{quoted_table_name}.#{connection.quote_column_name(name)}) LIKE lower(:query)", { :query => "%#{query}" }] }
30 30
           }
31 31
         end
32 32
       end
@@ -37,7 +37,7 @@ def define_basic_search_scope
37 37
           query = args.flatten.first
38 38
           columns = opts[:on] || non_state_text_and_string_columns
39 39
           joiner = opts[:require].eql?(:all) ? 'AND' : 'OR'
40  
-          match = columns.collect { |name| "#{quoted_table_name}.#{connection.quote_column_name(name)} LIKE :query" }.join(" #{joiner} ")
  40
+          match = columns.collect { |name| "lower(#{quoted_table_name}.#{connection.quote_column_name(name)}) LIKE lower(:query)" }.join(" #{joiner} ")
41 41
           { :conditions => [match, { :query => "%#{query}%" } ] }
42 42
         }
43 43
       end
52  test/associations_test.rb
... ...
@@ -1,34 +1,30 @@
1 1
 require 'test_helper'
2 2
 
3  
-class AssociationsTest < Test::Unit::TestCase
  3
+class AssociationsTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class which has included Pacecar" do
6  
-    setup do
7  
-      @class = User
8  
-    end
9  
-    context "with recent_records methods" do
10  
-      setup do
11  
-        @time = 2.days.ago.to_datetime
12  
-      end
13  
-      should "set the correct options for a recent methods for one association" do
14  
-        expected =<<-SQL
15  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (((select count(*) from #{Comment.quoted_table_name} where #{Comment.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "user_id"} = #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(@class.primary_key)} and #{Comment.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name("created_at")} > '#{@time.to_s(:db)}') > 0))
16  
-        SQL
17  
-        assert_equal expected.strip, @class.recent_comments_since(@time).to_sql
18  
-      end
19  
-      should "set the correct options for a recent methods combining associations with or" do
20  
-        expected =<<-SQL
21  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (((select count(*) from #{Article.quoted_table_name} where #{Article.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "user_id"} = #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(@class.primary_key)} and #{Article.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name("created_at")} > '#{@time.to_s(:db)}') > 0) or ((select count(*) from #{Comment.quoted_table_name} where #{Comment.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "user_id"} = #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(@class.primary_key)} and #{Comment.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name("created_at")} > '#{@time.to_s(:db)}') > 0))
22  
-        SQL
23  
-        assert_equal expected.strip, @class.recent_articles_or_comments_since(@time).to_sql
24  
-      end
25  
-      should "set the correct options for a recent methods combining associations with and" do
26  
-        expected =<<-SQL
27  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (((select count(*) from #{Article.quoted_table_name} where #{Article.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "user_id"} = #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(@class.primary_key)} and #{Article.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name("created_at")} > '#{@time.to_s(:db)}') > 0) and ((select count(*) from #{Comment.quoted_table_name} where #{Comment.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "user_id"} = #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(@class.primary_key)} and #{Comment.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name("created_at")} > '#{@time.to_s(:db)}') > 0))
28  
-        SQL
29  
-        assert_equal expected.strip, @class.recent_articles_and_comments_since(@time).to_sql
30  
-      end
31  
-    end
  5
+  setup do
  6
+    @comment_user = Factory :user
  7
+    @post_user = Factory :user
  8
+    @both_user = Factory :user
  9
+    Factory :comment, :user => @comment_user, :created_at => 10.days.ago
  10
+    Factory :comment, :user => @comment_user, :created_at => 3.days.ago
  11
+    Factory :post, :owner => @post_user, :created_at => 10.days.ago
  12
+    Factory :post, :owner => @post_user, :created_at => 3.days.ago
  13
+
  14
+    Factory :comment, :user => @both_user, :created_at => 10.days.ago
  15
+    Factory :comment, :user => @both_user, :created_at => 3.days.ago
  16
+    Factory :post, :owner => @both_user, :created_at => 10.days.ago
  17
+    Factory :post, :owner => @both_user, :created_at => 3.days.ago
  18
+  end
  19
+
  20
+  test "set the correct options for a recent methods for one association" do
  21
+    assert_equal [@comment_user, @both_user], User.recent_comments_since(5.days.ago)
  22
+  end
  23
+  test "set the correct options for a recent methods combining associations with or" do
  24
+    assert_equal [@comment_user, @post_user, @both_user], User.recent_posts_or_comments_since(5.days.ago)
  25
+  end
  26
+  test "set the correct options for a recent methods combining associations with and" do
  27
+    assert_equal [@both_user], User.recent_posts_and_comments_since(5.days.ago)
32 28
   end
33 29
 
34 30
 end
59  test/boolean_test.rb
... ...
@@ -1,41 +1,30 @@
1 1
 require 'test_helper'
2 2
 
3  
-class BooleanTest < Test::Unit::TestCase
  3
+class BooleanTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class which has included Pacecar" do
6  
-    setup do
7  
-      @class = User
8  
-    end
9  
-    should "set the correct expected values for a boolean column method" do
10  
-      expected =<<-SQL
11  
-      SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "admin"} = #{ActiveRecord::Base.connection.quoted_true})
12  
-      SQL
13  
-      assert_equal expected.strip, @class.admin.to_sql
14  
-    end
15  
-    should "set the correct expected values for a not_ boolean column method" do
16  
-      expected =<<-SQL
17  
-      SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "admin"} = #{ActiveRecord::Base.connection.quoted_false})
18  
-      SQL
19  
-      assert_equal expected.strip, @class.not_admin.to_sql
20  
-    end
21  
-    context "With boolean column scopes that can count" do
22  
-      setup do
23  
-        @true_mock = mock
24  
-        @false_mock = mock
25  
-        @class.expects(:admin).returns @true_mock
26  
-        @class.expects(:not_admin).returns @false_mock
27  
-      end
28  
-      should "return correct value for balance class method when true greater than false" do
29  
-        @true_mock.expects(:count).returns 5
30  
-        @false_mock.expects(:count).returns 2
31  
-        assert_equal 3, @class.admin_balance
32  
-      end
33  
-      should "return correct value for balance class method when true less than false" do
34  
-        @true_mock.expects(:count).returns 2
35  
-        @false_mock.expects(:count).returns 5
36  
-        assert_equal -3, @class.admin_balance
37  
-      end
38  
-    end
  5
+  setup do
  6
+    @one = Factory :user, :admin => true
  7
+    @two = Factory :user, :admin => true
  8
+    @three = Factory :user, :admin => true
  9
+    @four = Factory :user, :admin => false
  10
+    @five = Factory :user, :admin => false
  11
+  end
  12
+
  13
+  test "set the correct expected values for a boolean column method" do
  14
+    assert_equal [@one, @two, @three], User.admin
  15
+  end
  16
+
  17
+  test "set the correct expected values for a not_ boolean column method" do
  18
+    assert_equal [@four, @five], User.not_admin
  19
+  end
  20
+
  21
+  test "return correct value for balance class method when true greater than false" do
  22
+    assert_equal 1, User.admin_balance
  23
+  end
  24
+
  25
+  test "return correct value for balance class method when true less than false" do
  26
+    3.times { Factory :user, :admin => false }
  27
+    assert_equal -2, User.admin_balance
39 28
   end
40 29
 
41 30
 end
175  test/datetime_test.rb
... ...
@@ -1,121 +1,80 @@
1 1
 require 'test_helper'
2 2
 
3  
-class DatetimeTest < Test::Unit::TestCase
  3
+class DatetimeTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class which has included Pacecar" do
6  
-    setup do
7  
-      @class = User
  5
+  setup do
  6
+    date = DateTime.parse '2000-01-01'
  7
+    @abe = Factory :user, :created_at => date, :rejected_at => date, :updated_at => date, :last_posted_on => date, :approved_at => date
  8
+
  9
+    date = DateTime.parse '2005-05-05'
  10
+    @bob = Factory :user, :created_at => date, :rejected_at => date, :updated_at => date, :last_posted_on => date, :approved_at => date
  11
+
  12
+    date = DateTime.parse '2010-10-10'
  13
+    @fox = Factory :user, :created_at => date, :rejected_at => date, :updated_at => date, :last_posted_on => date, :approved_at => date
  14
+  end
  15
+
  16
+  [:created_at, :rejected_at, :updated_at, :last_posted_on, :approved_at].each do |column|
  17
+    test "set the correct expected values for a #{column}_before method" do
  18
+      date = DateTime.parse '2003-01-01'
  19
+      assert_equal [@abe], User.send(:"#{column}_before", date)
  20
+    end
  21
+
  22
+    test "set the correct expected values for a #{column}_after datetime column method" do
  23
+      date = DateTime.parse '2007-01-01'
  24
+      assert_equal [@fox], User.send(:"#{column}_after", date)
  25
+    end
  26
+
  27
+    test "set the correct expected values for a #{column}_in_past method without a zone default" do
  28
+      assert_nil Time.zone_default
  29
+      now = DateTime.parse '2007-01-01'
  30
+      User.stubs(:now).returns now
  31
+      assert_equal [@abe, @bob], User.send(:"#{column}_in_past")
8 32
     end
9  
-    context "for each date and datetime column" do
10  
-      [:created_at, :rejected_at, :updated_at, :last_posted_on, :approved_at].each do |column|
11  
-        context "with before and after methods for #{column}" do
12  
-          setup do
13  
-            @time = 5.days.ago.to_datetime
14  
-          end
15  
-          should "set the correct expected values for a #{column}_before method" do
16  
-            expected =<<-SQL
17  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} <= '#{@time.to_s(:db)}')
18  
-            SQL
19  
-            assert_equal expected.strip, @class.send(:"#{column}_before", @time).to_sql
20  
-          end
21  
-          should "set the correct expected values for a after_ datetime column method" do
22  
-            expected =<<-SQL
23  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} >= '#{@time.to_s(:db)}')
24  
-            SQL
25  
-            assert_equal expected.strip, @class.send(:"#{column}_after", @time).to_sql
26  
-          end
27  
-        end
28 33
 
29  
-        context "with in_past and in_future methods" do
30  
-          setup do
31  
-            assert_nil Time.zone_default
32  
-            @now = Time.now.utc.to_datetime
33  
-            @class.stubs(:now).returns @now
34  
-          end
35  
-          should "set the correct expected values for a #{column}_in_past method" do
36  
-            expected =<<-SQL
37  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} <= '#{@now.to_s(:db)}')
38  
-            SQL
39  
-            assert_equal expected.strip, @class.send(:"#{column}_in_past").to_sql
40  
-          end
41  
-          should "set the correct expected values for a #{column}_in_future datetime column method" do
42  
-            expected =<<-SQL
43  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} >= '#{@now.to_s(:db)}')
44  
-            SQL
45  
-            assert_equal expected.strip, @class.send(:"#{column}_in_future").to_sql
46  
-          end
47  
-        end
  34
+    test "set the correct expected values for a #{column}_in_future datetime column method without a zone default" do
  35
+      assert_nil Time.zone_default
  36
+      now = DateTime.parse '2007-01-01'
  37
+      User.stubs(:now).returns now
  38
+      assert_equal [@fox], User.send(:"#{column}_in_future")
  39
+    end
48 40
 
49  
-        context "with in_past and in_future methods given a zone_default" do
50  
-          setup do
51  
-            Time.zone_default = Time.__send__(:get_zone, "UTC")
52  
-            @now = Time.zone_default.now.to_datetime
53  
-            Time.zone_default.stubs(:now).returns @now
54  
-          end
55  
-          teardown do
56  
-            Time.zone_default = nil
57  
-          end
58  
-          should "set the correct expected values for a #{column}_in_past method" do
59  
-            expected =<<-SQL
60  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} <= '#{@now.to_s(:db)}')
61  
-            SQL
62  
-            assert_equal expected.strip, @class.send(:"#{column}_in_past", @time).to_sql
63  
-          end
64  
-          should "set the correct expected values for a #{column}_in_future datetime column method" do
65  
-            expected =<<-SQL
66  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} >= '#{@now.to_s(:db)}')
67  
-            SQL
68  
-            assert_equal expected.strip, @class.send(:"#{column}_in_future", @time).to_sql
69  
-          end
70  
-        end
  41
+    test "set the correct expected values for a #{column}_in_past method given a zone_default" do
  42
+      Time.zone_default = Time.__send__(:get_zone, "UTC")
  43
+      now = DateTime.parse '2007-01-01'
  44
+      Time.zone_default.stubs(:now).returns now
  45
+      assert_equal [@abe, @bob], User.send(:"#{column}_in_past")
  46
+      Time.zone_default = nil
  47
+    end
71 48
 
72  
-        context "with _inside and _outside methods" do
73  
-          setup do
74  
-            @start = 3.days.ago.to_datetime
75  
-            @stop = 2.days.ago.to_datetime
76  
-          end
77  
-          should "set the correct expected values for a #{column}_inside method" do
78  
-            expected =<<-SQL
79  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} >= '#{@start.to_s(:db)}' and #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} <= '#{@stop.to_s(:db)}')
80  
-            SQL
81  
-            assert_equal expected.strip, @class.send(:"#{column}_inside", @start, @stop).to_sql
82  
-          end
83  
-          should "set the correct expected values for a #{column}_outside method" do
84  
-            expected =<<-SQL
85  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} <= '#{@start.to_s(:db)}' and #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column} >= '#{@stop.to_s(:db)}')
86  
-            SQL
87  
-            assert_equal expected.strip, @class.send(:"#{column}_outside", @start, @stop).to_sql
88  
-          end
89  
-        end
  49
+    test "set the correct expected values for a #{column}_in_future datetime column method given a zone_default" do
  50
+      Time.zone_default = Time.__send__(:get_zone, "UTC")
  51
+      now = DateTime.parse '2007-01-01'
  52
+      Time.zone_default.stubs(:now).returns now
  53
+      assert_equal [@fox], User.send(:"#{column}_in_future")
  54
+      Time.zone_default = nil
  55
+    end
90 56
 
91  
-        context "with year month and day methods" do
92  
-          setup do
93  
-            @year = '2000'
94  
-            @month = '01'
95  
-            @day = '01'
96  
-          end
97  
-          should "set the correct expected values for a #{column}_in_year method" do
98  
-            expected =<<-SQL
99  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (year(#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column}) = '#{@year}')
100  
-            SQL
101  
-            assert_equal expected.strip, @class.send(:"#{column}_in_year", @year).to_sql
102  
-          end
103  
-          should "set the correct expected values for a #{column}_in_month method" do
104  
-            expected =<<-SQL
105  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (month(#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column}) = '#{@month}')
106  
-            SQL
107  
-            assert_equal expected.strip, @class.send(:"#{column}_in_month", @month).to_sql
108  
-          end
109  
-          should "set the correct expected values for a #{column}_in_day method" do
110  
-            expected =<<-SQL
111  
-            SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (day(#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name column}) = '#{@day}')
112  
-            SQL
113  
-            assert_equal expected.strip, @class.send(:"#{column}_in_day", @day).to_sql
114  
-          end
115  
-        end
  57
+    test "set the correct expected values for a #{column}_inside method" do
  58
+      start = DateTime.parse '2003-01-01'
  59
+      stop = DateTime.parse '2007-01-01'
  60
+      assert_equal [@bob], User.send(:"#{column}_inside", start, stop)
  61
+    end
  62
+    test "set the correct expected values for a #{column}_outside method" do
  63
+      start = DateTime.parse '2003-01-01'
  64
+      stop = DateTime.parse '2007-01-01'
  65
+      assert_equal [@abe, @fox], User.send(:"#{column}_outside", start, stop)
  66
+    end
116 67
 
117  
-      end
  68
+    test "set the correct expected values for a #{column}_in_year method" do
  69
+      assert_equal [@abe], User.send(:"#{column}_in_year", '2000')
  70
+    end
  71
+    test "set the correct expected values for a #{column}_in_month method" do
  72
+      assert_equal [@bob], User.send(:"#{column}_in_month", '05')
118 73
     end
  74
+    test "set the correct expected values for a #{column}_in_day method" do
  75
+      assert_equal [@fox], User.send(:"#{column}_in_day", '10')
  76
+    end
  77
+
119 78
   end
120 79
 
121 80
 end
2  test/dummy/app/models/mammal.rb
@@ -2,4 +2,6 @@ class Mammal < ActiveRecord::Base
2 2
 
3 3
   include Pacecar
4 4
 
  5
+  has_many :posts, :as => :owner
  6
+
5 7
 end
2  test/dummy/app/models/user.rb
@@ -8,6 +8,6 @@ class User < ActiveRecord::Base
8 8
 
9 9
   has_ranking :comments
10 10
   has_recent_records :comments
11  
-  has_recent_records :articles, :comments
  11
+  has_recent_records :posts, :comments
12 12
 
13 13
 end
44  test/duration_test.rb
... ...
@@ -1,34 +1,22 @@
1 1
 require 'test_helper'
2 2
 
3  
-class DurationTest < Test::Unit::TestCase
  3
+class DurationTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class which has included Pacecar" do
6  
-    setup do
7  
-      @class = User
8  
-    end
9  
-    context "with duration methods" do
10  
-      setup do
11  
-        @days = 14
12  
-      end
13  
-      should "set the correct expected values for a with_duration_of datetime column method" do
14  
-        expected =<<-SQL
15  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (datediff(#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "created_at"}, #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "updated_at"}) = #{@days})
16  
-        SQL
17  
-        assert_equal expected.strip, @class.with_duration_of(@days, :created_at, :updated_at).to_sql
18  
-      end
19  
-      should "set the correct expected values for a with_duration_over datetime column method" do
20  
-        expected =<<-SQL
21  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (datediff(#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "created_at"}, #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "updated_at"}) > #{@days})
22  
-        SQL
23  
-        assert_equal expected.strip, @class.with_duration_over(@days, :created_at, :updated_at).to_sql
24  
-      end
25  
-      should "set the correct expected values for a with_duration_under datetime column method" do
26  
-        expected =<<-SQL
27  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (datediff(#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "created_at"}, #{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "updated_at"}) < #{@days})
28  
-        SQL
29  
-        assert_equal expected.strip, @class.with_duration_under(@days, :created_at, :updated_at).to_sql
30  
-      end
31  
-    end
  5
+  setup do
  6
+    @same_user = Factory :user, :created_at => 15.days.ago.midnight, :updated_at => 15.days.ago.midnight
  7
+    @updated_user = Factory :user, :created_at => 15.days.ago.midnight, :updated_at => 1.days.ago.midnight
  8
+  end
  9
+
  10
+  test "set the correct expected values for a with_duration_of datetime column method" do
  11
+    assert_equal [@updated_user], User.with_duration_of(14, :created_at, :updated_at)
  12
+  end
  13
+
  14
+  test "set the correct expected values for a with_duration_over datetime column method" do
  15
+    assert_equal [@updated_user], User.with_duration_over(10, :created_at, :updated_at)
  16
+  end
  17
+
  18
+  test "set the correct expected values for a with_duration_under datetime column method" do
  19
+    assert_equal [@same_user], User.with_duration_under(10, :created_at, :updated_at)
32 20
   end
33 21
 
34 22
 end
17  test/factories.rb
... ...
@@ -0,0 +1,17 @@
  1
+Factory.sequence(:age) { |n| n.to_i }
  2
+Factory.sequence(:rating) { |n| n.to_f }
  3
+
  4
+Factory.define :comment do |f|
  5
+  f.association :user
  6
+end
  7
+
  8
+Factory.define :mammal do |f|
  9
+end
  10
+
  11
+Factory.define :post do |f|
  12
+end
  13
+
  14
+Factory.define :user do |f|
  15
+  f.age     { Factory.next :age }
  16
+  f.rating  { Factory.next :rating }
  17
+end
86  test/helpers_test.rb
... ...
@@ -1,66 +1,46 @@
1 1
 require 'test_helper'
2 2
 
3  
-class HelpersTest < Test::Unit::TestCase
  3
+class HelpersTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class without a db table" do
6  
-    setup do
7  
-      @class = Article
8  
-    end
9  
-    should "return an empty array when asked about #safe_columns" do
10  
-      columns = @class.send :safe_columns
11  
-      assert_equal [], columns
12  
-    end
13  
-    should "survive an include of Pacecar" do
14  
-      assert_nothing_raised do
15  
-        @class.send :include, Pacecar
16  
-      end
  5
+  test "A class without a db table should return an empty array when asked about #safe_columns" do
  6
+    columns = Article.send :safe_columns
  7
+    assert_equal [], columns
  8
+  end
  9
+  test "A class without a db table should survive an include of Pacecar" do
  10
+    assert_nothing_raised do
  11
+      Article.send :include, Pacecar
17 12
     end
18 13
   end
19 14
 
20  
-  context "A class with a db table" do
21  
-    setup do
22  
-      @class = Comment
23  
-    end
24  
-    should "return columns for #safe_column_names" do
25  
-      column_names = @class.send :safe_column_names
26  
-      assert_equal ['id', 'user_id', 'description', 'created_at', 'updated_at'], column_names
27  
-    end
  15
+  test "A class with a db table should return columns for #safe_column_names" do
  16
+    column_names = Comment.safe_column_names
  17
+    assert_equal ['id', 'user_id', 'description', 'created_at', 'updated_at'], column_names
28 18
   end
29 19
 
30  
-  context "A class with many column types" do
31  
-    setup do
32  
-      @class = User
33  
-    end
34  
-    should "return boolean columns for #boolean_column_names" do
35  
-      column_names = @class.send :boolean_column_names
36  
-      assert_equal ['admin'], column_names
37  
-    end
38  
-    should "return non boolean columns for #non_boolean_column_names" do
39  
-      column_names = @class.send :non_boolean_column_names
40  
-      assert_equal ['id', 'approved_at', 'rejected_at', 'last_posted_on', 'first_name', 'last_name', 'description', 'age', 'rating', 'created_at', 'updated_at'], column_names
41  
-    end
42  
-    should "return datetime columns for #datetime_column_names" do
43  
-      column_names = @class.send :datetime_column_names
44  
-      assert_equal ['approved_at', 'rejected_at', 'last_posted_on', 'created_at', 'updated_at'], column_names
45  
-    end
46  
-    should "return text and string columns for #text_and_string_column_names" do
47  
-      column_names = @class.send :text_and_string_column_names
48  
-      assert_equal ['first_name', 'last_name', 'description'], column_names
49  
-    end
50  
-    should "return numeric columns for #numeric_column_names" do
51  
-      column_names = @class.send :numeric_column_names
52  
-      assert_equal ['id', 'age', 'rating'], column_names
53  
-    end
  20
+  test "A class with many column types should return boolean columns for #boolean_column_names" do
  21
+    column_names = User.boolean_column_names
  22
+    assert_equal ['admin'], column_names
  23
+  end
  24
+  test "A class with many column types should return non boolean columns for #non_boolean_column_names" do
  25
+    column_names = User.non_boolean_column_names
  26
+    assert_equal ['id', 'approved_at', 'rejected_at', 'last_posted_on', 'first_name', 'last_name', 'description', 'age', 'rating', 'created_at', 'updated_at'], column_names
  27
+  end
  28
+  test "A class with many column types should return datetime columns for #datetime_column_names" do
  29
+    column_names = User.datetime_column_names
  30
+    assert_equal ['approved_at', 'rejected_at', 'last_posted_on', 'created_at', 'updated_at'], column_names
  31
+  end
  32
+  test "A class with many column types should return text and string columns for #text_and_string_column_names" do
  33
+    column_names = User.text_and_string_column_names
  34
+    assert_equal ['first_name', 'last_name', 'description'], column_names
  35
+  end
  36
+  test "A class with many column types should return numeric columns for #numeric_column_names" do
  37
+    column_names = User.numeric_column_names
  38
+    assert_equal ['id', 'age', 'rating'], column_names
54 39
   end
55 40
 
56  
-  context "A class with a state column" do
57  
-    setup do
58  
-      @class = Post
59  
-    end
60  
-    should "return all non state text and string columns for #non_state_text_and_string_column_names" do
61  
-      column_names = @class.send :non_state_text_and_string_columns
62  
-      assert_equal ['title', 'body'], column_names
63  
-    end
  41
+  test "A class with a state column should return all non state text and string columns for #non_state_text_and_string_column_names" do
  42
+    column_names = Post.non_state_text_and_string_columns
  43
+    assert_equal ['title', 'body'], column_names
64 44
   end
65 45
 
66 46
 end
45  test/limit_test.rb
... ...
@@ -1,32 +1,25 @@
1 1
 require 'test_helper'
2 2
 
3  
-class LimitTest < Test::Unit::TestCase
  3
+class LimitTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class which has included Pacecar" do
6  
-    setup do
7  
-      @class = User
8  
-    end
9  
-    context "with order methods" do
10  
-      should "set the correct expected values for a by_ column method" do
11  
-        expected =<<-SQL
12  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} LIMIT 10
13  
-        SQL
14  
-        assert_equal expected.strip, @class.limited.to_sql
15  
-      end
16  
-      should "set the correct expected values for a by_ column method when sent args" do
17  
-        expected =<<-SQL
18  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} LIMIT 20
19  
-        SQL
20  
-        assert_equal expected.strip, @class.limited(20).to_sql
21  
-      end
22  
-      should "set the correct expected values for a by_ column method when per_page defined" do
23  
-        @class.expects(:per_page).returns 30
24  
-        expected =<<-SQL
25  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} LIMIT 30
26  
-        SQL
27  
-        assert_equal expected.strip, @class.limited.to_sql
28  
-      end
29  
-    end
  5
+  setup do
  6
+    50.times { Factory :user }
  7
+  end
  8
+
  9
+  test "set the correct expected values for a by_ column method" do
  10
+    assert_equal 50, User.count
  11
+    assert_equal 10, User.limited.all.size
  12
+  end
  13
+
  14
+  test "set the correct expected values for a by_ column method when sent args" do
  15
+    assert_equal 50, User.count
  16
+    assert_equal 20, User.limited(20).all.size
  17
+  end
  18
+
  19
+  test "set the correct expected values for a by_ column method when per_page defined" do
  20
+    User.expects(:per_page).returns 30
  21
+    assert_equal 50, User.count
  22
+    assert_equal 30, User.limited.all.size
30 23
   end
31 24
 
32 25
 end
93  test/numeric_test.rb
... ...
@@ -1,64 +1,43 @@
1 1
 require 'test_helper'
2 2
 
3  
-class NumericTest < Test::Unit::TestCase
  3
+class NumericTest < ActiveSupport::TestCase
4 4
 
5  
-  context "A class which has included Pacecar" do
6  
-    setup do
7  
-      @class = User
8  
-    end
9  
-    context "for an integer column" do
10  
-      should "set the correct expected values for a _greater_than column method" do
11  
-        expected =<<-SQL
12  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "age"} > 21)
13  
-        SQL
14  
-        assert_equal expected.strip, @class.age_greater_than(21).to_sql
15  
-      end
16  
-      should "set the correct expected values for a _greater_than_or_equal_to column method" do
17  
-        expected =<<-SQL
18  
-        SELECT #{@class.quoted_table_name}.* FROM #{@class.quoted_table_name} WHERE (#{@class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name "age"} >= 21)
19  
-        SQL
20  
-        assert_equal expected.strip, @class.age_greater_than_or_equal_to(21).to_sql
21  
-      end
22  
-      should "set the correct expected values for a _less_than column method" do
23  
-        expected =<<-SQL
24  
-        SELECT #{@class.quoted_table_name}.* FROM #{