github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jnunemaker / mongomapper

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 714
    • 142
  • Source
  • Commits
  • Network (142)
  • Downloads (33)
  • Wiki (4)
  • Graphs
  • Tree: 1831798

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (33)
    • v0.6.10
    • v0.6.9
    • v0.6.8
    • v0.6.7
    • v0.6.6
    • v0.6.5
    • v0.6.4
    • v0.6.3
    • v0.6.2
    • v0.6.1
    • v0.6.0
    • v0.5.8
    • v0.5.7
    • v0.5.6
    • v0.5.5
    • v0.5.4
    • v0.5.3
    • v0.5.2
    • v0.5.1
    • v0.5.0
    • v0.4.2
    • v0.4.1
    • v0.4.0
    • v0.3.5
    • v0.3.4
    • v0.3.3
    • v0.3.2
    • v0.3.1
    • v0.3.0
    • v0.2.0
    • v0.1.2
    • v0.1.1
    • v0.1.0
Sending Request…
Click here to lend your support to: mongomapper and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Awesome gem for modeling your domain and storing it in mongo — Read more

  cancel

http://mongomapper.com

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added gemspec to repo. 
jnunemaker (author)
Fri Jun 26 21:24:37 -0700 2009
commit  1831798fe3b8b2aea398435a4b1ea6f29f1a63c5
tree    22b96914a2bf153926c1465afa980acfb56b8c83
parent  d436116300ae554956064aef3b4b7f9c3ab32db7
mongomapper / test / test_finder_options.rb test/test_finder_options.rb
100644 134 lines (109 sloc) 4.062 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
require 'test_helper'
 
class FinderOptionsTest < Test::Unit::TestCase
  include MongoMapper
  
  should "raise error if provided something other than a hash" do
    lambda { FinderOptions.new }.should raise_error(ArgumentError)
    lambda { FinderOptions.new(1) }.should raise_error(ArgumentError)
  end
  
  should "have symbolize the keys of the hash provided" do
    FinderOptions.new('offset' => 1).options.keys.map do |key|
      key.should be_instance_of(Symbol)
    end
  end
  
  context "Converting conditions to criteria" do
    should "work with simple criteria" do
      FinderOptions.new(:conditions => {:foo => 'bar'}).criteria.should == {
        :foo => 'bar'
      }
      
      FinderOptions.new(:conditions => {:foo => 'bar', :baz => 'wick'}).criteria.should == {
        :foo => 'bar',
        :baz => 'wick'
      }
    end
    
    should "use $in for arrays" do
      FinderOptions.new(:conditions => {:foo => [1,2,3]}).criteria.should == {
        :foo => {'$in' => [1,2,3]}
      }
    end
    
    should "work arbitrarily deep" do
      FinderOptions.new(:conditions => {:foo => {:bar => [1,2,3]}}).criteria.should == {
        :foo => {:bar => {'$in' => [1,2,3]}}
      }
    end
  end
  
  context "ordering" do
    should "single field with ascending direction" do
      hash = OrderedHash.new
      hash[:foo] = 1
      FinderOptions.new(:order => 'foo asc').options[:sort].should == hash
      FinderOptions.new(:order => 'foo ASC').options[:sort].should == hash
    end
    
    should "single field with descending direction" do
      hash = OrderedHash.new
      hash[:foo] = -1
      FinderOptions.new(:order => 'foo desc').options[:sort].should == hash
      FinderOptions.new(:order => 'foo DESC').options[:sort].should == hash
    end
    
    should "convert field without direction to ascending" do
      hash = OrderedHash.new
      hash[:foo] = 1
      FinderOptions.new(:order => 'foo').options[:sort].should == hash
    end
    
    should "convert multiple fields with directions" do
      hash = OrderedHash.new
      hash[:foo] = -1
      hash[:bar] = 1
      hash[:baz] = -1
      options = FinderOptions.new(:order => 'foo desc, bar asc, baz desc').options[:sort].should == hash
    end
    
    should "convert multiple fields with some missing directions" do
      hash = OrderedHash.new
      hash[:foo] = -1
      hash[:bar] = 1
      hash[:baz] = 1
      options = FinderOptions.new(:order => 'foo desc, bar, baz').options[:sort].should == hash
    end
  end
  
  context "offset" do
    should "default to 0" do
      FinderOptions.new({}).options[:offset].should == 0
    end
    
    should "use offset provided" do
      FinderOptions.new(:offset => 2).options[:offset].should == 2
    end
    
    should "covert string to integer" do
      FinderOptions.new(:offset => '2').options[:offset].should == 2
    end
  end
  
  context "limit" do
    should "default to 0" do
      FinderOptions.new({}).options[:limit].should == 0
    end
    
    should "use offset provided" do
      FinderOptions.new(:limit => 2).options[:limit].should == 2
    end
    
    should "covert string to integer" do
      FinderOptions.new(:limit => '2').options[:limit].should == 2
    end
  end
  
  context "fields" do
    should "default to nil" do
      FinderOptions.new({}).options[:fields].should be(nil)
    end
    
    should "be converted to nil if empty string" do
      FinderOptions.new(:fields => '').options[:fields].should be(nil)
    end
    
    should "be converted to nil if []" do
      FinderOptions.new(:fields => []).options[:fields].should be(nil)
    end
    
    should "should work with array" do
      FinderOptions.new({:fields => %w(a b)}).options[:fields].should == %w(a b)
    end
    
    should "convert comma separated list to array" do
      FinderOptions.new({:fields => 'a, b'}).options[:fields].should == %w(a b)
    end
    
    should "also work as select" do
      FinderOptions.new(:select => %w(a b)).options[:fields].should == %w(a b)
    end
  end
end # FinderOptionsTest
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server