store_complex 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/store_complex/version.rb +1 -1
- data/spec/store_complex_spec.rb +81 -3
- data/store_complex.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f928eb507c1684b9c0d4cc8ef1790706064e3299
|
4
|
+
data.tar.gz: 934ba534eb93fd6b0393ac66b06acf7b82319779
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65ebf37c90d7d361bd5192b321697b124cc36d6cce411d571cc657e1ee37af4a2b5f549717dc7876a5da9a68331cdcacc613859c9c4210fc83667314a58ddbbe
|
7
|
+
data.tar.gz: a375c3f45053c0a2cb424bf06e25eb634e44947a466ca452d123d45b586ab4a00c55b81d84018bd555e883db54a1c60445da5d8c41c8f85c38596aea439858dd
|
data/spec/store_complex_spec.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ARSomething < ActiveRecord::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
class Something
|
7
|
+
extend StoreComplex::Accessor
|
4
8
|
def test_hstore
|
5
|
-
|
9
|
+
$test_hstore ||= {}
|
10
|
+
end
|
11
|
+
def test_hstore=(value)
|
12
|
+
$test_hstore = value
|
6
13
|
end
|
7
14
|
store_complex :test_hstore, :test_attr
|
8
15
|
end
|
9
16
|
|
17
|
+
|
10
18
|
RSpec.describe 'StoreComplex::obj_to_store' do
|
11
19
|
it 'converts nil to nil' do
|
12
20
|
expect( StoreComplex::obj_to_store(nil) ).to eq nil
|
@@ -51,7 +59,77 @@ RSpec.describe StoreComplex do
|
|
51
59
|
it 'has a version (smoke test)' do
|
52
60
|
expect(StoreComplex::VERSION).to be_a String
|
53
61
|
end
|
62
|
+
end
|
63
|
+
|
64
|
+
RSpec.describe StoreComplex::Accessor do
|
65
|
+
let(:obj) { Something.new }
|
66
|
+
let(:obj1) { Something.new }
|
54
67
|
it 'injects its methods into ActiveRecord' do
|
55
|
-
expect(
|
68
|
+
expect(ARSomething.methods).to include *StoreComplex::Accessor.instance_methods
|
69
|
+
end
|
70
|
+
it 'allows to store arrays in the store' do
|
71
|
+
value = [1,'a',true]
|
72
|
+
obj.test_attr = value
|
73
|
+
expect( obj.test_attr ).to eq value
|
74
|
+
end
|
75
|
+
it 'allows to store hashes in the store' do
|
76
|
+
value = {'a'=>'b','c'=>12}
|
77
|
+
obj.test_attr = value
|
78
|
+
expect( obj.test_attr ).to eq value
|
79
|
+
end
|
80
|
+
it 'allows to store sets in the store as arrays' do
|
81
|
+
value = Set[1,'a',true]
|
82
|
+
obj.test_attr = value
|
83
|
+
expect( obj.test_attr ).to eq value.to_a
|
84
|
+
end
|
85
|
+
it 'allows to store strings wrapped in an array' do
|
86
|
+
value = 'string'
|
87
|
+
obj.test_attr = value
|
88
|
+
expect( obj.test_attr ).to eq [value]
|
89
|
+
end
|
90
|
+
it 'allows to store integers wrapped in an array' do
|
91
|
+
value = 198
|
92
|
+
obj.test_attr = value
|
93
|
+
expect( obj.test_attr ).to eq [value]
|
94
|
+
end
|
95
|
+
it 'converts symbols to strings when storing' do
|
96
|
+
value = [:a,:b]
|
97
|
+
obj.test_attr = value
|
98
|
+
expect( obj.test_attr ).to eq value.map(&:to_s)
|
99
|
+
|
100
|
+
value = {a:1}
|
101
|
+
obj.test_attr = value
|
102
|
+
expect( obj.test_attr ).to eq value.map { |k,v| [k.to_s,v] }.to_h
|
103
|
+
end
|
104
|
+
it 'detects changes to the stored hashes' do
|
105
|
+
obj.test_attr = {'a'=>2,'b'=>4}
|
106
|
+
obj.test_attr.delete('a')
|
107
|
+
expect( obj1.test_attr ).to eq( {'b'=>4} )
|
108
|
+
end
|
109
|
+
it 'detects changes to the stored arrays' do
|
110
|
+
obj.test_attr = [1,10,8,55]
|
111
|
+
obj.test_attr.sort!
|
112
|
+
expect( obj1.test_attr ).to eq [1,8,10,55]
|
113
|
+
end
|
114
|
+
it 'detects changes to the stored sub-arrays' do
|
115
|
+
obj.test_attr = [[1,10,8,55],[2,19,88,7]]
|
116
|
+
obj.test_attr[1].sort!
|
117
|
+
expect( obj1.test_attr ).to eq [[1,10,8,55],[2,7,19,88]]
|
118
|
+
end
|
119
|
+
it 'detects changing an element in a sub-element' do
|
120
|
+
obj.test_attr = { 'a' => [1,2], 'b' => [3,4], 'c' => [5,6] }
|
121
|
+
obj.test_attr['b'][1] = 10
|
122
|
+
expect( obj1.test_attr ).to eq( { 'a' => [1,2], 'b' => [3,10], 'c' => [5,6] } )
|
123
|
+
end
|
124
|
+
it 'detects changes to the added element of a stored array' do
|
125
|
+
obj.test_attr = [[1,10,8,55],[2,19,88,7]]
|
126
|
+
obj.test_attr << [3,0,7]
|
127
|
+
obj.test_attr[2].sort!
|
128
|
+
expect( obj1.test_attr ).to eq [[1,10,8,55],[2,19,88,7],[0,3,7]]
|
129
|
+
end
|
130
|
+
it 'detects changes to the stored strings' do
|
131
|
+
obj.test_attr = ['some string']
|
132
|
+
obj.test_attr[0].upcase!
|
133
|
+
expect( obj1.test_attr ).to eq ['SOME STRING']
|
56
134
|
end
|
57
135
|
end
|
data/store_complex.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.required_ruby_version = '>= 2.1.0'
|
28
28
|
|
29
29
|
spec.add_dependency 'rails', '>= 4.0'
|
30
|
-
spec.add_dependency 'observable_object'
|
30
|
+
spec.add_dependency 'observable_object', '>= 0.1.2'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'bundler', '>= 1.6'
|
33
33
|
spec.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_complex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- moonfly (Andrey Pronin)
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.1.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.1.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|