pacecar 1.5.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +9 -1
- data/Appraisals +9 -17
- data/Gemfile +1 -1
- data/Gemfile.lock +93 -108
- data/MIT-LICENSE +1 -1
- data/README.md +10 -109
- data/Rakefile +9 -5
- data/TESTING.md +40 -0
- data/gemfiles/rails_4_mysql2_driver.gemfile +8 -0
- data/gemfiles/rails_4_pg_driver.gemfile +8 -0
- data/gemfiles/rails_4_sqlite3_driver.gemfile +8 -0
- data/lib/pacecar.rb +0 -10
- data/lib/pacecar/boolean.rb +8 -20
- data/lib/pacecar/helpers.rb +7 -16
- data/lib/pacecar/limit.rb +9 -9
- data/lib/pacecar/order.rb +9 -9
- data/lib/pacecar/polymorph.rb +5 -5
- data/lib/pacecar/presence.rb +8 -9
- data/lib/pacecar/search.rb +8 -32
- data/lib/pacecar/state.rb +13 -9
- data/lib/pacecar/version.rb +1 -1
- data/pacecar.gemspec +18 -16
- data/spec/boolean_spec.rb +6 -18
- data/spec/dummy/app/models/mammal.rb +1 -1
- data/spec/dummy/app/models/post.rb +2 -2
- data/spec/dummy/app/models/user.rb +1 -6
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +4 -26
- data/spec/dummy/config/boot.rb +3 -9
- data/spec/dummy/config/database.yml +1 -7
- data/spec/dummy/config/environment.rb +2 -2
- data/spec/dummy/config/environments/development.rb +15 -12
- data/spec/dummy/config/environments/production.rb +57 -26
- data/spec/dummy/config/environments/test.rb +16 -15
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +9 -3
- data/spec/dummy/config/initializers/secret_token.rb +7 -2
- data/spec/dummy/config/initializers/session_store.rb +1 -6
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +20 -2
- data/spec/dummy/config/routes.rb +22 -24
- data/spec/factories.rb +2 -2
- data/spec/helpers_spec.rb +18 -26
- data/spec/integration/navigation_spec.rb +4 -5
- data/spec/limit_spec.rb +11 -11
- data/spec/order_spec.rb +8 -8
- data/spec/pacecar_spec.rb +3 -3
- data/spec/polymorph_spec.rb +6 -6
- data/spec/presence_spec.rb +9 -9
- data/spec/search_spec.rb +14 -48
- data/spec/spec_helper.rb +11 -17
- data/spec/state_spec.rb +29 -29
- metadata +76 -70
- data/gemfiles/rails-3.0.11-database-mysql.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-mysql.gemfile.lock +0 -134
- data/gemfiles/rails-3.0.11-database-mysql2.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-mysql2.gemfile.lock +0 -134
- data/gemfiles/rails-3.0.11-database-pg.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-pg.gemfile.lock +0 -134
- data/gemfiles/rails-3.0.11-database-sqlite3-ruby.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-sqlite3-ruby.gemfile.lock +0 -136
- data/gemfiles/rails-3.0.11-database-sqlite3.gemfile +0 -8
- data/gemfiles/rails-3.0.11-database-sqlite3.gemfile.lock +0 -134
- data/gemfiles/rails-3.1.3-database-mysql.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-mysql.gemfile.lock +0 -144
- data/gemfiles/rails-3.1.3-database-mysql2.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-mysql2.gemfile.lock +0 -144
- data/gemfiles/rails-3.1.3-database-pg.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-pg.gemfile.lock +0 -144
- data/gemfiles/rails-3.1.3-database-sqlite3-ruby.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-sqlite3-ruby.gemfile.lock +0 -146
- data/gemfiles/rails-3.1.3-database-sqlite3.gemfile +0 -8
- data/gemfiles/rails-3.1.3-database-sqlite3.gemfile.lock +0 -144
- data/lib/pacecar/associations.rb +0 -39
- data/lib/pacecar/datetime.rb +0 -91
- data/lib/pacecar/duration.rb +0 -51
- data/lib/pacecar/numeric.rb +0 -29
- data/lib/pacecar/ranking.rb +0 -53
- data/spec/associations_spec.rb +0 -32
- data/spec/datetime_spec.rb +0 -92
- data/spec/duration_spec.rb +0 -22
- data/spec/numeric_spec.rb +0 -43
- data/spec/ranking_spec.rb +0 -63
data/lib/pacecar/numeric.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Pacecar
|
2
|
-
module Numeric
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def self.extended(base)
|
9
|
-
base.send :define_numeric_scopes
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def define_numeric_scopes
|
15
|
-
numeric_column_names.each do |name|
|
16
|
-
{ :greater_than => '>', :less_than => '<' }.each do |method_name, symbol|
|
17
|
-
scope "#{name}_#{method_name}".to_sym, lambda { |value|
|
18
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} #{symbol} ?", value] }
|
19
|
-
}
|
20
|
-
scope "#{name}_#{method_name}_or_equal_to".to_sym, lambda { |value|
|
21
|
-
{ :conditions => ["#{quoted_table_name}.#{connection.quote_column_name name} #{symbol}= ?", value] }
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/pacecar/ranking.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Pacecar
|
2
|
-
module Ranking
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
|
9
|
-
def has_ranking(association)
|
10
|
-
define_ranking_scope association, :maximum, :desc
|
11
|
-
define_ranking_scope association, :minimum, :asc
|
12
|
-
end
|
13
|
-
|
14
|
-
def has_calculated_records(*names)
|
15
|
-
opts = names.extract_options!
|
16
|
-
names.each do |association_name|
|
17
|
-
*columns = opts[:on] || []
|
18
|
-
columns.flatten.each do |column|
|
19
|
-
define_calculated_scope association_name, column, :average, :avg
|
20
|
-
define_calculated_scope association_name, column, :total, :sum
|
21
|
-
define_calculated_scope association_name, column, :count, :count
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def define_ranking_scope(association, direction_name, direction)
|
29
|
-
scope "#{direction_name}_#{association}", {
|
30
|
-
:select => "#{quoted_table_name}.*, count(#{reflections[association].quoted_table_name}.#{connection.quote_column_name(reflections[association].respond_to?(:foreign_key) ? reflections[association].foreign_key : reflections[association].primary_key_name)}) as #{association}_count",
|
31
|
-
:order => "#{association}_count #{direction}"
|
32
|
-
}.merge(association_group_and_join(association))
|
33
|
-
end
|
34
|
-
|
35
|
-
def define_calculated_scope(association_name, column, function_name, function_method)
|
36
|
-
{ 'highest' => 'desc', 'lowest' => 'asc' }.each do |direction_name, direction|
|
37
|
-
scope "by_#{association_name}_#{direction_name}_#{column}_#{function_name}".to_sym, {
|
38
|
-
:select => "#{quoted_table_name}.*, #{function_method}(#{connection.quote_table_name(association_name)}.#{connection.quote_column_name column}) as #{association_name}_#{column}_#{function_name}",
|
39
|
-
:order => "#{association_name}_#{column}_#{function_name} #{direction}"
|
40
|
-
}.merge(association_group_and_join(association_name))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def association_group_and_join(association_name)
|
45
|
-
{
|
46
|
-
:joins => "inner join #{connection.quote_table_name(association_name)} on #{connection.quote_table_name(association_name)}.#{connection.quote_column_name(reflections[association_name].respond_to?(:foreign_key) ? reflections[association_name].foreign_key : reflections[association_name].primary_key_name)} = #{quoted_table_name}.#{connection.quote_column_name primary_key}",
|
47
|
-
:group => safe_column_names.collect { |column_name| "#{quoted_table_name}.#{connection.quote_column_name(column_name)}" }.join(', ')
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/spec/associations_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Associations', 'has recent records' do
|
4
|
-
|
5
|
-
before 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
|
-
it "should set the correct options for a recent methods for one association" do
|
21
|
-
User.recent_comments_since(5.days.ago).should == [@comment_user, @both_user]
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should set the correct options for a recent methods combining associations with or" do
|
25
|
-
User.recent_posts_or_comments_since(5.days.ago).should == [@comment_user, @post_user, @both_user]
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should set the correct options for a recent methods combining associations with and" do
|
29
|
-
User.recent_posts_and_comments_since(5.days.ago).should == [@both_user]
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/datetime_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Datetime' do
|
4
|
-
|
5
|
-
before 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
|
-
describe "before and after methods" do
|
18
|
-
it "should set the correct expected values for a #{column}_before method" do
|
19
|
-
date = DateTime.parse '2003-01-01'
|
20
|
-
User.send(:"#{column}_before", date).should == [@abe]
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should set the correct expected values for a #{column}_after datetime column method" do
|
24
|
-
date = DateTime.parse '2007-01-01'
|
25
|
-
User.send(:"#{column}_after", date).should == [@fox]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "past and future methods" do
|
30
|
-
it "should set the correct expected values for a #{column}_in_past method without a zone default" do
|
31
|
-
Time.zone_default = nil
|
32
|
-
Time.zone_default.should == nil
|
33
|
-
now = DateTime.parse '2007-01-01'
|
34
|
-
User.stubs(:now).returns now
|
35
|
-
User.send(:"#{column}_in_past").should == [@abe, @bob]
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should set the correct expected values for a #{column}_in_future datetime column method without a zone default" do
|
39
|
-
Time.zone_default = nil
|
40
|
-
Time.zone_default.should == nil
|
41
|
-
now = DateTime.parse '2007-01-01'
|
42
|
-
User.stubs(:now).returns now
|
43
|
-
User.send(:"#{column}_in_future").should == [@fox]
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should set the correct expected values for a #{column}_in_past method given a zone_default" do
|
47
|
-
Time.zone_default = Time.respond_to?(:find_zone) ? Time.find_zone("UTC") : Time.__send__(:get_zone, "UTC")
|
48
|
-
now = DateTime.parse '2007-01-01'
|
49
|
-
Time.zone_default.stubs(:now).returns now
|
50
|
-
User.send(:"#{column}_in_past").should == [@abe, @bob]
|
51
|
-
Time.zone_default = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should set the correct expected values for a #{column}_in_future datetime column method given a zone_default" do
|
55
|
-
Time.zone_default = Time.respond_to?(:find_zone) ? Time.find_zone("UTC") : Time.__send__(:get_zone, "UTC")
|
56
|
-
now = DateTime.parse '2007-01-01'
|
57
|
-
Time.zone_default.stubs(:now).returns now
|
58
|
-
User.send(:"#{column}_in_future").should == [@fox]
|
59
|
-
Time.zone_default = nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "inside and outside methods" do
|
64
|
-
it "should set the correct expected values for a #{column}_inside method" do
|
65
|
-
start = DateTime.parse '2003-01-01'
|
66
|
-
stop = DateTime.parse '2007-01-01'
|
67
|
-
User.send(:"#{column}_inside", start, stop).should == [@bob]
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should set the correct expected values for a #{column}_outside method" do
|
71
|
-
start = DateTime.parse '2003-01-01'
|
72
|
-
stop = DateTime.parse '2007-01-01'
|
73
|
-
User.send(:"#{column}_outside", start, stop).should == [@abe, @fox]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "year month and day methods" do
|
78
|
-
it "should set the correct expected values for a #{column}_in_year method" do
|
79
|
-
User.send(:"#{column}_in_year", '2000').should == [@abe]
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should set the correct expected values for a #{column}_in_month method" do
|
83
|
-
User.send(:"#{column}_in_month", '05').should == [@bob]
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should set the correct expected values for a #{column}_in_day method" do
|
87
|
-
User.send(:"#{column}_in_day", '10').should == [@fox]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
data/spec/duration_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Duration' do
|
4
|
-
|
5
|
-
before 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
|
-
it "should set the correct expected values for a with_duration_of datetime column method" do
|
11
|
-
User.with_duration_of(14, :created_at, :updated_at).should == [@updated_user]
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should set the correct expected values for a with_duration_over datetime column method" do
|
15
|
-
User.with_duration_over(10, :created_at, :updated_at).should == [@updated_user]
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should set the correct expected values for a with_duration_under datetime column method" do
|
19
|
-
User.with_duration_under(10, :created_at, :updated_at).should == [@same_user]
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/spec/numeric_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Numeric' do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@young = Factory :user, :age => 11, :rating => 10.0
|
7
|
-
@legal = Factory :user, :age => 21, :rating => 7.5
|
8
|
-
@older = Factory :user, :age => 31, :rating => 5.0
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should set the correct expected values for a _greater_than column method for an integer column" do
|
12
|
-
User.age_greater_than(21).should == [@older]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set the correct expected values for a _greater_than_or_equal_to column method for an integer column" do
|
16
|
-
User.age_greater_than_or_equal_to(21).should == [@legal, @older]
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should set the correct expected values for a _less_than column method for an integer column" do
|
20
|
-
User.age_less_than(21).should == [@young]
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should set the correct expected values for a _less_than_or_equal_to column method for an integer column" do
|
24
|
-
User.age_less_than_or_equal_to(21).should == [@young, @legal]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should set the correct expected values for a _greater_than column method for a float column" do
|
28
|
-
User.rating_greater_than(7.5).should == [@young]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should set the correct expected values for a _greater_than_or_equal_to column method for a float column" do
|
32
|
-
User.rating_greater_than_or_equal_to(7.5).should == [@young, @legal]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should set the correct expected values for a _less_than column method for a float column" do
|
36
|
-
User.rating_less_than(7.5).should == [@older]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should set the correct expected values for a _less_than_or_equal_to column method for a float column" do
|
40
|
-
User.rating_less_than_or_equal_to(7.5).should == [@legal, @older]
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
data/spec/ranking_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Ranking', 'has ranking' do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@many = Factory :user
|
7
|
-
5.times { Factory :comment, :user => @many }
|
8
|
-
@few = Factory :user
|
9
|
-
2.times { Factory :comment, :user => @few }
|
10
|
-
@none = Factory :user
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should set the correct expected values on a maximum_ column method" do
|
14
|
-
output = User.maximum_comments
|
15
|
-
output.should == [@many, @few]
|
16
|
-
output.first.comments_count.to_i.should == 5
|
17
|
-
output.last.comments_count.to_i.should == 2
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should set the correct expected values on a minimum_ column method" do
|
21
|
-
output = User.minimum_comments
|
22
|
-
output.should == [@few, @many]
|
23
|
-
output.first.comments_count.to_i.should == 2
|
24
|
-
output.last.comments_count.to_i.should == 5
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'Ranking', 'has calculated records' do
|
30
|
-
before do
|
31
|
-
@user_one = Factory :user
|
32
|
-
@user_two = Factory :user
|
33
|
-
Factory :comment, :user => @user_one, :rating => 8
|
34
|
-
Factory :comment, :user => @user_one, :rating => 6
|
35
|
-
Factory :comment, :user => @user_two, :rating => 4
|
36
|
-
Factory :comment, :user => @user_two, :rating => 3
|
37
|
-
Factory :comment, :user => @user_two, :rating => 2
|
38
|
-
end
|
39
|
-
it "should order records based on association column highest average" do
|
40
|
-
output = User.by_comments_highest_rating_average
|
41
|
-
output.should == [@user_one, @user_two]
|
42
|
-
output.first.comments_rating_average.to_i.should == 7
|
43
|
-
output.last.comments_rating_average.to_i.should == 3
|
44
|
-
end
|
45
|
-
it "should order records based on association column lowest average" do
|
46
|
-
output = User.by_comments_lowest_rating_average
|
47
|
-
output.should == [@user_two, @user_one]
|
48
|
-
output.first.comments_rating_average.to_i.should == 3
|
49
|
-
output.last.comments_rating_average.to_i.should == 7
|
50
|
-
end
|
51
|
-
it "should order records based on association column highest total" do
|
52
|
-
output = User.by_comments_highest_rating_total
|
53
|
-
output.should == [@user_one, @user_two]
|
54
|
-
output.first.comments_rating_total.to_i.should == 14
|
55
|
-
output.last.comments_rating_total.to_i.should == 9
|
56
|
-
end
|
57
|
-
it "should order records based on association column lowest total" do
|
58
|
-
output = User.by_comments_lowest_rating_total
|
59
|
-
output.should == [@user_two, @user_one]
|
60
|
-
output.first.comments_rating_total.to_i.should == 9
|
61
|
-
output.last.comments_rating_total.to_i.should == 14
|
62
|
-
end
|
63
|
-
end
|