post_json 1.0.3
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/MIT-LICENSE +20 -0
- data/README.md +194 -0
- data/Rakefile +21 -0
- data/lib/core_ext/abstract_adapter_extend.rb +16 -0
- data/lib/core_ext/active_record_relation_extend.rb +16 -0
- data/lib/core_ext/hash_extend.rb +36 -0
- data/lib/generators/post_json/install/install_generator.rb +32 -0
- data/lib/generators/post_json/install/templates/create_post_json_documents.rb +13 -0
- data/lib/generators/post_json/install/templates/create_post_json_dynamic_indexes.rb +9 -0
- data/lib/generators/post_json/install/templates/create_post_json_model_settings.rb +18 -0
- data/lib/generators/post_json/install/templates/create_procedures.rb +120 -0
- data/lib/generators/post_json/install/templates/enable_extensions.rb +28 -0
- data/lib/generators/post_json/install/templates/initializer.rb +9 -0
- data/lib/post_json.rb +56 -0
- data/lib/post_json/base.rb +278 -0
- data/lib/post_json/concerns/argument_methods.rb +33 -0
- data/lib/post_json/concerns/dynamic_index_methods.rb +34 -0
- data/lib/post_json/concerns/finder_methods.rb +343 -0
- data/lib/post_json/concerns/query_methods.rb +157 -0
- data/lib/post_json/concerns/settings_methods.rb +106 -0
- data/lib/post_json/dynamic_index.rb +99 -0
- data/lib/post_json/model_settings.rb +17 -0
- data/lib/post_json/query_translator.rb +48 -0
- data/lib/post_json/version.rb +3 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +26 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/post_json.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/migrate/20131015022029_enable_extensions.rb +28 -0
- data/spec/dummy/db/migrate/20131015022030_create_procedures.rb +120 -0
- data/spec/dummy/db/migrate/20131015022031_create_post_json_model_settings.rb +18 -0
- data/spec/dummy/db/migrate/20131015022032_create_post_json_collections.rb +16 -0
- data/spec/dummy/db/migrate/20131015022033_create_post_json_documents.rb +13 -0
- data/spec/dummy/db/migrate/20131015022034_create_post_json_dynamic_indexes.rb +9 -0
- data/spec/dummy/db/structure.sql +311 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/models/base_spec.rb +393 -0
- data/spec/models/collection_spec.rb +27 -0
- data/spec/models/queries_spec.rb +164 -0
- data/spec/modules/argument_methods_spec.rb +17 -0
- data/spec/modules/query_methods_spec.rb +69 -0
- data/spec/spec_helper.rb +54 -0
- metadata +184 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,393 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Base model" do
|
4
|
+
|
5
|
+
context "resolve to class" do
|
6
|
+
subject { PostJson }
|
7
|
+
|
8
|
+
it { expect { subject::Base.collection_name }.to raise_error(ArgumentError) }
|
9
|
+
|
10
|
+
context "of same class instance" do
|
11
|
+
subject { PostJson::Collection['SomeModel'] }
|
12
|
+
|
13
|
+
it { subject.should equal(PostJson::Collection['SomeModel'])}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "should allow same primary key for different models" do
|
18
|
+
let(:doc1) { PostJson::Collection['Customer'].create id: "abc"}
|
19
|
+
let(:doc2) { PostJson::Collection['Order'].create id: "abc"}
|
20
|
+
|
21
|
+
it { doc1.id.should == "abc" }
|
22
|
+
it { doc1.id.should == doc2.id}
|
23
|
+
end
|
24
|
+
|
25
|
+
context "should not allow same primary key for more documents on same model" do
|
26
|
+
before do
|
27
|
+
PostJson::Collection['Customer'].create id: "abc"
|
28
|
+
end
|
29
|
+
|
30
|
+
it { expect { PostJson::Collection['Customer'].create(id: "abc") }.to raise_error(ActiveRecord::RecordNotUnique) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "should auto-assign primary key when nil" do
|
34
|
+
subject { PostJson::Collection['Customer'].create }
|
35
|
+
its(:id) { should match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)}
|
36
|
+
end
|
37
|
+
|
38
|
+
context "should auto-assign primary key when blank" do
|
39
|
+
subject { PostJson::Collection['Customer'].create id: " " }
|
40
|
+
its(:id) { should match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)}
|
41
|
+
end
|
42
|
+
|
43
|
+
context "should strip primary key surrounded with whitespaces" do
|
44
|
+
let(:new_id) { "a b c" }
|
45
|
+
subject { PostJson::Collection['Customer'].create id: " #{new_id} " }
|
46
|
+
its(:id) { should == new_id }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "should downcase primary key" do
|
50
|
+
let(:new_id) { "abc" }
|
51
|
+
subject { PostJson::Collection['Customer'].create id: "#{new_id.upcase}" }
|
52
|
+
its(:id) { should == new_id }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "should now allow change of primary key" do
|
56
|
+
subject { PostJson::Collection['Customer'].create id: 1 }
|
57
|
+
|
58
|
+
it { expect { subject.update_attribute('id', 2) }.to raise_error(ArgumentError) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "collection name" do
|
62
|
+
let(:name) { "§!#¤%&" }
|
63
|
+
subject { PostJson::Collection[" #{name} "] }
|
64
|
+
|
65
|
+
its(:collection_name) { should == name }
|
66
|
+
|
67
|
+
context "changed" do
|
68
|
+
let(:new_name) { "Customer" }
|
69
|
+
before do
|
70
|
+
subject.rename_collection(" #{new_name} ")
|
71
|
+
end
|
72
|
+
|
73
|
+
its(:collection_name) { should == new_name }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "use timestamps" do
|
78
|
+
let(:model) { PostJson::Collection['Customer'] }
|
79
|
+
subject { model }
|
80
|
+
|
81
|
+
its(:record_timestamps) { should be_true }
|
82
|
+
|
83
|
+
context "and model attributes are not set" do
|
84
|
+
subject { model.create(id: "abc") }
|
85
|
+
|
86
|
+
its(:created_at) { should > 1.minute.ago }
|
87
|
+
its(:created_at) { should < 1.minute.from_now }
|
88
|
+
its(:updated_at) { should > 1.minute.ago }
|
89
|
+
its(:updated_at) { should < 1.minute.from_now }
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
context "is disabled" do
|
94
|
+
before do
|
95
|
+
model.record_timestamps = false
|
96
|
+
end
|
97
|
+
|
98
|
+
its(:record_timestamps) { should be_false }
|
99
|
+
|
100
|
+
context "and model attributes are not set" do
|
101
|
+
subject { model.create(id: "abc") }
|
102
|
+
|
103
|
+
its(:created_at) { should be_nil }
|
104
|
+
its(:updated_at) { should be_nil }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "move attributes to body" do
|
110
|
+
subject { PostJson::Collection['Customer'].create(id: "abc", name: "Jacob") }
|
111
|
+
|
112
|
+
it { subject.read_attribute('id').should == "abc" }
|
113
|
+
it { subject.read_attribute('__doc__body')['id'].should == "abc" }
|
114
|
+
it { subject.read_attribute('__doc__body')['name'].should == "Jacob" }
|
115
|
+
end
|
116
|
+
|
117
|
+
context "with unique cache key" do
|
118
|
+
subject { PostJson::Collection['Customer'].create(id: "abc", name: "Jacob") }
|
119
|
+
|
120
|
+
context "version number" do
|
121
|
+
before do
|
122
|
+
subject.update_column('__doc__version', 10)
|
123
|
+
end
|
124
|
+
|
125
|
+
let(:expected_cache_key) {"#{subject.class.name.underscore.dasherize}-#{subject.id}-version-#{subject.__doc__version}"}
|
126
|
+
|
127
|
+
its(:cache_key) { should == expected_cache_key }
|
128
|
+
end
|
129
|
+
|
130
|
+
context "digest" do
|
131
|
+
before do
|
132
|
+
subject.update_column('__doc__version', nil)
|
133
|
+
end
|
134
|
+
let(:expected_cache_key) {"#{subject.class.name.underscore.dasherize}-#{subject.id}-version-#{Digest::MD5.hexdigest(subject.attributes.inspect)}"}
|
135
|
+
|
136
|
+
its(:cache_key) { should == expected_cache_key }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "attributes" do
|
141
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
142
|
+
subject do
|
143
|
+
PostJson::Collection['Customer'].record_timestamps = false
|
144
|
+
PostJson::Collection['Customer'].include_version_number = false
|
145
|
+
PostJson::Collection['Customer'].create(body)
|
146
|
+
end
|
147
|
+
|
148
|
+
its(:attributes) { should == body }
|
149
|
+
end
|
150
|
+
|
151
|
+
context "to hash" do
|
152
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
153
|
+
subject { PostJson::Collection['Customer'].create(body) }
|
154
|
+
|
155
|
+
its(:to_h) { should == subject.attributes }
|
156
|
+
its(:to_h) { should_not equal(subject.attributes) }
|
157
|
+
end
|
158
|
+
|
159
|
+
context "body attribute" do
|
160
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
161
|
+
let(:other_body) { {"id" => "abc", "name" => "Martin"} }
|
162
|
+
subject do
|
163
|
+
PostJson::Collection['Customer'].record_timestamps = false
|
164
|
+
PostJson::Collection['Customer'].include_version_number = false
|
165
|
+
PostJson::Collection['Customer'].create(body)
|
166
|
+
end
|
167
|
+
|
168
|
+
its(:__doc__body) { should == body }
|
169
|
+
its(:__doc__body_was) { should == body }
|
170
|
+
its(:__doc__body_change) { should be_nil }
|
171
|
+
its(:__doc__body_changed?) { should be_false }
|
172
|
+
it { subject.__doc__body_read_attribute('name').should == "Jacob" }
|
173
|
+
it { subject.__doc__body_attribute_was('name').should == "Jacob" }
|
174
|
+
it { subject.__doc__body_attribute_changed?('name').should be_false }
|
175
|
+
it { subject['name'].should == "Jacob" }
|
176
|
+
it { subject.attribute_changed?('name').should be_false }
|
177
|
+
|
178
|
+
context "change" do
|
179
|
+
before do
|
180
|
+
#subject.write_attribute('__doc__body', other_body)
|
181
|
+
subject.__doc__body_write_attribute('name', "Martin")
|
182
|
+
end
|
183
|
+
|
184
|
+
its(:__doc__body) { should == other_body }
|
185
|
+
its(:__doc__body_was) { should == body }
|
186
|
+
its(:__doc__body_change) { should == [body, other_body] }
|
187
|
+
its(:__doc__body_changed?) { should be_true }
|
188
|
+
it { subject.__doc__body_read_attribute('name').should == "Martin" }
|
189
|
+
it { subject.__doc__body_attribute_was('name').should == "Jacob" }
|
190
|
+
it { subject.__doc__body_attribute_changed?('name').should be_true }
|
191
|
+
it { subject['name'].should == "Martin" }
|
192
|
+
it { subject.attribute_changed?('name').should be_true }
|
193
|
+
end
|
194
|
+
|
195
|
+
context "unchange" do
|
196
|
+
before do
|
197
|
+
# subject.write_attribute('__doc__body', other_body)
|
198
|
+
# subject.write_attribute('__doc__body', body)
|
199
|
+
subject.__doc__body_write_attribute('name', "Martin")
|
200
|
+
subject.__doc__body_write_attribute('name', "Jacob")
|
201
|
+
end
|
202
|
+
|
203
|
+
its(:__doc__body) { should == body }
|
204
|
+
its(:__doc__body_was) { should == body }
|
205
|
+
its(:__doc__body_change) { should be_nil }
|
206
|
+
its(:__doc__body_changed?) { should be_false }
|
207
|
+
it { subject.__doc__body_read_attribute('name').should == "Jacob" }
|
208
|
+
it { subject.__doc__body_attribute_was('name').should == "Jacob" }
|
209
|
+
it { subject.__doc__body_attribute_changed?('name').should be_false }
|
210
|
+
it { subject['name'].should == "Jacob" }
|
211
|
+
it { subject.attribute_changed?('name').should be_false }
|
212
|
+
end
|
213
|
+
|
214
|
+
context "nil as body" do
|
215
|
+
before do
|
216
|
+
subject.__doc__body = nil
|
217
|
+
end
|
218
|
+
|
219
|
+
its(:__doc__body) { should be_nil }
|
220
|
+
its(:__doc__body_was) { should == body }
|
221
|
+
its(:__doc__body_change) { should == [body, nil] }
|
222
|
+
its(:__doc__body_changed?) { should be_true }
|
223
|
+
it { subject.__doc__body_read_attribute('name').should be_nil }
|
224
|
+
it { subject.__doc__body_attribute_was('name').should == "Jacob" }
|
225
|
+
it { subject.__doc__body_attribute_changed?('name').should be_true }
|
226
|
+
it { subject['name'].should be_nil }
|
227
|
+
it { subject.attribute_changed?('name').should be_true }
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "body attribute" do
|
232
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
233
|
+
subject { PostJson::Collection['Customer'].create(body) }
|
234
|
+
|
235
|
+
its(:name) { should == "Jacob" }
|
236
|
+
its(:name_changed?) { should be_false }
|
237
|
+
its(:name_was) { should == "Jacob" }
|
238
|
+
its(:name_change) { should be_nil }
|
239
|
+
|
240
|
+
context "changed" do
|
241
|
+
before do
|
242
|
+
subject.name = "Martin"
|
243
|
+
end
|
244
|
+
|
245
|
+
its(:name) { should == "Martin" }
|
246
|
+
its(:name_changed?) { should be_true }
|
247
|
+
its(:name_was) { should == "Jacob" }
|
248
|
+
its(:name_change) { should == ["Jacob", "Martin"] }
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context "version enabled" do
|
253
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
254
|
+
subject { PostJson::Collection['Customer'].create(body) }
|
255
|
+
|
256
|
+
its(:version) { should == 1 }
|
257
|
+
|
258
|
+
context "after update with change" do
|
259
|
+
before do
|
260
|
+
subject.name = "Martin"
|
261
|
+
subject.save
|
262
|
+
end
|
263
|
+
|
264
|
+
its(:version) { should == 2 }
|
265
|
+
end
|
266
|
+
|
267
|
+
context "after update without change" do
|
268
|
+
before do
|
269
|
+
subject.name = "Martin"
|
270
|
+
subject.name = "Jacob"
|
271
|
+
subject.save
|
272
|
+
end
|
273
|
+
|
274
|
+
its(:version) { should == 1 }
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context "version disabled" do
|
279
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
280
|
+
subject do
|
281
|
+
PostJson::Collection['Customer'].include_version_number = false
|
282
|
+
PostJson::Collection['Customer'].create(body)
|
283
|
+
end
|
284
|
+
|
285
|
+
its(:version) { should be_nil }
|
286
|
+
|
287
|
+
context "after update with change" do
|
288
|
+
before do
|
289
|
+
subject.name = "Martin"
|
290
|
+
subject.save
|
291
|
+
end
|
292
|
+
|
293
|
+
its(:version) { should be_nil }
|
294
|
+
end
|
295
|
+
|
296
|
+
context "after update without change" do
|
297
|
+
before do
|
298
|
+
subject.name = "Martin"
|
299
|
+
subject.name = "Jacob"
|
300
|
+
subject.save
|
301
|
+
end
|
302
|
+
|
303
|
+
its(:version) { should be_nil }
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
context "model settings" do
|
308
|
+
subject { PostJson::Collection['Customer'] }
|
309
|
+
|
310
|
+
its(:meta) { should == {} }
|
311
|
+
its(:record_timestamps) { should be_true }
|
312
|
+
its(:created_at_attribute_name) { should == "created_at" }
|
313
|
+
its(:updated_at_attribute_name) { should == "updated_at" }
|
314
|
+
its(:include_version_number) { should be_true }
|
315
|
+
its(:version_attribute_name) { should == "version" }
|
316
|
+
its(:use_dynamic_index) { should be_true }
|
317
|
+
its(:create_dynamic_index_milliseconds_threshold) { should == 50 }
|
318
|
+
|
319
|
+
context "meta" do
|
320
|
+
before { subject.meta = {"validate" => true} }
|
321
|
+
its(:meta) { should == {"validate" => true} }
|
322
|
+
end
|
323
|
+
|
324
|
+
context "record_timestamps" do
|
325
|
+
before { subject.record_timestamps = false }
|
326
|
+
its(:record_timestamps) { should be_false }
|
327
|
+
end
|
328
|
+
|
329
|
+
context "created_at_attribute_name" do
|
330
|
+
before { subject.created_at_attribute_name = "createdAt" }
|
331
|
+
its(:created_at_attribute_name) { should == "createdAt" }
|
332
|
+
end
|
333
|
+
|
334
|
+
context "updated_at_attribute_name" do
|
335
|
+
before { subject.updated_at_attribute_name = "updatedAt" }
|
336
|
+
its(:updated_at_attribute_name) { should == "updatedAt" }
|
337
|
+
end
|
338
|
+
|
339
|
+
context "include_version_number" do
|
340
|
+
before { subject.include_version_number = false }
|
341
|
+
its(:include_version_number) { should be_false }
|
342
|
+
end
|
343
|
+
|
344
|
+
context "version_attribute_name" do
|
345
|
+
before { subject.version_attribute_name = "lock_version" }
|
346
|
+
its(:version_attribute_name) { should == "lock_version" }
|
347
|
+
end
|
348
|
+
|
349
|
+
context "use_dynamic_index" do
|
350
|
+
before { subject.use_dynamic_index = false }
|
351
|
+
its(:use_dynamic_index) { should be_false }
|
352
|
+
end
|
353
|
+
|
354
|
+
context "create_dynamic_index_milliseconds_threshold" do
|
355
|
+
before { subject.create_dynamic_index_milliseconds_threshold = 111 }
|
356
|
+
its(:create_dynamic_index_milliseconds_threshold) { should == 111 }
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context "dynamic indexes" do
|
361
|
+
subject { PostJson::Collection['Customer'] }
|
362
|
+
|
363
|
+
its(:dynamic_indexes) { should == [] }
|
364
|
+
|
365
|
+
context "create index" do
|
366
|
+
let(:selector) { "name" }
|
367
|
+
before do
|
368
|
+
subject.create_dynamic_index(selector)
|
369
|
+
end
|
370
|
+
its(:dynamic_indexes) { should == [selector] }
|
371
|
+
|
372
|
+
context "and destroy index" do
|
373
|
+
before do
|
374
|
+
subject.destroy_dynamic_index(selector)
|
375
|
+
end
|
376
|
+
its(:dynamic_indexes) { should == [] }
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context "json" do
|
382
|
+
let(:body) { {"id" => "abc", "name" => "Jacob"} }
|
383
|
+
let(:document) { PostJson::Collection['Customer'].create(body) }
|
384
|
+
subject { JSON.parse(document.to_json) }
|
385
|
+
|
386
|
+
it { subject.keys.sort.should == ["created_at", "id", "name", "updated_at", "version"] }
|
387
|
+
it { subject["created_at"].should == document.created_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ') }
|
388
|
+
it { subject["id"].should == document.id }
|
389
|
+
it { subject["name"].should == document.name }
|
390
|
+
it { subject["updated_at"].should == document.updated_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ') }
|
391
|
+
it { subject["version"].should == document.version }
|
392
|
+
end
|
393
|
+
end
|