Browse files

fix collection name in pagination result when it is a compound name

  • Loading branch information...
1 parent ae32975 commit 7a47b6af676abbf1940cdf4bcd8aed20ef0c0822 @wandenberg wandenberg committed Mar 20, 2013
Showing with 31 additions and 29 deletions.
  1. +15 −14 Gemfile.lock
  2. +1 −1 lib/mongoid/query_string_interface.rb
  3. +1 −1 lib/version.rb
  4. +14 −13 spec/mongoid/query_string_interface_spec.rb
View
29 Gemfile.lock
@@ -1,23 +1,23 @@
PATH
remote: .
specs:
- mongoid_query_string_interface (0.7.1)
+ mongoid_query_string_interface (0.7.2)
mongoid (>= 2.0.2)
query_string_interface (>= 0.5.0)
will_paginate (~> 3.0.pre2)
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.2.6)
- activesupport (= 3.2.6)
+ activemodel (3.2.12)
+ activesupport (= 3.2.12)
builder (~> 3.0.0)
- activesupport (3.2.6)
+ activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
bson (1.3.1)
bson_ext (1.3.1)
- builder (3.0.0)
+ builder (3.0.4)
columnize (0.3.4)
database_cleaner (0.6.7)
debugger (1.5.0)
@@ -27,16 +27,17 @@ GEM
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.0)
diff-lcs (1.1.2)
- i18n (0.6.0)
+ i18n (0.6.4)
linecache (0.46)
rbx-require-relative (> 0.0.4)
- mongo (1.3.1)
- bson (>= 1.3.1)
- mongoid (2.4.11)
- activemodel (~> 3.1)
- mongo (<= 1.6.2)
+ mongoid (3.1.2)
+ activemodel (~> 3.2)
+ moped (~> 1.4.2)
+ origin (~> 1.0)
tzinfo (~> 0.3.22)
- multi_json (1.3.6)
+ moped (1.4.3)
+ multi_json (1.7.0)
+ origin (1.0.11)
query_string_interface (0.5.0)
activesupport (>= 3.0.0)
rake (0.8.7)
@@ -57,8 +58,8 @@ GEM
simplecov (0.4.2)
simplecov-html (~> 0.4.4)
simplecov-html (0.4.5)
- tzinfo (0.3.33)
- will_paginate (3.0.3)
+ tzinfo (0.3.37)
+ will_paginate (3.0.4)
PLATFORMS
ruby
View
2 lib/mongoid/query_string_interface.rb
@@ -91,7 +91,7 @@ def build_results_with_pager_for(collection)
end
def collection_name_in_pagination_result
- model_name.human.underscore.pluralize.to_sym
+ model_name.human.underscore.pluralize.gsub(/\s/, "_").to_sym
end
end
end
View
2 lib/version.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
module Mongoid #:nodoc
module QueryStringInterface #:nodoc
- VERSION = "0.7.1"
+ VERSION = "0.7.2"
end
end
View
27 spec/mongoid/query_string_interface_spec.rb
@@ -34,11 +34,13 @@ def self.paginatable_collection_from(collection, total, params)
end
end
-class SimpleDocument
- include Mongoid::Document
- extend Mongoid::QueryStringInterface
+module MyTests
+ class SimpleDocument
+ include Mongoid::Document
+ extend Mongoid::QueryStringInterface
- field :title
+ field :title
+ end
end
class EmbeddedDocument
@@ -69,23 +71,23 @@ class EmbeddedDocument
describe "defaults" do
it "should return an empty hash as the default filtering options" do
- SimpleDocument.default_filtering_options.should == {}
+ MyTests::SimpleDocument.default_filtering_options.should == {}
end
it "should return an empty array as the default sorting options" do
- SimpleDocument.default_sorting_options.should == []
+ MyTests::SimpleDocument.default_sorting_options.should == []
end
it "should return hash with per_page => 12 and page => 1 for the default pagination options" do
- SimpleDocument.default_pagination_options.should == { :per_page => 12, :page => 1 }
+ MyTests::SimpleDocument.default_pagination_options.should == { :per_page => 12, :page => 1 }
end
it "should return an empty hash as the default sorting attributes to replace" do
- SimpleDocument.sorting_attributes_to_replace.should == {}
+ MyTests::SimpleDocument.sorting_attributes_to_replace.should == {}
end
it "should return an empty hash as the default filtering attributes to replace" do
- SimpleDocument.filtering_attributes_to_replace.should == {}
+ MyTests::SimpleDocument.filtering_attributes_to_replace.should == {}
end
end
@@ -124,8 +126,8 @@ class EmbeddedDocument
it "should return results using human model name" do
params = { 'title' => 'title' }
collection = mock(WillPaginate::Collection).as_null_object
- Document.stub(:filter_by).with(params).and_return(collection)
- Document.filter_with_pagination_by(params).should have_key(:documents)
+ MyTests::SimpleDocument.stub(:filter_by).with(params).and_return(collection)
+ MyTests::SimpleDocument.filter_with_pagination_by(params).should have_key(:simple_documents)
end
end
@@ -524,11 +526,10 @@ def self.paginate(options)
end
it "should return the results, using the model name as the key, as a paginatable collection" do
- key = Document.model_name.human.underscore.pluralize.to_sym
paginatable_collection = WillPaginate::Collection.create page, per_page, total do |pager|
pager.replace(collection)
end
- Document.paginatable_collection_from(collection, total, options)[key].should == paginatable_collection
+ Document.paginatable_collection_from(collection, total, options)[:documents].should == paginatable_collection
end
end
end

0 comments on commit 7a47b6a

Please sign in to comment.