dm-persevere-adapter 0.31.0 → 0.32.0
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/VERSION +1 -1
- data/lib/persevere_adapter.rb +5 -12
- data/spec/persevere_adapter_spec.rb +8 -8
- metadata +1 -9
- data/spec/unit/create_spec.rb +0 -35
- data/spec/unit/delete_spec.rb +0 -23
- data/spec/unit/read_spec.rb +0 -102
- data/spec/unit/update_spec.rb +0 -37
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.32.0
|
data/lib/persevere_adapter.rb
CHANGED
@@ -59,7 +59,6 @@ module DataMapper
|
|
59
59
|
if values.is_a?(Array)
|
60
60
|
values.map! { |v| property.typecast(v) }
|
61
61
|
return values.sort[0].new_offset(Rational(Time.now.getlocal.gmt_offset/3600, 24)) if property.type == DateTime
|
62
|
-
return values.sort[0] + Time.now.gmt_offset if property.type == Time
|
63
62
|
return values.sort[0]
|
64
63
|
end
|
65
64
|
property.typecast(value)
|
@@ -70,7 +69,6 @@ module DataMapper
|
|
70
69
|
if values.is_a?(Array)
|
71
70
|
values.map! { |v| property.typecast(v) }
|
72
71
|
return values.sort[-1].new_offset(Rational(Time.now.getlocal.gmt_offset/3600, 24)) if property.type == DateTime
|
73
|
-
return values.sort[-1] + Time.now.gmt_offset if property.type == Time
|
74
72
|
return values.sort[-1]
|
75
73
|
end
|
76
74
|
property.typecast(value)
|
@@ -238,15 +236,7 @@ module DataMapper
|
|
238
236
|
created = 0
|
239
237
|
resources.each do |resource|
|
240
238
|
serial = resource.model.serial(self.name)
|
241
|
-
|
242
|
-
#
|
243
|
-
# This isn't the best solution but for an adapter, it'd be nice
|
244
|
-
# to support objects being in *tables* instead of in one big icky
|
245
|
-
# sort of table.
|
246
|
-
#
|
247
|
-
tblname = resource.model.storage_name
|
248
|
-
|
249
|
-
path = "/#{tblname}/"
|
239
|
+
path = "/#{resource.model.storage_name}/"
|
250
240
|
payload = make_json_compatible_hash(resource)
|
251
241
|
|
252
242
|
payload.delete(:id)
|
@@ -597,7 +587,10 @@ module DataMapper
|
|
597
587
|
json_rsrc[property.field] = case value
|
598
588
|
when DateTime then value.new_offset(0).strftime("%Y-%m-%dT%H:%M:%SZ")
|
599
589
|
when Date then value.to_s
|
600
|
-
when Time then value.
|
590
|
+
when Time then value.strftime("%H:%M:%S")
|
591
|
+
when Float then value.to_f
|
592
|
+
when BigDecimal then value.to_f
|
593
|
+
when Integer then value.to_i
|
601
594
|
else value
|
602
595
|
end
|
603
596
|
end
|
@@ -16,17 +16,17 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
16
16
|
|
17
17
|
class ::Bozon
|
18
18
|
include DataMapper::Resource
|
19
|
-
|
19
|
+
|
20
20
|
# Persevere only does id's as strings.
|
21
21
|
property :id, String, :serial => true
|
22
22
|
property :author, String
|
23
23
|
property :created_at, DateTime
|
24
24
|
property :title, String
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
class ::Dataino
|
28
28
|
include DataMapper::Resource
|
29
|
-
|
29
|
+
|
30
30
|
# Persevere only does id's as strings.
|
31
31
|
property :id, String, :serial => true
|
32
32
|
property :author, String
|
@@ -49,7 +49,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
49
49
|
'data' => { 'type' => 'string'}
|
50
50
|
}
|
51
51
|
}
|
52
|
-
|
52
|
+
|
53
53
|
@test_schema_hash_alt = {
|
54
54
|
'id' => 'test1/Vanilla',
|
55
55
|
'properties' => {
|
@@ -65,7 +65,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
65
65
|
'newdata' => { 'type' => 'any'}
|
66
66
|
}
|
67
67
|
}
|
68
|
-
|
68
|
+
|
69
69
|
@test_schema_hash_alt_mod = {
|
70
70
|
'id' => 'test1/Vanilla',
|
71
71
|
'properties' => {
|
@@ -183,18 +183,18 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
183
183
|
Bozon.auto_migrate!
|
184
184
|
(0..99).each{|i| Bozon.create!(:author => i, :title => i)}
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
it "should limit" do
|
188
188
|
result = Bozon.all(:limit => 2)
|
189
189
|
result.length.should == 2
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
it "should return data from an offset" do
|
193
193
|
result = Bozon.all(:limit => 5, :offset => 10)
|
194
194
|
result.length.should == 5
|
195
195
|
result.map { |item| item.id }.should == ["11", "12", "13", "14", "15"]
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
after(:all) do
|
199
199
|
Bozon.auto_migrate_down!
|
200
200
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-persevere-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan R. Judson
|
@@ -62,10 +62,6 @@ files:
|
|
62
62
|
- spec/persevere_spec.rb
|
63
63
|
- spec/spec.opts
|
64
64
|
- spec/spec_helper.rb
|
65
|
-
- spec/unit/create_spec.rb
|
66
|
-
- spec/unit/delete_spec.rb
|
67
|
-
- spec/unit/read_spec.rb
|
68
|
-
- spec/unit/update_spec.rb
|
69
65
|
- tasks/spec.rb
|
70
66
|
has_rdoc: true
|
71
67
|
homepage: http://github.com/yogo/dm-persevere-adapter
|
@@ -100,7 +96,3 @@ test_files:
|
|
100
96
|
- spec/persevere_adapter_spec.rb
|
101
97
|
- spec/persevere_spec.rb
|
102
98
|
- spec/spec_helper.rb
|
103
|
-
- spec/unit/create_spec.rb
|
104
|
-
- spec/unit/delete_spec.rb
|
105
|
-
- spec/unit/read_spec.rb
|
106
|
-
- spec/unit/update_spec.rb
|
data/spec/unit/create_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
#
|
6
|
-
# I need to make the Book class for Books to relate to
|
7
|
-
#
|
8
|
-
class Book
|
9
|
-
include DataMapper::Resource
|
10
|
-
|
11
|
-
# Persevere only does id's as strings.
|
12
|
-
property :id, String, :serial => true
|
13
|
-
property :author, String
|
14
|
-
property :created_at, DateTime
|
15
|
-
property :title, String
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'A Persevere adapter' do
|
19
|
-
|
20
|
-
before do
|
21
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'when saving a resource' do
|
25
|
-
|
26
|
-
before do
|
27
|
-
@book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should call the adapter create method' do
|
31
|
-
#@adapter.should_receive(:create).with([@book])
|
32
|
-
@book.save
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/spec/unit/delete_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# $LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
#
|
3
|
-
# require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
#
|
5
|
-
# describe 'A Persevere adapter' do
|
6
|
-
#
|
7
|
-
# before do
|
8
|
-
# @adapter = DataMapper::Repository.adapters[:default]
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# describe 'when deleting an existing resource' do
|
12
|
-
# before do
|
13
|
-
# @book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
14
|
-
# @book.stub!(:new_record?).and_return(false)
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# it 'should do an HTTP DELETE' do
|
18
|
-
# @adapter.should_receive(:delete)
|
19
|
-
# @book.destroy
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# end
|
23
|
-
# end
|
data/spec/unit/read_spec.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe 'A Persevere adapter' do
|
6
|
-
|
7
|
-
before do
|
8
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
9
|
-
end
|
10
|
-
|
11
|
-
# describe 'when getting one resource' do
|
12
|
-
#
|
13
|
-
# describe 'if the resource exists' do
|
14
|
-
#
|
15
|
-
# before do
|
16
|
-
# book_xml = <<-BOOK
|
17
|
-
# <?xml version='1.0' encoding='UTF-8'?>
|
18
|
-
# <book>
|
19
|
-
# <author>Stephen King</author>
|
20
|
-
# <created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
21
|
-
# <id type='integer'>1</id>
|
22
|
-
# <title>The Shining</title>
|
23
|
-
# <updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
24
|
-
# </book>
|
25
|
-
# BOOK
|
26
|
-
# @id = 1
|
27
|
-
# @response = mock(Net::HTTPResponse)
|
28
|
-
# @response.stub!(:body).and_return(book_xml)
|
29
|
-
# @adapter.stub!(:http_get).and_return(@response)
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# it 'should return the resource' do
|
33
|
-
# book = Book.get(@id)
|
34
|
-
# book.should_not be_nil
|
35
|
-
# book.id.should be_an_instance_of(Fixnum)
|
36
|
-
# book.id.should == 1
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# it 'should do an HTTP GET' do
|
40
|
-
# @adapter.should_receive(:http_get).with('/books/1.xml').and_return(@response)
|
41
|
-
# Book.get(@id)
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# it "it be equal to itself" do
|
45
|
-
# Book.get(@id).should == Book.get(@id)
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# describe 'if the resource does not exist' do
|
51
|
-
# it 'should return nil' do
|
52
|
-
# @id = 1
|
53
|
-
# @response = mock(Net::HTTPNotFound)
|
54
|
-
# @response.stub!(:content_type).and_return('text/html')
|
55
|
-
# @response.stub!(:body).and_return('<html></html>')
|
56
|
-
# @adapter.stub!(:http_get).and_return(@response)
|
57
|
-
# id = 4200
|
58
|
-
# Book.get(id).should be_nil
|
59
|
-
# end
|
60
|
-
# end
|
61
|
-
# end
|
62
|
-
#
|
63
|
-
# describe 'when getting all resource of a particular type' do
|
64
|
-
# before do
|
65
|
-
# books_xml = <<-BOOK
|
66
|
-
# <?xml version='1.0' encoding='UTF-8'?>
|
67
|
-
# <books type='array'>
|
68
|
-
# <book>
|
69
|
-
# <author>Ursula K LeGuin</author>
|
70
|
-
# <created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
71
|
-
# <id type='integer'>1</id>
|
72
|
-
# <title>The Dispossed</title>
|
73
|
-
# <updated-at type='datetime'>2008-06-08T17:02:28Z</updated-at>
|
74
|
-
# </book>
|
75
|
-
# <book>
|
76
|
-
# <author>Stephen King</author>
|
77
|
-
# <created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
78
|
-
# <id type='integer'>2</id>
|
79
|
-
# <title>The Shining</title>
|
80
|
-
# <updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
81
|
-
# </book>
|
82
|
-
# </books>
|
83
|
-
# BOOK
|
84
|
-
# @response = mock(Net::HTTPResponse)
|
85
|
-
# @response.stub!(:body).and_return(books_xml)
|
86
|
-
# @adapter.stub!(:http_get).and_return(@response)
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# it 'should get a non-empty list' do
|
90
|
-
# Book.all.should_not be_empty
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# it 'should receive one Resource for each entity in the XML' do
|
94
|
-
# Book.all.size.should == 2
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# it 'should do an HTTP GET' do
|
98
|
-
# @adapter.should_receive(:http_get).and_return(@response)
|
99
|
-
# Book.first
|
100
|
-
# end
|
101
|
-
# end
|
102
|
-
end
|
data/spec/unit/update_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# $LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
#
|
3
|
-
# require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
#
|
5
|
-
# describe 'A Persevere adapter' do
|
6
|
-
#
|
7
|
-
# describe 'when updating an existing resource' do
|
8
|
-
# # before do
|
9
|
-
# # @books_xml = <<-XML
|
10
|
-
# # <book>
|
11
|
-
# # <id type='integer'>42</id>
|
12
|
-
# # <title>Starship Troopers</title>
|
13
|
-
# # <author>Robert Heinlein</author>
|
14
|
-
# # <created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
15
|
-
# # </book>
|
16
|
-
# # XML
|
17
|
-
# # repository do |repo|
|
18
|
-
# # @repository = repo
|
19
|
-
# # @book = Book.new(:id => 42,
|
20
|
-
# # :title => 'Starship Troopers',
|
21
|
-
# # :author => 'Robert Heinlein',
|
22
|
-
# # :created_at => DateTime.parse('2008-06-08T17:02:28Z'))
|
23
|
-
# # @book.instance_eval { @new_record = false }
|
24
|
-
# # @repository.identity_map(Book)[@book.key] = @book
|
25
|
-
# # @book.title = "Mary Had a Little Lamb"
|
26
|
-
# # end
|
27
|
-
# # end
|
28
|
-
# #
|
29
|
-
# # it 'should do an HTTP PUT' do
|
30
|
-
# # adapter = @repository.adapter #DataMapper::Repository.adapters[:default]
|
31
|
-
# # adapter.should_receive(:http_put).with('/books/42.xml', @book.to_xml)
|
32
|
-
# # @repository.scope do
|
33
|
-
# # @book.save
|
34
|
-
# # end
|
35
|
-
# # end
|
36
|
-
# end
|
37
|
-
# end
|