ixtlan-datamapper 0.1.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.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/MIT-LICENSE +20 -0
- data/README.md +94 -0
- data/Rakefile +29 -0
- data/ixtlan-datamapper.gemspec +32 -0
- data/lib/ixtlan-datamapper.rb +23 -0
- data/lib/ixtlan/datamapper/collection.rb +28 -0
- data/lib/ixtlan/datamapper/collection.rb~ +28 -0
- data/lib/ixtlan/datamapper/conditional_get.rb +46 -0
- data/lib/ixtlan/datamapper/conditional_get.rb~ +47 -0
- data/lib/ixtlan/datamapper/cuba_plugin.rb~ +74 -0
- data/lib/ixtlan/datamapper/immutable.rb +18 -0
- data/lib/ixtlan/datamapper/immutable.rb~ +83 -0
- data/lib/ixtlan/datamapper/modified.rb~ +83 -0
- data/lib/ixtlan/datamapper/modified_by.rb +39 -0
- data/lib/ixtlan/datamapper/modified_by.rb~ +39 -0
- data/lib/ixtlan/datamapper/optimistic.rb~ +53 -0
- data/lib/ixtlan/datamapper/optimistic_get.rb +71 -0
- data/lib/ixtlan/datamapper/optimistic_get.rb~ +72 -0
- data/lib/ixtlan/datamapper/stale_check.rb~ +49 -0
- data/lib/ixtlan/datamapper/stale_object_exception.rb +26 -0
- data/lib/ixtlan/datamapper/stale_object_exception.rb~ +26 -0
- data/lib/ixtlan/datamapper/use_utc.rb +4 -0
- data/lib/ixtlan/datamapper/use_utc.rb~ +5 -0
- data/lib/ixtlan/datamapper/validations_ext.rb +61 -0
- data/spec/collection_spec.rb +57 -0
- data/spec/collection_spec.rb~ +54 -0
- data/spec/conditional_get_spec.rb +69 -0
- data/spec/conditional_get_spec.rb~ +70 -0
- data/spec/datamapper_spec.rb~ +74 -0
- data/spec/immutable_spec.rb +33 -0
- data/spec/immutable_spec.rb~ +70 -0
- data/spec/modified_by_spec.rb +54 -0
- data/spec/modified_by_spec.rb~ +33 -0
- data/spec/optimistic_get_spec.rb +57 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/spec_helper.rb~ +12 -0
- metadata +199 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'ixtlan/datamapper/immutable'
|
4
|
+
|
5
|
+
class C
|
6
|
+
include DataMapper::Resource
|
7
|
+
include Ixtlan::DataMapper::Immutable
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
property :name, String
|
11
|
+
|
12
|
+
timestamps :at
|
13
|
+
end
|
14
|
+
|
15
|
+
DataMapper.finalize
|
16
|
+
DataMapper.auto_migrate!
|
17
|
+
|
18
|
+
describe Ixtlan::DataMapper::Immutable do
|
19
|
+
|
20
|
+
subject { C.create :name => 'huffalump' }
|
21
|
+
|
22
|
+
it 'is valid and persistent' do
|
23
|
+
subject.valid?.must_equal true
|
24
|
+
subject.persistence_state?.must_equal true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is valid and persistent' do
|
28
|
+
subject.name = 'noone'
|
29
|
+
subject.valid?.must_equal false
|
30
|
+
subject.save.must_equal false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'ixtlan/datamapper/use_utc'
|
4
|
+
require 'ixtlan/datamapper/conditional_get'
|
5
|
+
|
6
|
+
class B
|
7
|
+
include DataMapper::Resource
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
property :name, String
|
11
|
+
|
12
|
+
timestamps :at
|
13
|
+
end
|
14
|
+
|
15
|
+
DataMapper.finalize
|
16
|
+
DataMapper.auto_migrate!
|
17
|
+
|
18
|
+
describe Ixtlan::DataMapper::ConditionalGet do
|
19
|
+
|
20
|
+
subject { B.create :name => 'huffalump' }
|
21
|
+
|
22
|
+
describe "#conditional_get" do
|
23
|
+
|
24
|
+
it 'returns false if everything is up-to-date' do
|
25
|
+
B.conditional_get(subject.updated_at.to_s, subject.id).must_equal false
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns false if everything is up-to-date with DateTime parameter' do
|
29
|
+
B.conditional_get!(subject.updated_at, subject.id).must_equal false
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns object for given id when there is no modified date' do
|
33
|
+
B.conditional_get(nil, subject.id).must_equal subject
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns nil on stale modified date' do
|
37
|
+
B.conditional_get(subject.updated_at + 1, subject.id).must_equal subject
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns nil on non-existing id' do
|
41
|
+
B.conditional_get(subject.updated_at.to_s, subject.id + 987).must_be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#conditional_get!" do
|
47
|
+
|
48
|
+
it 'returns false if everything is up-to-date' do
|
49
|
+
B.conditional_get!(subject.updated_at.to_s, subject.id).must_equal false
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns false if everything is up-to-date with DateTime parameter' do
|
53
|
+
B.conditional_get!(subject.updated_at, subject.id).must_equal false
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'fails with not-found exception with non-existing id' do
|
57
|
+
lambda { B.conditional_get!(subject.updated_at.to_s, subject.id + 987) }.must_raise DataMapper::ObjectNotFoundError
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'retuens object with stale modified parameter' do
|
61
|
+
B.conditional_get!((subject.updated_at - 1000).to_s, subject.id).must_equal subject
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns object without modified parameter given' do
|
65
|
+
B.conditional_get!(nil, subject.id).must_equal subject
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'ixtlan/datamapper/modified_by'
|
4
|
+
|
5
|
+
class D
|
6
|
+
include DataMapper::Resource
|
7
|
+
|
8
|
+
property :id, Serial
|
9
|
+
property :name, String
|
10
|
+
|
11
|
+
modified_by D
|
12
|
+
end
|
13
|
+
|
14
|
+
DataMapper.finalize
|
15
|
+
DataMapper.auto_migrate!
|
16
|
+
|
17
|
+
describe Ixtlan::DataMapper::ModifiedBy do
|
18
|
+
|
19
|
+
subject do
|
20
|
+
unless d = D.get( 1 )
|
21
|
+
d = D.new :name => 'huffalump', :id => 1, :modified_by_id => 1
|
22
|
+
d.save!
|
23
|
+
end
|
24
|
+
d
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is valid per default' do
|
28
|
+
subject.current_user.must_be_nil
|
29
|
+
subject.persistence_state?.must_equal true
|
30
|
+
subject.dirty?.must_equal false
|
31
|
+
subject.valid?.must_equal true
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is not valid when dirty' do
|
35
|
+
subject.name = 'asd'
|
36
|
+
subject.current_user.must_be_nil
|
37
|
+
subject.dirty?.must_equal true
|
38
|
+
subject.valid?.must_equal false
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'is valid when dirty and current_user set' do
|
42
|
+
subject.name = 'asd'
|
43
|
+
subject.current_user = subject
|
44
|
+
subject.dirty?.must_equal true
|
45
|
+
subject.valid?.must_equal true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is valid after setting current user' do
|
49
|
+
subject.current_user = subject
|
50
|
+
subject.dirty?.must_equal false
|
51
|
+
subject.valid?.must_equal true
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'ixtlan/datamapper/immutable'
|
4
|
+
|
5
|
+
class C
|
6
|
+
include DataMapper::Resource
|
7
|
+
include Ixtlan::DataMapper::Immutable
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
property :name, String
|
11
|
+
|
12
|
+
timestamps :at
|
13
|
+
end
|
14
|
+
|
15
|
+
DataMapper.finalize
|
16
|
+
DataMapper.auto_migrate!
|
17
|
+
|
18
|
+
describe Ixtlan::DataMapper::Immutable do
|
19
|
+
|
20
|
+
subject { C.create :name => 'huffalump' }
|
21
|
+
|
22
|
+
it 'is valid and persistent' do
|
23
|
+
subject.valid?.must_equal true
|
24
|
+
subject.persistence_state?.must_equal true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is valid and persistent' do
|
28
|
+
subject.name = 'noone'
|
29
|
+
subject.valid?.must_equal false
|
30
|
+
subject.save.must_equal false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'ixtlan/datamapper/optimistic_get'
|
4
|
+
|
5
|
+
class A
|
6
|
+
include DataMapper::Resource
|
7
|
+
|
8
|
+
property :id, Serial
|
9
|
+
property :name, String
|
10
|
+
|
11
|
+
timestamps :at
|
12
|
+
end
|
13
|
+
|
14
|
+
DataMapper.finalize
|
15
|
+
DataMapper.auto_migrate!
|
16
|
+
|
17
|
+
describe Ixtlan::DataMapper::OptimisticGet do
|
18
|
+
|
19
|
+
subject { A.create :name => 'huffalump' }
|
20
|
+
|
21
|
+
describe "#optimistic_get" do
|
22
|
+
|
23
|
+
it 'should load' do
|
24
|
+
A.optimistic_get(subject.updated_at.to_s, subject.id).must_equal subject
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should fail with stale exception' do
|
28
|
+
lambda { A.optimistic_get((subject.updated_at - 1000).to_s, subject.id) }.must_raise Ixtlan::DataMapper::StaleObjectException
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should fail with nil' do
|
32
|
+
A.optimistic_get(subject.updated_at.to_s, subject.id + 987).must_be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#optimistic_get!" do
|
38
|
+
|
39
|
+
it 'should load' do
|
40
|
+
A.optimistic_get!(subject.updated_at.to_s, subject.id).must_equal subject
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should fail with not-found exception' do
|
44
|
+
lambda { A.optimistic_get!(subject.updated_at.to_s, subject.id + 987) }.must_raise DataMapper::ObjectNotFoundError
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should fail with stale exception' do
|
48
|
+
lambda { A.optimistic_get!((subject.updated_at - 1000).to_s, subject.id) }.must_raise Ixtlan::DataMapper::StaleObjectException
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should fail with stale exception updated being nil' do
|
52
|
+
lambda { A.optimistic_get!(nil, subject.id) }.must_raise Ixtlan::DataMapper::StaleObjectException
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# single spec setup
|
2
|
+
$LOAD_PATH.unshift File.expand_path( '../../lib', __FILE__ )
|
3
|
+
|
4
|
+
gem 'minitest'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
require 'dm-core'
|
8
|
+
require 'dm-timestamps'
|
9
|
+
require 'dm-validations'
|
10
|
+
require 'dm-migrations'
|
11
|
+
require 'dm-sqlite-adapter'
|
12
|
+
|
13
|
+
require 'ixtlan/datamapper/use_utc'
|
14
|
+
|
15
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# single spec setup
|
2
|
+
$LOAD_PATH.unshift File.expand_path( '../../lib', __FILE__ )
|
3
|
+
|
4
|
+
gem 'minitest'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
require 'dm-core'
|
8
|
+
require 'dm-timestamps'
|
9
|
+
require 'dm-migrations'
|
10
|
+
require 'dm-sqlite-adapter'
|
11
|
+
|
12
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ixtlan-datamapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mkristian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: virtus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dm-aggregates
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dm-timestamps
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dm-migrations
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dm-validations
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dm-sqlite-adapter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.3'
|
125
|
+
description: 'collection of utilities for datamapper: optimistic get, conditional
|
126
|
+
get, use-utc timestampt, tag model as immutable, etc'
|
127
|
+
email:
|
128
|
+
- m.kristian@web.de
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- MIT-LICENSE
|
134
|
+
- ixtlan-datamapper.gemspec
|
135
|
+
- README.md
|
136
|
+
- lib/ixtlan-datamapper.rb
|
137
|
+
- lib/ixtlan/datamapper/optimistic_get.rb
|
138
|
+
- lib/ixtlan/datamapper/collection.rb
|
139
|
+
- lib/ixtlan/datamapper/optimistic.rb~
|
140
|
+
- lib/ixtlan/datamapper/validations_ext.rb
|
141
|
+
- lib/ixtlan/datamapper/collection.rb~
|
142
|
+
- lib/ixtlan/datamapper/use_utc.rb~
|
143
|
+
- lib/ixtlan/datamapper/optimistic_get.rb~
|
144
|
+
- lib/ixtlan/datamapper/immutable.rb~
|
145
|
+
- lib/ixtlan/datamapper/modified_by.rb~
|
146
|
+
- lib/ixtlan/datamapper/stale_check.rb~
|
147
|
+
- lib/ixtlan/datamapper/modified.rb~
|
148
|
+
- lib/ixtlan/datamapper/use_utc.rb
|
149
|
+
- lib/ixtlan/datamapper/conditional_get.rb
|
150
|
+
- lib/ixtlan/datamapper/stale_object_exception.rb~
|
151
|
+
- lib/ixtlan/datamapper/immutable.rb
|
152
|
+
- lib/ixtlan/datamapper/conditional_get.rb~
|
153
|
+
- lib/ixtlan/datamapper/modified_by.rb
|
154
|
+
- lib/ixtlan/datamapper/stale_object_exception.rb
|
155
|
+
- lib/ixtlan/datamapper/cuba_plugin.rb~
|
156
|
+
- spec/conditional_get_spec.rb
|
157
|
+
- spec/immutable_spec.rb~
|
158
|
+
- spec/immutable_spec.rb
|
159
|
+
- spec/datamapper_spec.rb~
|
160
|
+
- spec/modified_by_spec.rb~
|
161
|
+
- spec/modified_by_spec.rb
|
162
|
+
- spec/spec_helper.rb~
|
163
|
+
- spec/collection_spec.rb
|
164
|
+
- spec/spec_helper.rb
|
165
|
+
- spec/optimistic_get_spec.rb
|
166
|
+
- spec/collection_spec.rb~
|
167
|
+
- spec/conditional_get_spec.rb~
|
168
|
+
- Rakefile
|
169
|
+
- Gemfile
|
170
|
+
homepage: http://github.com/mkristian/ixtlan-datamapper
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.0.14
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: collection of utilities for datamapper
|
194
|
+
test_files:
|
195
|
+
- spec/conditional_get_spec.rb
|
196
|
+
- spec/immutable_spec.rb
|
197
|
+
- spec/modified_by_spec.rb
|
198
|
+
- spec/collection_spec.rb
|
199
|
+
- spec/optimistic_get_spec.rb
|