light_mongo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/VERSION +1 -1
- data/lib/document/active_model_compliance.rb +49 -0
- data/spec/document/active_model_compliance_spec.rb +119 -0
- metadata +4 -1
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'active_model/naming'
|
4
|
+
|
5
|
+
require 'active_model/deprecated_error_methods'
|
6
|
+
require 'active_model/errors'
|
7
|
+
|
8
|
+
# Still missing from complete ActionPack integration is
|
9
|
+
# validations, which I've left out of this "barebones"
|
10
|
+
# compliance, and translations, which might be worth
|
11
|
+
# bundling in the future.
|
12
|
+
|
13
|
+
module LightMongo
|
14
|
+
module Document
|
15
|
+
|
16
|
+
module ActiveModelCompliance
|
17
|
+
# Replace this with your own validations.
|
18
|
+
def valid?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
# There is currently no useful difference
|
23
|
+
# between a new record and a destroyed record.
|
24
|
+
#
|
25
|
+
# As such, these methods are essentially synonymous.
|
26
|
+
def new_record?
|
27
|
+
@_id.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroyed?
|
31
|
+
@_id.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@errors = ActiveModel::Errors.new(self)
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def errors
|
40
|
+
@errors
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.included(doc_class)
|
44
|
+
doc_class.extend ActiveModel::Naming
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../lib/document/active_model_compliance'
|
2
|
+
|
3
|
+
ActiveModelCompliance = LightMongo::Document::ActiveModelCompliance
|
4
|
+
|
5
|
+
class ActiveModelComplianceTest
|
6
|
+
include LightMongo::Document::ActiveModelCompliance
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ActiveModelCompliance do
|
10
|
+
before(:each) do
|
11
|
+
@model = ActiveModelComplianceTest.new
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#valid?" do
|
15
|
+
it "responds to #valid?" do
|
16
|
+
@model.should respond_to(:valid?)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "always returns true" do
|
20
|
+
@model.valid?.should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#new_record?" do
|
25
|
+
it "responds to #new_record?" do
|
26
|
+
@model.should respond_to(:new_record?)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when the object has an id" do
|
30
|
+
before(:each) do
|
31
|
+
@model.instance_variable_set(:@_id, mock(:id))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is false" do
|
35
|
+
@model.new_record?.should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the object has no id" do
|
40
|
+
before(:each) do
|
41
|
+
@model.instance_variable_set(:@_id, nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "is true" do
|
45
|
+
@model.new_record?.should be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#destroyed?" do
|
51
|
+
it "responds to #destroyed?" do
|
52
|
+
@model.should respond_to(:destroyed?)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the object has an id" do
|
56
|
+
before(:each) do
|
57
|
+
@model.instance_variable_set(:@_id, mock(:id))
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is false" do
|
61
|
+
@model.destroyed?.should be_false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when the object has no id" do
|
66
|
+
before(:each) do
|
67
|
+
@model.instance_variable_set(:@_id, nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "is true" do
|
71
|
+
@model.destroyed?.should be_true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#errors" do
|
77
|
+
it "responds to errors" do
|
78
|
+
@model.should respond_to(:errors)
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#[]" do
|
82
|
+
it "returns an array on a missing key lookup" do
|
83
|
+
@model.errors[:does_not_exist].should be_an(Array)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#full_messages" do
|
88
|
+
it "returns an array" do
|
89
|
+
@model.errors.full_messages.should be_an(Array)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe ".model_name" do
|
95
|
+
it "responds to model_name" do
|
96
|
+
ActiveModelComplianceTest.should respond_to(:model_name)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "is a string" do
|
100
|
+
ActiveModelComplianceTest.model_name.should be_a(String)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "has a human inflector" do
|
104
|
+
ActiveModelComplianceTest.model_name.human.should be_a(String)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "has a partial path inflector" do
|
108
|
+
ActiveModelComplianceTest.model_name.partial_path.should be_a(String)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "has a singular inflector" do
|
112
|
+
ActiveModelComplianceTest.model_name.singular.should be_a(String)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "has a plural inflector" do
|
116
|
+
ActiveModelComplianceTest.model_name.plural.should be_a(String)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light_mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Crosby-McCullough
|
@@ -44,12 +44,14 @@ files:
|
|
44
44
|
- integration/object_embedding_spec.rb
|
45
45
|
- integration/support/integration_helper.rb
|
46
46
|
- lib/document.rb
|
47
|
+
- lib/document/active_model_compliance.rb
|
47
48
|
- lib/document/persistence.rb
|
48
49
|
- lib/document/serialization.rb
|
49
50
|
- lib/document/serialization/hash_serializer.rb
|
50
51
|
- lib/document/serialization/serializer.rb
|
51
52
|
- lib/light_mongo.rb
|
52
53
|
- lib/util.rb
|
54
|
+
- spec/document/active_model_compliance_spec.rb
|
53
55
|
- spec/document/persistence_spec.rb
|
54
56
|
- spec/document/serialization/hash_serializer_spec.rb
|
55
57
|
- spec/document/serialization/serializer_spec.rb
|
@@ -84,6 +86,7 @@ signing_key:
|
|
84
86
|
specification_version: 3
|
85
87
|
summary: A lightweight Ruby object persistence library for Mongo DB
|
86
88
|
test_files:
|
89
|
+
- spec/document/active_model_compliance_spec.rb
|
87
90
|
- spec/document/persistence_spec.rb
|
88
91
|
- spec/document/serialization/hash_serializer_spec.rb
|
89
92
|
- spec/document/serialization/serializer_spec.rb
|