couch_potato 0.2.25 → 0.2.26
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/CHANGES.md +3 -0
- data/VERSION.yml +3 -3
- data/lib/core_ext/date.rb +12 -1
- data/lib/core_ext/time.rb +11 -1
- data/spec/property_spec.rb +3 -2
- data/spec/unit/date_spec.rb +22 -0
- data/spec/unit/time_spec.rb +22 -0
- metadata +5 -1
data/CHANGES.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
## Changes
|
2
2
|
|
3
|
+
### master
|
4
|
+
* added to_s(:json) to Date and Time to be able to get properly formatted dates/times for searching with dates/times (langalex)
|
5
|
+
|
3
6
|
### 0.2.25
|
4
7
|
* automatic view updates: when you change the definition of a view couch potato will now update the design document in the database (langalex)
|
5
8
|
* support for properties of type Date, better support for Time (langalex)
|
data/VERSION.yml
CHANGED
data/lib/core_ext/date.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
class Date
|
2
2
|
def to_json(*a)
|
3
|
-
%("#{
|
3
|
+
%("#{to_s(:json)}")
|
4
4
|
end
|
5
5
|
|
6
|
+
def to_s_with_json(*args)
|
7
|
+
if args[0] == :json
|
8
|
+
strftime("%Y/%m/%d")
|
9
|
+
else
|
10
|
+
to_s_without_json *args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
alias_method :to_s_without_json, :to_s
|
14
|
+
alias_method :to_s, :to_s_with_json
|
15
|
+
|
16
|
+
|
6
17
|
def self.json_create string
|
7
18
|
return nil if string.nil?
|
8
19
|
Date.parse(string)
|
data/lib/core_ext/time.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
class Time
|
2
2
|
def to_json(*a)
|
3
|
-
%("#{
|
3
|
+
%("#{to_s(:json)}")
|
4
4
|
end
|
5
5
|
|
6
|
+
def to_s_with_json(*args)
|
7
|
+
if args[0] == :json
|
8
|
+
getutc.strftime("%Y/%m/%d %H:%M:%S +0000")
|
9
|
+
else
|
10
|
+
to_s_without_json *args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
alias_method :to_s_without_json, :to_s
|
14
|
+
alias_method :to_s, :to_s_with_json
|
15
|
+
|
6
16
|
def self.json_create string
|
7
17
|
return nil if string.nil?
|
8
18
|
d = DateTime.parse(string).new_offset
|
data/spec/property_spec.rb
CHANGED
@@ -145,11 +145,12 @@ describe 'properties' do
|
|
145
145
|
w.time.to_s.should == time.utc.to_s
|
146
146
|
end
|
147
147
|
|
148
|
-
it "should parse a string and persist it as time" do
|
149
|
-
w = Watch.new :time => '2009-01-01 13:25
|
148
|
+
it "should parse a string and persist it as utc time" do
|
149
|
+
w = Watch.new :time => '2009-01-01 13:25 +0100'
|
150
150
|
CouchPotato.database.save_document! w
|
151
151
|
w = CouchPotato.database.load_document w.id
|
152
152
|
w.time.should be_a(Time)
|
153
|
+
w.time.should == Time.parse('2009-01-01 12:25 +0000')
|
153
154
|
end
|
154
155
|
|
155
156
|
it "should store nil" do
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Date, 'to_json' do
|
4
|
+
it "should format the date in a way that i can use it for sorting in couchdb" do
|
5
|
+
date = Date.parse('2009-01-01')
|
6
|
+
date.to_json.should == "\"2009/01/01\""
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Date, 'to_s(:json)' do
|
11
|
+
it "should format it in the same way as to_json does so i can use this to do queries over date attributes" do
|
12
|
+
date = Date.parse('2009-01-01')
|
13
|
+
date.to_s(:json).should == "2009/01/01"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Date, 'to_s' do
|
18
|
+
it "should leave the original to_s untouched" do
|
19
|
+
date = Date.parse('2009-01-01')
|
20
|
+
date.to_s.should == "2009-01-01"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Time, 'to_json' do
|
4
|
+
it "should convert to utc and format the time in a way that i can use it for sorting in couchdb" do
|
5
|
+
time = Time.parse('2009-01-01 11:12:23 +0200')
|
6
|
+
time.to_json.should == "\"2009/01/01 09:12:23 +0000\""
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Time, 'to_s(:json)' do
|
11
|
+
it "should format it in the same way as to_json does so i can use this to do queries over time attributes" do
|
12
|
+
time = Time.parse('2009-01-01 11:12:23 +0200')
|
13
|
+
time.to_s(:json).should == "2009/01/01 09:12:23 +0000"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Time, 'to_s' do
|
18
|
+
it "should leave the original to_s untouched" do
|
19
|
+
time = Time.parse('2009-01-01 10:12:23 +0100').getutc
|
20
|
+
time.to_s.should include("09:12:23")
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -111,11 +111,13 @@ files:
|
|
111
111
|
- spec/unit/create_spec.rb
|
112
112
|
- spec/unit/customs_views_spec.rb
|
113
113
|
- spec/unit/database_spec.rb
|
114
|
+
- spec/unit/date_spec.rb
|
114
115
|
- spec/unit/dirty_attributes_spec.rb
|
115
116
|
- spec/unit/json_create_id_spec.rb
|
116
117
|
- spec/unit/model_view_spec_spec.rb
|
117
118
|
- spec/unit/rspec_matchers_spec.rb
|
118
119
|
- spec/unit/string_spec.rb
|
120
|
+
- spec/unit/time_spec.rb
|
119
121
|
- spec/unit/validation_spec.rb
|
120
122
|
- spec/unit/view_query_spec.rb
|
121
123
|
- spec/update_spec.rb
|
@@ -168,11 +170,13 @@ test_files:
|
|
168
170
|
- spec/unit/create_spec.rb
|
169
171
|
- spec/unit/customs_views_spec.rb
|
170
172
|
- spec/unit/database_spec.rb
|
173
|
+
- spec/unit/date_spec.rb
|
171
174
|
- spec/unit/dirty_attributes_spec.rb
|
172
175
|
- spec/unit/json_create_id_spec.rb
|
173
176
|
- spec/unit/model_view_spec_spec.rb
|
174
177
|
- spec/unit/rspec_matchers_spec.rb
|
175
178
|
- spec/unit/string_spec.rb
|
179
|
+
- spec/unit/time_spec.rb
|
176
180
|
- spec/unit/validation_spec.rb
|
177
181
|
- spec/unit/view_query_spec.rb
|
178
182
|
- spec/update_spec.rb
|