redis_orm 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -0
- data/Manifest +32 -0
- data/Rakefile +7 -15
- data/TODO +5 -0
- data/lib/redis_orm/associations/belongs_to.rb +37 -3
- data/lib/redis_orm/associations/has_one.rb +32 -0
- data/lib/redis_orm/redis_orm.rb +47 -9
- data/redis_orm.gemspec +4 -4
- data/test/association_indices_test.rb +51 -28
- data/test/associations_test.rb +0 -59
- data/test/atomicity_test.rb +0 -7
- data/test/basic_functionality_test.rb +12 -28
- data/test/callbacks_test.rb +0 -70
- data/test/changes_array_test.rb +0 -6
- data/test/classes/album.rb +6 -0
- data/test/classes/article.rb +7 -0
- data/test/classes/book.rb +6 -0
- data/test/classes/catalog_item.rb +5 -0
- data/test/classes/category.rb +7 -0
- data/test/classes/city.rb +7 -0
- data/test/classes/comment.rb +26 -0
- data/test/classes/country.rb +5 -0
- data/test/classes/custom_user.rb +8 -0
- data/test/classes/cutout.rb +20 -0
- data/test/classes/cutout_aggregator.rb +5 -0
- data/test/classes/default_user.rb +10 -0
- data/test/classes/dynamic_finder_user.rb +8 -0
- data/test/classes/empty_person.rb +2 -0
- data/test/classes/giftcard.rb +6 -0
- data/test/classes/jigsaw.rb +4 -0
- data/test/classes/location.rb +5 -0
- data/test/classes/message.rb +4 -0
- data/test/classes/note.rb +5 -0
- data/test/classes/omni_user.rb +8 -0
- data/test/classes/person.rb +6 -0
- data/test/classes/photo.rb +21 -0
- data/test/classes/profile.rb +8 -0
- data/test/classes/sortable_user.rb +11 -0
- data/test/classes/timestamp.rb +3 -0
- data/test/classes/user.rb +39 -0
- data/test/classes/uuid_default_user.rb +12 -0
- data/test/classes/uuid_timestamp.rb +5 -0
- data/test/classes/uuid_user.rb +13 -0
- data/test/dynamic_finders_test.rb +9 -26
- data/test/exceptions_test.rb +1 -21
- data/test/has_one_has_many_test.rb +0 -12
- data/test/indices_test.rb +0 -18
- data/test/modules/belongs_to_model_within_module.rb +6 -0
- data/test/modules/has_many_model_within_module.rb +11 -0
- data/test/options_test.rb +0 -37
- data/test/polymorphic_test.rb +0 -39
- data/test/sortable_test.rb +60 -74
- data/test/test_helper.rb +4 -0
- data/test/uuid_as_id_test.rb +38 -70
- data/test/validations_test.rb +0 -8
- metadata +45 -12
@@ -0,0 +1,12 @@
|
|
1
|
+
class UuidDefaultUser < RedisOrm::Base
|
2
|
+
use_uuid_as_id
|
3
|
+
|
4
|
+
property :name, String, :default => "german"
|
5
|
+
property :age, Integer, :default => 26
|
6
|
+
property :wage, Float, :default => 256.25
|
7
|
+
property :male, RedisOrm::Boolean, :default => true
|
8
|
+
property :admin, RedisOrm::Boolean, :default => false
|
9
|
+
|
10
|
+
property :created_at, Time
|
11
|
+
property :modified_at, Time
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class UuidUser < RedisOrm::Base
|
2
|
+
use_uuid_as_id
|
3
|
+
|
4
|
+
property :name, String
|
5
|
+
property :age, Integer
|
6
|
+
property :wage, Float
|
7
|
+
property :male, RedisOrm::Boolean
|
8
|
+
|
9
|
+
property :created_at, Time
|
10
|
+
property :modified_at, Time
|
11
|
+
|
12
|
+
has_many :users, :as => :friends
|
13
|
+
end
|
@@ -1,46 +1,28 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class User < RedisOrm::Base
|
4
|
-
property :first_name, String
|
5
|
-
property :last_name, String
|
6
|
-
|
7
|
-
index :first_name, :unique => true
|
8
|
-
index :last_name, :unique => true
|
9
|
-
index [:first_name, :last_name], :unique => false
|
10
|
-
end
|
11
|
-
|
12
|
-
class CustomUser < RedisOrm::Base
|
13
|
-
property :first_name, String
|
14
|
-
property :last_name, String
|
15
|
-
|
16
|
-
index :first_name, :unique => false
|
17
|
-
index :last_name, :unique => false
|
18
|
-
index [:first_name, :last_name], :unique => true
|
19
|
-
end
|
20
|
-
|
21
3
|
describe "check associations" do
|
22
4
|
it "should create and use indexes to implement dynamic finders" do
|
23
|
-
user1 =
|
5
|
+
user1 = DynamicFinderUser.new
|
24
6
|
user1.first_name = "Dmitrii"
|
25
7
|
user1.last_name = "Samoilov"
|
26
8
|
user1.save
|
27
9
|
|
28
|
-
|
10
|
+
DynamicFinderUser.find_by_first_name("John").should == nil
|
29
11
|
|
30
|
-
user =
|
12
|
+
user = DynamicFinderUser.find_by_first_name "Dmitrii"
|
31
13
|
user.id.should == user1.id
|
32
14
|
|
33
|
-
|
15
|
+
DynamicFinderUser.find_all_by_first_name("Dmitrii").size.should == 1
|
34
16
|
|
35
|
-
user =
|
17
|
+
user = DynamicFinderUser.find_by_first_name_and_last_name('Dmitrii', 'Samoilov')
|
36
18
|
user.should be
|
37
19
|
user.id.should == user1.id
|
38
20
|
|
39
|
-
|
21
|
+
DynamicFinderUser.find_all_by_first_name_and_last_name('Dmitrii', 'Samoilov').size.should == 1
|
40
22
|
|
41
|
-
|
23
|
+
DynamicFinderUser.find_all_by_last_name_and_first_name('Samoilov', 'Dmitrii')[0].id.should == user1.id
|
42
24
|
|
43
|
-
lambda{
|
25
|
+
lambda{DynamicFinderUser.find_by_first_name_and_cast_name('Dmitrii', 'Samoilov')}.should raise_error
|
44
26
|
end
|
45
27
|
|
46
28
|
it "should create and use indexes to implement dynamic finders" do
|
@@ -62,6 +44,7 @@ describe "check associations" do
|
|
62
44
|
CustomUser.find_all_by_first_name("Dmitrii").size.should == 2
|
63
45
|
end
|
64
46
|
|
47
|
+
# TODO
|
65
48
|
it "should properly delete indices when record was deleted" do
|
66
49
|
|
67
50
|
end
|
data/test/exceptions_test.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class User < RedisOrm::Base
|
4
|
-
property :name, String
|
5
|
-
property :age, Integer
|
6
|
-
property :created_at, Time
|
7
|
-
|
8
|
-
index :age
|
9
|
-
|
10
|
-
has_one :profile
|
11
|
-
end
|
12
|
-
|
13
|
-
class Profile < RedisOrm::Base
|
14
|
-
property :title, String
|
15
|
-
belongs_to :user
|
16
|
-
end
|
17
|
-
|
18
|
-
class Jigsaw < RedisOrm::Base
|
19
|
-
property :title, String
|
20
|
-
belongs_to :user
|
21
|
-
end
|
22
|
-
|
23
3
|
describe "exceptions test" do
|
24
4
|
it "should raise an exception if association is provided with improper class" do
|
25
5
|
User.count.should == 0
|
@@ -31,7 +11,7 @@ describe "exceptions test" do
|
|
31
11
|
user.name.should == "german"
|
32
12
|
User.count.should == 1
|
33
13
|
|
34
|
-
lambda{ User.find :all, :conditions => {:
|
14
|
+
lambda{ User.find :all, :conditions => {:gender => true} }.should raise_error
|
35
15
|
User.find(:all, :conditions => {:age => 26}).size.should == 1
|
36
16
|
lambda{ User.find :all, :conditions => {:name => "german", :age => 26} }.should raise_error
|
37
17
|
|
@@ -1,17 +1,5 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class Profile < RedisOrm::Base
|
4
|
-
property :name, String
|
5
|
-
|
6
|
-
has_one :location
|
7
|
-
end
|
8
|
-
|
9
|
-
class Location < RedisOrm::Base
|
10
|
-
property :coordinates, String
|
11
|
-
|
12
|
-
has_many :profiles
|
13
|
-
end
|
14
|
-
|
15
3
|
describe "check associations" do
|
16
4
|
it "should save associations properly" do
|
17
5
|
@profile = Profile.new
|
data/test/indices_test.rb
CHANGED
@@ -1,23 +1,5 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class User < RedisOrm::Base
|
4
|
-
property :first_name, String
|
5
|
-
property :last_name, String
|
6
|
-
|
7
|
-
index :first_name
|
8
|
-
index :last_name
|
9
|
-
index [:first_name, :last_name]
|
10
|
-
end
|
11
|
-
|
12
|
-
class OmniUser < RedisOrm::Base
|
13
|
-
property :email, String
|
14
|
-
property :uid, Integer
|
15
|
-
|
16
|
-
index :email, :case_insensitive => true
|
17
|
-
index :uid
|
18
|
-
index [:email, :uid], :case_insensitive => true
|
19
|
-
end
|
20
|
-
|
21
3
|
describe "check indices" do
|
22
4
|
it "should change index accordingly to the changes in the model" do
|
23
5
|
user = User.new :first_name => "Robert", :last_name => "Pirsig"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module HasManyModelWithinModule
|
2
|
+
class SpecialComment < RedisOrm::Base
|
3
|
+
property :body, String, :default => "test"
|
4
|
+
belongs_to :brochure, :as => :book
|
5
|
+
end
|
6
|
+
|
7
|
+
class Brochure < RedisOrm::Base
|
8
|
+
property :title, String
|
9
|
+
has_many :special_comments
|
10
|
+
end
|
11
|
+
end
|
data/test/options_test.rb
CHANGED
@@ -1,42 +1,5 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class Album < RedisOrm::Base
|
4
|
-
property :title, String
|
5
|
-
|
6
|
-
has_one :photo, :as => :front_photo
|
7
|
-
has_many :photos, :dependent => :destroy
|
8
|
-
end
|
9
|
-
|
10
|
-
class Category < RedisOrm::Base
|
11
|
-
property :title, String
|
12
|
-
|
13
|
-
has_many :photos, :dependent => :nullify
|
14
|
-
end
|
15
|
-
|
16
|
-
class Photo < RedisOrm::Base
|
17
|
-
property :image, String
|
18
|
-
property :image_type, String
|
19
|
-
|
20
|
-
property :checked, RedisOrm::Boolean, :default => false
|
21
|
-
index :checked
|
22
|
-
|
23
|
-
property :inverted, RedisOrm::Boolean, :default => true
|
24
|
-
index :inverted
|
25
|
-
|
26
|
-
index :image
|
27
|
-
index [:image, :image_type]
|
28
|
-
|
29
|
-
belongs_to :album
|
30
|
-
belongs_to :user
|
31
|
-
belongs_to :category
|
32
|
-
end
|
33
|
-
|
34
|
-
class User < RedisOrm::Base
|
35
|
-
property :name, String
|
36
|
-
|
37
|
-
has_one :photo, :dependent => :destroy
|
38
|
-
end
|
39
|
-
|
40
3
|
describe "test options" do
|
41
4
|
before(:each) do
|
42
5
|
@album = Album.new
|
data/test/polymorphic_test.rb
CHANGED
@@ -1,44 +1,5 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class CatalogItem < RedisOrm::Base
|
4
|
-
property :title, String
|
5
|
-
|
6
|
-
belongs_to :resource, :polymorphic => true
|
7
|
-
end
|
8
|
-
|
9
|
-
class Book < RedisOrm::Base
|
10
|
-
property :price, Integer, :default => 0 # in cents
|
11
|
-
property :title, String
|
12
|
-
|
13
|
-
has_one :catalog_item
|
14
|
-
end
|
15
|
-
|
16
|
-
class Giftcard < RedisOrm::Base
|
17
|
-
property :price, Integer, :default => 0 # in cents
|
18
|
-
property :title, String
|
19
|
-
|
20
|
-
has_one :catalog_item
|
21
|
-
end
|
22
|
-
|
23
|
-
# for second test
|
24
|
-
class Person < RedisOrm::Base
|
25
|
-
property :name, String
|
26
|
-
|
27
|
-
belongs_to :location, :polymorphic => true
|
28
|
-
end
|
29
|
-
|
30
|
-
class Country < RedisOrm::Base
|
31
|
-
property :name, String
|
32
|
-
|
33
|
-
has_many :people
|
34
|
-
end
|
35
|
-
|
36
|
-
class City < RedisOrm::Base
|
37
|
-
property :name, String
|
38
|
-
|
39
|
-
has_many :people
|
40
|
-
end
|
41
|
-
|
42
3
|
describe "check polymorphic property" do
|
43
4
|
it "should provide proper associations and save records correctly for has_one/belongs_to polymorphic" do
|
44
5
|
book = Book.new :title => "Permutation City", :author => "Egan Greg", :price => 1529
|
data/test/sortable_test.rb
CHANGED
@@ -1,130 +1,116 @@
|
|
1
1
|
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class User < RedisOrm::Base
|
4
|
-
property :name, String, :sortable => true
|
5
|
-
property :age, Integer, :sortable => true
|
6
|
-
property :wage, Float, :sortable => true
|
7
|
-
|
8
|
-
property :address, String
|
9
|
-
|
10
|
-
index :name
|
11
|
-
index :age
|
12
|
-
end
|
13
|
-
|
14
|
-
class SortableUser < RedisOrm::Base
|
15
|
-
property :name, String, :sortable => true
|
16
|
-
index :name
|
17
|
-
end
|
18
|
-
|
19
3
|
describe "test options" do
|
20
4
|
before(:each) do
|
21
|
-
@dan =
|
22
|
-
@abe =
|
23
|
-
@michael =
|
24
|
-
@todd =
|
5
|
+
@dan = SortableUser.create :name => "Daniel", :age => 26, :wage => 40000.0, :address => "Bellevue"
|
6
|
+
@abe = SortableUser.create :name => "Abe", :age => 30, :wage => 100000.0, :address => "Bellevue"
|
7
|
+
@michael = SortableUser.create :name => "Michael", :age => 25, :wage => 60000.0, :address => "Bellevue"
|
8
|
+
@todd = SortableUser.create :name => "Todd", :age => 22, :wage => 30000.0, :address => "Bellevue"
|
25
9
|
end
|
26
10
|
|
27
11
|
it "should return records in specified order" do
|
28
|
-
$redis.llen("
|
29
|
-
$redis.zcard("
|
30
|
-
$redis.zcard("
|
12
|
+
$redis.llen("sortable_user:name_ids").to_i.should == SortableUser.count
|
13
|
+
$redis.zcard("sortable_user:age_ids").to_i.should == SortableUser.count
|
14
|
+
$redis.zcard("sortable_user:wage_ids").to_i.should == SortableUser.count
|
31
15
|
|
32
|
-
|
33
|
-
|
16
|
+
SortableUser.find(:all, :order => [:name, :asc]).should == [@abe, @dan, @michael, @todd]
|
17
|
+
SortableUser.find(:all, :order => [:name, :desc]).should == [@todd, @michael, @dan, @abe]
|
34
18
|
|
35
|
-
|
36
|
-
|
19
|
+
SortableUser.find(:all, :order => [:age, :asc]).should == [@todd, @michael, @dan, @abe]
|
20
|
+
SortableUser.find(:all, :order => [:age, :desc]).should == [@abe, @dan, @michael, @todd]
|
37
21
|
|
38
|
-
|
39
|
-
|
22
|
+
SortableUser.find(:all, :order => [:wage, :asc]).should == [@todd, @dan, @michael, @abe]
|
23
|
+
SortableUser.find(:all, :order => [:wage, :desc]).should == [@abe, @michael, @dan, @todd]
|
40
24
|
end
|
41
25
|
|
42
26
|
it "should return records which met specified conditions in specified order" do
|
43
|
-
@abe2 =
|
27
|
+
@abe2 = SortableUser.create :name => "Abe", :age => 12, :wage => 10.0, :address => "Santa Fe"
|
44
28
|
|
45
29
|
# :asc should be default value for property in :order clause
|
46
|
-
|
30
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage]).should == [@abe2, @abe]
|
47
31
|
|
48
|
-
|
49
|
-
|
32
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :desc]).should == [@abe, @abe2]
|
33
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :asc]).should == [@abe2, @abe]
|
50
34
|
|
51
|
-
|
52
|
-
|
35
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:age, :desc]).should == [@abe, @abe2]
|
36
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:age, :asc]).should == [@abe2, @abe]
|
53
37
|
|
54
|
-
|
55
|
-
|
38
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :desc]).should == [@abe, @abe2]
|
39
|
+
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :asc]).should == [@abe2, @abe]
|
56
40
|
end
|
57
41
|
|
58
42
|
it "should update keys after the persisted object was edited and sort properly" do
|
59
43
|
@abe.update_attributes :name => "Zed", :age => 12, :wage => 10.0, :address => "Santa Fe"
|
60
44
|
|
61
|
-
$redis.llen("
|
62
|
-
$redis.zcard("
|
63
|
-
$redis.zcard("
|
45
|
+
$redis.llen("sortable_user:name_ids").to_i.should == SortableUser.count
|
46
|
+
$redis.zcard("sortable_user:age_ids").to_i.should == SortableUser.count
|
47
|
+
$redis.zcard("sortable_user:wage_ids").to_i.should == SortableUser.count
|
64
48
|
|
65
|
-
|
66
|
-
|
49
|
+
SortableUser.find(:all, :order => [:name, :asc]).should == [@dan, @michael, @todd, @abe]
|
50
|
+
SortableUser.find(:all, :order => [:name, :desc]).should == [@abe, @todd, @michael, @dan]
|
67
51
|
|
68
|
-
|
69
|
-
|
52
|
+
SortableUser.find(:all, :order => [:age, :asc]).should == [@abe, @todd, @michael, @dan]
|
53
|
+
SortableUser.find(:all, :order => [:age, :desc]).should == [@dan, @michael, @todd, @abe]
|
70
54
|
|
71
|
-
|
72
|
-
|
55
|
+
SortableUser.find(:all, :order => [:wage, :asc]).should == [@abe, @todd, @dan, @michael]
|
56
|
+
SortableUser.find(:all, :order => [:wage, :desc]).should == [@michael, @dan, @todd, @abe]
|
73
57
|
end
|
74
58
|
|
75
59
|
it "should update keys after the persisted object was deleted and sort properly" do
|
76
|
-
user_count =
|
60
|
+
user_count = SortableUser.count
|
77
61
|
@abe.destroy
|
78
62
|
|
79
|
-
$redis.llen("
|
80
|
-
$redis.zcard("
|
81
|
-
$redis.zcard("
|
63
|
+
$redis.llen("sortable_user:name_ids").to_i.should == user_count - 1
|
64
|
+
$redis.zcard("sortable_user:age_ids").to_i.should == user_count - 1
|
65
|
+
$redis.zcard("sortable_user:wage_ids").to_i.should == user_count - 1
|
82
66
|
|
83
|
-
|
84
|
-
|
67
|
+
SortableUser.find(:all, :order => [:name, :asc]).should == [@dan, @michael, @todd]
|
68
|
+
SortableUser.find(:all, :order => [:name, :desc]).should == [@todd, @michael, @dan]
|
85
69
|
|
86
|
-
|
87
|
-
|
70
|
+
SortableUser.find(:all, :order => [:age, :asc]).should == [@todd, @michael, @dan]
|
71
|
+
SortableUser.find(:all, :order => [:age, :desc]).should == [@dan, @michael, @todd]
|
88
72
|
|
89
|
-
|
90
|
-
|
73
|
+
SortableUser.find(:all, :order => [:wage, :asc]).should == [@todd, @dan, @michael]
|
74
|
+
SortableUser.find(:all, :order => [:wage, :desc]).should == [@michael, @dan, @todd]
|
91
75
|
end
|
92
76
|
|
93
77
|
it "should sort objects with more than 3-4 symbols" do
|
94
|
-
vladislav =
|
95
|
-
vladimir =
|
96
|
-
vlad =
|
78
|
+
vladislav = SortableUser.create :name => "Vladislav", :age => 19, :wage => 120.0
|
79
|
+
vladimir = SortableUser.create :name => "Vladimir", :age => 22, :wage => 220.5
|
80
|
+
vlad = SortableUser.create :name => "Vlad", :age => 29, :wage => 1200.0
|
97
81
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
82
|
+
SortableUser.find(:all, :order => [:name, :desc], :limit => 3).should == [vladislav, vladimir, vlad]
|
83
|
+
SortableUser.find(:all, :order => [:name, :desc], :limit => 2, :offset => 4).should == [@michael, @dan]
|
84
|
+
SortableUser.find(:all, :order => [:name, :desc], :offset => 3).should == [@todd, @michael, @dan, @abe]
|
85
|
+
SortableUser.find(:all, :order => [:name, :desc]).should == [vladislav, vladimir, vlad, @todd, @michael, @dan, @abe]
|
86
|
+
|
87
|
+
SortableUser.find(:all, :order => [:name, :asc], :limit => 3, :offset => 4).should == [vlad, vladimir, vladislav]
|
88
|
+
SortableUser.find(:all, :order => [:name, :asc], :offset => 3).should == [@todd, vlad, vladimir, vladislav]
|
89
|
+
SortableUser.find(:all, :order => [:name, :asc], :limit => 3).should == [@abe, @dan, @michael]
|
90
|
+
SortableUser.find(:all, :order => [:name, :asc]).should == [@abe, @dan, @michael, @todd, vlad, vladimir, vladislav]
|
107
91
|
end
|
108
92
|
|
109
93
|
it "should properly handle multiple users with almost the same names" do
|
110
|
-
users = []
|
94
|
+
users = [@abe, @todd, @michael, @dan]
|
111
95
|
20.times{|i| users << SortableUser.create(:name => "user#{i}") }
|
112
|
-
|
96
|
+
users.sort{|n,m| n.name <=> m.name}.should == SortableUser.all(:order => [:name, :asc])
|
113
97
|
end
|
114
98
|
|
115
99
|
it "should properly handle multiple users with almost the same names (descending order)" do
|
116
|
-
rev_users = []
|
100
|
+
rev_users = [@abe, @todd, @michael, @dan]
|
117
101
|
20.times{|i| rev_users << SortableUser.create(:name => "user#{i}") }
|
118
102
|
SortableUser.all(:order => [:name, :desc]).should == rev_users.sort{|n,m| n.name <=> m.name}.reverse
|
119
103
|
end
|
120
104
|
|
121
105
|
it "should properly store records with the same names" do
|
122
|
-
users = []
|
106
|
+
users = [@abe, @todd, @michael, @dan]
|
123
107
|
users << SortableUser.create(:name => "user#1")
|
124
108
|
users << SortableUser.create(:name => "user#2")
|
125
109
|
users << SortableUser.create(:name => "user#1")
|
126
110
|
users << SortableUser.create(:name => "user#2")
|
127
|
-
|
128
|
-
|
111
|
+
|
112
|
+
# we pluck only *name* here since it didn't sort by id (and it could be messed up)
|
113
|
+
SortableUser.all(:order => [:name, :desc]).map{|u| u.name}.should == users.sort{|n,m| n.name <=> m.name}.map{|u| u.name}.reverse
|
114
|
+
SortableUser.all(:order => [:name, :asc]).map{|u| u.name}.should == users.sort{|n,m| n.name <=> m.name}.map{|u| u.name}
|
129
115
|
end
|
130
116
|
end
|