Skip to content
This repository
Newer
Older
100644 64 lines (57 sloc) 2.308 kb
02fd5de2 »
2011-01-19 change to use rspec
1 require 'spec_helper'
2
c5727f9c »
2011-01-20 move calculated records method to ranking, allow them to share method…
3 describe 'Ranking', 'has ranking' do
02fd5de2 »
2011-01-19 change to use rspec
4
5 before do
a6191879 »
2012-04-02 avoid factory girl syntax deprecation warnings
6 @many = create :user
7 5.times { create :comment, :user => @many }
8 @few = create :user
9 2.times { create :comment, :user => @few }
10 @none = create :user
02fd5de2 »
2011-01-19 change to use rspec
11 end
12
13 it "should set the correct expected values on a maximum_ column method" do
b4abc546 »
2011-01-19 add association calculation method to order by results of a sql funct…
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
02fd5de2 »
2011-01-19 change to use rspec
18 end
19
20 it "should set the correct expected values on a minimum_ column method" do
b4abc546 »
2011-01-19 add association calculation method to order by results of a sql funct…
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
02fd5de2 »
2011-01-19 change to use rspec
25 end
26
27 end
c5727f9c »
2011-01-20 move calculated records method to ranking, allow them to share method…
28
29 describe 'Ranking', 'has calculated records' do
30 before do
a6191879 »
2012-04-02 avoid factory girl syntax deprecation warnings
31 @user_one = create :user
32 @user_two = create :user
33 create :comment, :user => @user_one, :rating => 8
34 create :comment, :user => @user_one, :rating => 6
35 create :comment, :user => @user_two, :rating => 4
36 create :comment, :user => @user_two, :rating => 3
37 create :comment, :user => @user_two, :rating => 2
c5727f9c »
2011-01-20 move calculated records method to ranking, allow them to share method…
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
Something went wrong with that request. Please try again.