ruby-ext-js 0.2.0 → 0.2.1
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/README.markdown +4 -0
- data/VERSION +1 -1
- data/lib/ruby-ext-js.rb +6 -6
- data/ruby-ext-js.gemspec +1 -1
- data/spec/ruby-ext-js_spec.rb +11 -11
- metadata +3 -3
data/README.markdown
CHANGED
@@ -65,6 +65,10 @@ Examples:
|
|
65
65
|
|
66
66
|
Version number conventions: Patch-level bumps for bug fixes, minor-level bumps for changes that break backwards-compatibility, major-level bumps for major new features.
|
67
67
|
|
68
|
+
## 0.2.1
|
69
|
+
|
70
|
+
* `ExtJs::Mongo.options` fixes.
|
71
|
+
|
68
72
|
## 0.2.0
|
69
73
|
|
70
74
|
* `ExtJs::Mongo.conditions` now returns a hash with string keys only instead of mixed string / symbol keys for better consistency with the [MongoDB Ruby driver](http://api.mongodb.org/ruby/1.2.0/index.html)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/ruby-ext-js.rb
CHANGED
@@ -22,7 +22,7 @@ module ExtJs
|
|
22
22
|
{
|
23
23
|
:order => [order],
|
24
24
|
:offset => offset,
|
25
|
-
|
25
|
+
:limit => limit
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
@@ -100,13 +100,13 @@ module ExtJs
|
|
100
100
|
protected
|
101
101
|
|
102
102
|
def self.skip_param( params )
|
103
|
-
return {
|
104
|
-
{
|
103
|
+
return { :skip => DEFAULT_SKIP } unless params.key?( "start" ) && params.key?( "limit" )
|
104
|
+
{ :skip => [params["start"].to_i, 0].max }
|
105
105
|
end
|
106
106
|
|
107
107
|
def self.limit_param( params )
|
108
|
-
return {
|
109
|
-
{
|
108
|
+
return { :limit => DEFAULT_LIMIT } unless params.key?( "limit" ) && params["limit"].to_i > 0
|
109
|
+
{ :limit => [params["limit"].to_i, MAX_LIMIT].min }
|
110
110
|
end
|
111
111
|
|
112
112
|
def self.sort_param( params )
|
@@ -115,7 +115,7 @@ module ExtJs
|
|
115
115
|
sort = params["sort"] ? params["sort"].to_sym : :id
|
116
116
|
dir = params["dir"] =~ /desc/i ? :desc : :asc
|
117
117
|
|
118
|
-
{
|
118
|
+
{ :sort => [sort, dir] }
|
119
119
|
end
|
120
120
|
|
121
121
|
def self.search_param( params )
|
data/ruby-ext-js.gemspec
CHANGED
data/spec/ruby-ext-js_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe "ExtJs" do
|
|
4
4
|
# describe "Postgres" do
|
5
5
|
# it "sorts on id when you ask it to sort on created_at" do
|
6
6
|
# ExtJs::Postgres.pagination_opts({
|
7
|
-
#
|
7
|
+
# :sort => "created_at",
|
8
8
|
# :order => "desc"
|
9
9
|
# })[:order].should == [:id.asc]
|
10
10
|
# end
|
@@ -91,25 +91,25 @@ describe "ExtJs" do
|
|
91
91
|
class TestMongo < ExtJs::Mongo; end
|
92
92
|
|
93
93
|
it "handles empty params with sensible defaults" do
|
94
|
-
TestMongo.new( {} ).options.should == {
|
94
|
+
TestMongo.new( {} ).options.should == { :limit => 50, :skip => 0 }
|
95
95
|
end
|
96
96
|
|
97
97
|
it "handles pagination" do
|
98
|
-
TestMongo.new( "start" => "50", "limit" => "10" ).options.should == {
|
99
|
-
TestMongo.new( "start" => "10" ).options.should == {
|
100
|
-
TestMongo.new( "limit" => "10" ).options.should == {
|
98
|
+
TestMongo.new( "start" => "50", "limit" => "10" ).options.should == { :limit => 10, :skip => 50 }
|
99
|
+
TestMongo.new( "start" => "10" ).options.should == { :limit => 50, :skip => 0 }
|
100
|
+
TestMongo.new( "limit" => "10" ).options.should == { :limit => 10, :skip => 0 }
|
101
101
|
end
|
102
102
|
|
103
103
|
it "handles sorting" do
|
104
|
-
TestMongo.new( "sort" => "foo" ).options.should == {
|
105
|
-
TestMongo.new( "sort" => "foo", "dir" => "desc" ).options.should == {
|
106
|
-
TestMongo.new( "sort" => "foo", "dir" => "no idea" ).options.should == {
|
107
|
-
TestMongo.new( "dir" => "asc" ).options.should == {
|
104
|
+
TestMongo.new( "sort" => "foo" ).options.should == { :limit => 50, :skip => 0, :sort => [:foo, :asc] }
|
105
|
+
TestMongo.new( "sort" => "foo", "dir" => "desc" ).options.should == { :limit => 50, :skip => 0, :sort => [:foo, :desc] }
|
106
|
+
TestMongo.new( "sort" => "foo", "dir" => "no idea" ).options.should == { :limit => 50, :skip => 0, :sort => [:foo, :asc] }
|
107
|
+
TestMongo.new( "dir" => "asc" ).options.should == { :limit => 50, :skip => 0 }
|
108
108
|
end
|
109
109
|
|
110
110
|
it "prevents dumb queries" do
|
111
|
-
TestMongo.new( "start" => "9999999", "limit" => "9999999" ).options.should == {
|
112
|
-
TestMongo.new( "start" => "-200", "limit" => "-200" ).options.should == {
|
111
|
+
TestMongo.new( "start" => "9999999", "limit" => "9999999" ).options.should == { :limit => 500, :skip => 9999999 }
|
112
|
+
TestMongo.new( "start" => "-200", "limit" => "-200" ).options.should == { :limit => 50, :skip => 0 }
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ext-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyson Tate
|