Permalink
Browse files

Merge pull request #47 from mattvv/master

Add Ordering & Simplify Testing for Local Environments
  • Loading branch information...
2 parents 3a357a6 + ed1faad commit 0332bed672c421e7da48cbd8973ff200e2021612 @adelevie committed Oct 29, 2012
@@ -24,11 +24,13 @@ def include_object(parent)
end
# deprecating until it works
- #def order(attribute)
- # attribute = attribute.to_sym if attribute.is_a?(String)
- # criteria[:order] = attribute
- # self
- #end
+ def order(attr)
+ orders = attr.split(" ")
+ if orders.count > 1
+ criteria[:order] = orders[1] == "desc" ? "-#{orders[0]}" : "#{orders[0]}"
+ end
+ self
+ end
def skip(skip)
criteria[:skip] = skip
@@ -44,9 +44,9 @@ def skip(n)
Query.new(self).skip(n)
end
- #def self.order(attribute)
- # Query.new(self).order(attribute)
- #end
+ def order(attr)
+ Query.new(self).order(attr)
+ end
end
def self.included(base)
@@ -1,8 +1,6 @@
require 'helper'
require 'parse_resource'
-#path = "parse_resource.yml"
-#settings = YAML.load(ERB.new(File.new(path).read).result)['test']
ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
class Bowl < ParseResource
View
@@ -11,6 +11,13 @@
require 'vcr'
require 'webmock/test_unit'
+if ENV["PARSE_RESOURCE_APPLICATION_ID"].nil? && ENV["PARSE_RESOURCE_MASTER_KEY"].nil?
+ path = "parse_resource.yml"
+ settings = YAML.load(ERB.new(File.new(path).read).result)['test']
+ ENV["PARSE_RESOURCE_APPLICATION_ID"] = settings['app_id']
+ ENV["PARSE_RESOURCE_MASTER_KEY"] = settings['master_key']
+end
+
VCR.configure do |c|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.hook_into :webmock # or :fakeweb
@@ -22,8 +29,5 @@
$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib/' )
require 'parse_resource'
-
-
-
class Test::Unit::TestCase
end
@@ -1,10 +1,6 @@
require 'helper'
require 'parse_resource'
-#path = "parse_resource.yml"
-#settings = YAML.load(ERB.new(File.new(path).read).result)['test']
-#ParseResource::Base.load!(settings['app_id'], settings['master_key'])
-
ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
class Post < ParseResource::Base
@@ -165,6 +161,30 @@ def test_limit
end
end
+ def test_order_descending
+ e1 = Event.create(:name => "1st")
+ e2 = Event.create(:name => "2nd")
+ events = Event.order("name desc").all
+ Event.destroy_all
+ assert_equal true, (events[0].name == "2nd")
+ end
+
+ def test_order_ascending
+ e1 = Event.create(:name => "1st")
+ e2 = Event.create(:name => "2nd")
+ events = Event.order("name asc").all
+ Event.destroy_all
+ assert_equal true, (events[0].name == "1st")
+ end
+
+ def test_order_no_field
+ e1 = Event.create(:name => "1st")
+ e2 = Event.create(:name => "2nd")
+ events = Event.order("desc").all
+ Event.destroy_all
+ assert_equal true, (events[0].name == "1st")
+ end
+
#def test_skip
# 15.times do |i|
# Post.create(:title => "skip", :author => i)
View
@@ -1,10 +1,6 @@
require 'helper'
require 'parse_resource'
-#path = "parse_resource.yml"
-#settings = YAML.load(ERB.new(File.new(path).read).result)['test']
-#ParseResource::Base.load!(settings['app_id'], settings['master_key'])
-
ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
View
@@ -1,9 +1,6 @@
require 'helper'
require 'parse_resource'
-#path = "parse_resource.yml"
-#settings = YAML.load(ERB.new(File.new(path).read).result)['test']
-#ParseResource::Base.load!(settings['app_id'], settings['master_key'])
ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
@@ -20,16 +17,6 @@ class TestQueryOptions < Test::Unit::TestCase
#def teardown
# Event.destroy_all
#end
-
- #def test_order
- # e1 = Event.create(:name => "1st")
- # e2 = Event.create(:name => "2nd")
- # events = Event.order("created_at").all
- # puts events[0].created_at
- # puts events[1].created_at
- # assert_equal true, (events[0].created_at < events[1].created_at)
- # Event.destroy_all
- #end
def test_skip
VCR.use_cassette('test_skip', :record => :new_episodes) do
@@ -44,7 +31,6 @@ def test_skip
all_events += results
count += results.count
end while not results.empty?
-
assert_equal true, (all_events.count == num_to_test)
found_names = []

0 comments on commit 0332bed

Please sign in to comment.