datapathy 0.6.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/.document +5 -0
- data/.gitignore +7 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.mkd +19 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/benchmarks/attributes.rb +67 -0
- data/benchmarks/initialize.rb +106 -0
- data/benchmarks/query.rb +34 -0
- data/datapathy.gemspec +31 -0
- data/lib/datapathy.rb +37 -0
- data/lib/datapathy/adapters/http_adapter.rb +121 -0
- data/lib/datapathy/collection.rb +123 -0
- data/lib/datapathy/config.rb +0 -0
- data/lib/datapathy/log_subscriber.rb +28 -0
- data/lib/datapathy/model.rb +142 -0
- data/lib/datapathy/model/crud.rb +61 -0
- data/lib/datapathy/model/dynamic_finders.rb +89 -0
- data/lib/datapathy/models/service.rb +6 -0
- data/lib/datapathy/query.rb +141 -0
- data/lib/datapathy/railtie.rb +48 -0
- data/profile/initialize.calltree +62 -0
- data/profile/initialize.rb +28 -0
- data/spec/adapter_api_spec.rb +146 -0
- data/spec/create_spec.rb +71 -0
- data/spec/crud_spec.rb +130 -0
- data/spec/datapathy_spec.rb +20 -0
- data/spec/delete_spec.rb +52 -0
- data/spec/find_by_spec.rb +24 -0
- data/spec/find_or_create_spec.rb +38 -0
- data/spec/integration/service_spec.rb +22 -0
- data/spec/query_spec.rb +89 -0
- data/spec/read_spec.rb +67 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/datapathy_test_app.rb +33 -0
- data/spec/support/matchers.rb +30 -0
- data/spec/support/models.rb +25 -0
- data/spec/update_spec.rb +55 -0
- data/spec/validations_spec.rb +31 -0
- metadata +235 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
require 'datapathy'
|
6
|
+
|
7
|
+
require 'pp'
|
8
|
+
require 'artifice'
|
9
|
+
|
10
|
+
# Requires supporting files with custom matchers and macros, etc,
|
11
|
+
# in ./support/ and its subdirectories.
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
13
|
+
|
14
|
+
module Helpers
|
15
|
+
require 'uuidtools'
|
16
|
+
def new_uuid
|
17
|
+
UUIDTools::UUID.random_create.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_adapter
|
21
|
+
Datapathy.default_adapter
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
|
27
|
+
config.include(Helpers)
|
28
|
+
config.include(Matchers)
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'yajl'
|
3
|
+
|
4
|
+
class DatapathyTestApp < Sinatra::Base
|
5
|
+
|
6
|
+
get '/' do
|
7
|
+
redirect '/services'
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/services' do
|
11
|
+
headers "Content-Type" => "application/json"
|
12
|
+
json({
|
13
|
+
:type => 'Service',
|
14
|
+
:href => '/services',
|
15
|
+
:items => [
|
16
|
+
{ :name => "Services", :href => '/services' },
|
17
|
+
{ :name => "Posts", :href => '/posts' }
|
18
|
+
]
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
|
25
|
+
def json(obj)
|
26
|
+
Yajl::Encoder.encode(obj, :pretty => true)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# start the server if ruby file executed directly
|
31
|
+
run! if __FILE__ == $0
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class HaveErrorsMatcher
|
5
|
+
|
6
|
+
def initialize(attribute)
|
7
|
+
@attribute = attribute
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(resource)
|
11
|
+
@resource = resource
|
12
|
+
!@resource.errors[@attribute].empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message_for_should
|
16
|
+
"Expected resource to have errors on #{@attribute}. Errors: #{@resource.errors.inspect}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure_message_for_should_not
|
20
|
+
"Expected resource to not have errors on #{@attribute}. Errors: #{@resource.errors.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def have_errors_on(attribute)
|
26
|
+
HaveErrorsMatcher.new(attribute)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
class Article
|
3
|
+
include Datapathy::Model
|
4
|
+
|
5
|
+
persists :id, :title, :text, :published_at
|
6
|
+
|
7
|
+
def summary
|
8
|
+
text[0,30]
|
9
|
+
end
|
10
|
+
|
11
|
+
# used to test querying on a method
|
12
|
+
def has_title?(title)
|
13
|
+
self.title == title
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class Person
|
19
|
+
include Datapathy::Model
|
20
|
+
|
21
|
+
persists :id, :name
|
22
|
+
|
23
|
+
validates_presence_of :name
|
24
|
+
|
25
|
+
end
|
data/spec/update_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'updating models' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@record_a = @record = {:id => new_uuid, :title => "Datapathy is amazing!", :text => "It really is!"}
|
7
|
+
@record_b = {:id => new_uuid, :title => "Datapathy is awesome!", :text => "Try it today!"}
|
8
|
+
@record_c = {:id => new_uuid, :title => "Datapathy is awesome!", :text => "Title is same, but text is different"}
|
9
|
+
|
10
|
+
@records = [@record_a, @record_b, @record_c]
|
11
|
+
@records.each do |record|
|
12
|
+
test_adapter.datastore[Article][record[:id]] = record
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
test_adapter.clear!
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'one at a time' do
|
21
|
+
before do
|
22
|
+
@article = Article[@record[:id]]
|
23
|
+
@article.title = "Datapathy is /still/ amazing!"
|
24
|
+
@article.save
|
25
|
+
|
26
|
+
@updated_article = Article[@record[:id]]
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should update the attributes' do
|
30
|
+
@updated_article.title.should eql(@article.title)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should not update other attributes' do
|
34
|
+
@updated_article.id.should eql(@record[:id])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'bulk' do
|
39
|
+
|
40
|
+
it 'should update based on a query' do
|
41
|
+
articles = Article.update(:text => "Updated Text") { |a|
|
42
|
+
a.title == @record_b[:title]
|
43
|
+
}
|
44
|
+
|
45
|
+
articles.each do |article|
|
46
|
+
updated_article = Article[article.id]
|
47
|
+
updated_article.text.should eql("Updated Text")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "validations" do
|
4
|
+
|
5
|
+
describe "enforced by the model" do
|
6
|
+
before do
|
7
|
+
@person = Person.new(:id => new_uuid)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be invalid' do
|
11
|
+
@person.name.should == nil
|
12
|
+
@person.valid?.should be_false
|
13
|
+
@person.should have_errors_on(:name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "enforced by the adapter" do
|
18
|
+
before do
|
19
|
+
@id = new_uuid
|
20
|
+
@person = Person.create(:id => @id, :name => "Paul")
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be invalid' do
|
24
|
+
person2 = Person.create(:id => @id, :name => "Rando")
|
25
|
+
person2.valid?.should be_false
|
26
|
+
person2.should have_errors_on(:id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
metadata
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datapathy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Paul Sadauskas
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-01 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
version: 3.1.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activemodel
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
version: 3.1.0
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: resourceful
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :runtime
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: yajl-ruby
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :runtime
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: uuidtools
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
type: :development
|
93
|
+
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
type: :development
|
107
|
+
version_requirements: *id006
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: artifice
|
110
|
+
prerelease: false
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
type: :development
|
121
|
+
version_requirements: *id007
|
122
|
+
- !ruby/object:Gem::Dependency
|
123
|
+
name: sinatra
|
124
|
+
prerelease: false
|
125
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
type: :development
|
135
|
+
version_requirements: *id008
|
136
|
+
description:
|
137
|
+
email: psadauskas@gmail.com
|
138
|
+
executables: []
|
139
|
+
|
140
|
+
extensions: []
|
141
|
+
|
142
|
+
extra_rdoc_files: []
|
143
|
+
|
144
|
+
files:
|
145
|
+
- .document
|
146
|
+
- .gitignore
|
147
|
+
- .rspec
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE
|
150
|
+
- README.mkd
|
151
|
+
- Rakefile
|
152
|
+
- VERSION
|
153
|
+
- benchmarks/attributes.rb
|
154
|
+
- benchmarks/initialize.rb
|
155
|
+
- benchmarks/query.rb
|
156
|
+
- datapathy.gemspec
|
157
|
+
- lib/datapathy.rb
|
158
|
+
- lib/datapathy/adapters/http_adapter.rb
|
159
|
+
- lib/datapathy/collection.rb
|
160
|
+
- lib/datapathy/config.rb
|
161
|
+
- lib/datapathy/log_subscriber.rb
|
162
|
+
- lib/datapathy/model.rb
|
163
|
+
- lib/datapathy/model/crud.rb
|
164
|
+
- lib/datapathy/model/dynamic_finders.rb
|
165
|
+
- lib/datapathy/models/service.rb
|
166
|
+
- lib/datapathy/query.rb
|
167
|
+
- lib/datapathy/railtie.rb
|
168
|
+
- profile/initialize.calltree
|
169
|
+
- profile/initialize.rb
|
170
|
+
- spec/adapter_api_spec.rb
|
171
|
+
- spec/create_spec.rb
|
172
|
+
- spec/crud_spec.rb
|
173
|
+
- spec/datapathy_spec.rb
|
174
|
+
- spec/delete_spec.rb
|
175
|
+
- spec/find_by_spec.rb
|
176
|
+
- spec/find_or_create_spec.rb
|
177
|
+
- spec/integration/service_spec.rb
|
178
|
+
- spec/query_spec.rb
|
179
|
+
- spec/read_spec.rb
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
- spec/support/datapathy_test_app.rb
|
182
|
+
- spec/support/matchers.rb
|
183
|
+
- spec/support/models.rb
|
184
|
+
- spec/update_spec.rb
|
185
|
+
- spec/validations_spec.rb
|
186
|
+
homepage: http://github.com/paul/datapathy
|
187
|
+
licenses: []
|
188
|
+
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
none: false
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
hash: 3
|
200
|
+
segments:
|
201
|
+
- 0
|
202
|
+
version: "0"
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
none: false
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
hash: 3
|
209
|
+
segments:
|
210
|
+
- 0
|
211
|
+
version: "0"
|
212
|
+
requirements: []
|
213
|
+
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 1.8.10
|
216
|
+
signing_key:
|
217
|
+
specification_version: 3
|
218
|
+
summary: The stupid-simple ORM for HTTP web services
|
219
|
+
test_files:
|
220
|
+
- spec/adapter_api_spec.rb
|
221
|
+
- spec/create_spec.rb
|
222
|
+
- spec/crud_spec.rb
|
223
|
+
- spec/datapathy_spec.rb
|
224
|
+
- spec/delete_spec.rb
|
225
|
+
- spec/find_by_spec.rb
|
226
|
+
- spec/find_or_create_spec.rb
|
227
|
+
- spec/integration/service_spec.rb
|
228
|
+
- spec/query_spec.rb
|
229
|
+
- spec/read_spec.rb
|
230
|
+
- spec/spec_helper.rb
|
231
|
+
- spec/support/datapathy_test_app.rb
|
232
|
+
- spec/support/matchers.rb
|
233
|
+
- spec/support/models.rb
|
234
|
+
- spec/update_spec.rb
|
235
|
+
- spec/validations_spec.rb
|