simple_record 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +27 -1
- data/lib/simple_record.rb +165 -91
- data/lib/simple_record/active_sdb.rb +1 -1
- data/lib/simple_record/attributes.rb +3 -3
- data/lib/simple_record/callbacks.rb +45 -17
- data/lib/simple_record/sharding.rb +238 -238
- data/lib/simple_record/translations.rb +223 -223
- data/lib/simple_record/validations.rb +69 -0
- data/test/my_model.rb +71 -35
- data/test/my_sharded_model.rb +25 -20
- data/test/my_simple_model.rb +13 -0
- data/test/test_shards.rb +122 -119
- data/test/test_simple_record.rb +5 -22
- data/test/test_validations.rb +45 -0
- metadata +42 -53
- data/lib/simple_record/rails2.rb +0 -30
data/test/test_simple_record.rb
CHANGED
@@ -7,6 +7,7 @@ require 'aws'
|
|
7
7
|
require_relative 'my_model'
|
8
8
|
require_relative 'my_child_model'
|
9
9
|
require_relative 'model_with_enc'
|
10
|
+
require_relative 'my_simple_model'
|
10
11
|
|
11
12
|
# Tests for SimpleRecord
|
12
13
|
#
|
@@ -50,7 +51,7 @@ class TestSimpleRecord < TestBase
|
|
50
51
|
sleep 1
|
51
52
|
mm2 = MyModel.find(id)
|
52
53
|
puts mm2.inspect
|
53
|
-
assert mm2.age.nil?, "doh, age
|
54
|
+
assert mm2.age.nil?, "doh, age should be nil, but it's " + mm2.age.inspect
|
54
55
|
end
|
55
56
|
|
56
57
|
|
@@ -79,7 +80,7 @@ class TestSimpleRecord < TestBase
|
|
79
80
|
assert mm.s1 == "", "mm.s1 is not empty string, it is " + mm.s1.inspect
|
80
81
|
|
81
82
|
mm = MyModel.find(id)
|
82
|
-
assert mm.name == "Travis2"
|
83
|
+
assert mm.name == "Travis2", "Name was not Travis2, it was #{mm.name}"
|
83
84
|
assert mm.age == 10
|
84
85
|
assert mm.cool == false
|
85
86
|
assert mm.s1 == "", "mm.s1 is not empty string, it is #{mm.s1.inspect}"
|
@@ -268,13 +269,14 @@ class TestSimpleRecord < TestBase
|
|
268
269
|
|
269
270
|
# http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html#M002136
|
270
271
|
def test_changed
|
271
|
-
mm =
|
272
|
+
mm = MySimpleModel.new
|
272
273
|
mm.name = "Travis"
|
273
274
|
mm.age = 32
|
274
275
|
mm.cool = true
|
275
276
|
mm.save
|
276
277
|
|
277
278
|
puts 'changed?=' + mm.changed?.to_s
|
279
|
+
p mm.changed
|
278
280
|
assert !mm.changed?
|
279
281
|
assert mm.changed.size == 0
|
280
282
|
assert mm.changes.size == 0
|
@@ -370,25 +372,6 @@ class TestSimpleRecord < TestBase
|
|
370
372
|
|
371
373
|
end
|
372
374
|
|
373
|
-
def test_validations
|
374
|
-
mm = MyModel.new()
|
375
|
-
assert mm.invalid?
|
376
|
-
assert mm.errors.size == 1
|
377
|
-
mm.name = "abcd"
|
378
|
-
assert mm.valid?
|
379
|
-
assert mm.errors.size == 0
|
380
|
-
|
381
|
-
mm.save_count = 2
|
382
|
-
assert mm.invalid?
|
383
|
-
|
384
|
-
mm.save_count = nil
|
385
|
-
|
386
|
-
assert mm.save, mm.errors.inspect
|
387
|
-
|
388
|
-
assert mm.valid?, mm.errors.inspect
|
389
|
-
assert mm.save_count == 1
|
390
|
-
end
|
391
|
-
|
392
375
|
|
393
376
|
def test_nil_attr_deletion
|
394
377
|
mm = MyModel.new
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), "/../lib/simple_record")
|
3
|
+
require File.join(File.dirname(__FILE__), "./test_helpers")
|
4
|
+
require_relative "test_base"
|
5
|
+
require "yaml"
|
6
|
+
require 'aws'
|
7
|
+
require_relative 'my_model'
|
8
|
+
require_relative 'my_child_model'
|
9
|
+
require_relative 'model_with_enc'
|
10
|
+
|
11
|
+
# Tests for SimpleRecord
|
12
|
+
#
|
13
|
+
|
14
|
+
class TestSimpleRecord < TestBase
|
15
|
+
|
16
|
+
def test_validations
|
17
|
+
mm = MyModel.new()
|
18
|
+
puts 'invalid? ' + mm.invalid?.to_s
|
19
|
+
assert mm.invalid?, "mm is valid. invalid? returned #{mm.invalid?}"
|
20
|
+
assert mm.errors.size == 1
|
21
|
+
assert !mm.attr_before_create
|
22
|
+
assert !mm.valid?
|
23
|
+
assert mm.save == false, mm.errors.inspect
|
24
|
+
assert mm.attr_before_create
|
25
|
+
assert !mm.attr_after_save
|
26
|
+
assert !mm.attr_after_create
|
27
|
+
mm.name = "abcd"
|
28
|
+
assert mm.valid?, mm.errors.inspect
|
29
|
+
assert mm.errors.size == 0
|
30
|
+
|
31
|
+
mm.save_count = 2
|
32
|
+
assert mm.invalid?
|
33
|
+
|
34
|
+
mm.save_count = nil
|
35
|
+
assert mm.valid?
|
36
|
+
assert mm.save, mm.errors.inspect
|
37
|
+
|
38
|
+
p mm
|
39
|
+
assert mm.attr_after_save
|
40
|
+
assert mm.attr_after_create
|
41
|
+
|
42
|
+
assert mm.valid?, mm.errors.inspect
|
43
|
+
assert mm.save_count == 1
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_record
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 2
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
version: 2.0.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
|
+
prerelease: !!null
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Travis Reeder
|
13
9
|
- Chad Arimura
|
14
10
|
- RightScale
|
15
|
-
autorequire:
|
11
|
+
autorequire: !!null
|
16
12
|
bindir: bin
|
17
13
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2011-02-08 00:00:00.000000000 -08:00
|
15
|
+
default_executable: !!null
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
23
18
|
name: aws
|
24
|
-
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
requirement: &26750952 !ruby/object:Gem::Requirement
|
26
20
|
none: false
|
27
|
-
requirements:
|
28
|
-
- -
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
- 0
|
32
|
-
version: "0"
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
33
25
|
type: :runtime
|
34
|
-
|
35
|
-
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *26750952
|
28
|
+
description: ActiveRecord like interface for Amazon SimpleDB. Store, query, shard,
|
29
|
+
etc. By http://www.appoxy.com
|
36
30
|
email: travis@appoxy.com
|
37
31
|
executables: []
|
38
|
-
|
39
32
|
extensions: []
|
40
|
-
|
41
|
-
extra_rdoc_files:
|
33
|
+
extra_rdoc_files:
|
42
34
|
- README.markdown
|
43
|
-
files:
|
35
|
+
files:
|
44
36
|
- lib/simple_record.rb
|
45
37
|
- lib/simple_record/active_sdb.rb
|
46
38
|
- lib/simple_record/attributes.rb
|
@@ -50,11 +42,11 @@ files:
|
|
50
42
|
- lib/simple_record/json.rb
|
51
43
|
- lib/simple_record/logging.rb
|
52
44
|
- lib/simple_record/password.rb
|
53
|
-
- lib/simple_record/rails2.rb
|
54
45
|
- lib/simple_record/results_array.rb
|
55
46
|
- lib/simple_record/sharding.rb
|
56
47
|
- lib/simple_record/stats.rb
|
57
48
|
- lib/simple_record/translations.rb
|
49
|
+
- lib/simple_record/validations.rb
|
58
50
|
- README.markdown
|
59
51
|
- test/conversions_test.rb
|
60
52
|
- test/model_with_enc.rb
|
@@ -62,6 +54,7 @@ files:
|
|
62
54
|
- test/my_child_model.rb
|
63
55
|
- test/my_model.rb
|
64
56
|
- test/my_sharded_model.rb
|
57
|
+
- test/my_simple_model.rb
|
65
58
|
- test/paging_array_test.rb
|
66
59
|
- test/temp.rb
|
67
60
|
- test/temp_test.rb
|
@@ -79,45 +72,40 @@ files:
|
|
79
72
|
- test/test_shards.rb
|
80
73
|
- test/test_simple_record.rb
|
81
74
|
- test/test_usage.rb
|
75
|
+
- test/test_validations.rb
|
82
76
|
has_rdoc: true
|
83
77
|
homepage: http://github.com/appoxy/simple_record/
|
84
78
|
licenses: []
|
85
|
-
|
86
|
-
post_install_message:
|
79
|
+
post_install_message: !!null
|
87
80
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
81
|
+
require_paths:
|
90
82
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
84
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
|
98
|
-
version: "0"
|
99
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
90
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
|
105
|
-
- 0
|
106
|
-
version: "0"
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
107
95
|
requirements: []
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
signing_key:
|
96
|
+
rubyforge_project: !!null
|
97
|
+
rubygems_version: 1.5.0
|
98
|
+
signing_key: !!null
|
112
99
|
specification_version: 3
|
113
100
|
summary: ActiveRecord like interface for Amazon SimpleDB. By http://www.appoxy.com
|
114
|
-
test_files:
|
101
|
+
test_files:
|
115
102
|
- test/conversions_test.rb
|
116
103
|
- test/model_with_enc.rb
|
117
104
|
- test/my_base_model.rb
|
118
105
|
- test/my_child_model.rb
|
119
106
|
- test/my_model.rb
|
120
107
|
- test/my_sharded_model.rb
|
108
|
+
- test/my_simple_model.rb
|
121
109
|
- test/paging_array_test.rb
|
122
110
|
- test/temp.rb
|
123
111
|
- test/temp_test.rb
|
@@ -135,3 +123,4 @@ test_files:
|
|
135
123
|
- test/test_shards.rb
|
136
124
|
- test/test_simple_record.rb
|
137
125
|
- test/test_usage.rb
|
126
|
+
- test/test_validations.rb
|
data/lib/simple_record/rails2.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# Only used if ActiveModel is not present
|
2
|
-
|
3
|
-
module SimpleRecord
|
4
|
-
module Rails2
|
5
|
-
|
6
|
-
|
7
|
-
def valid?
|
8
|
-
errors.clear
|
9
|
-
|
10
|
-
# run_callbacks(:validate)
|
11
|
-
validate
|
12
|
-
|
13
|
-
if new_record?
|
14
|
-
# run_callbacks(:validate_on_create)
|
15
|
-
validate_on_create
|
16
|
-
else
|
17
|
-
# run_callbacks(:validate_on_update)
|
18
|
-
validate_on_update
|
19
|
-
end
|
20
|
-
|
21
|
-
errors.empty?
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def invalid?
|
26
|
-
!valid?
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|