store_schema 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/README.md +77 -72
- data/lib/store_schema/accessor_definer.rb +3 -3
- data/lib/store_schema/configuration.rb +1 -1
- data/lib/store_schema/converter.rb +6 -6
- data/lib/store_schema/module.rb +5 -5
- data/lib/store_schema/version.rb +1 -1
- data/lib/store_schema.rb +5 -5
- metadata +9 -68
- data/.gemfiles/5.1.gemfile +0 -3
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/Gemfile +0 -2
- data/Rakefile +0 -4
- data/spec/lib/store_schema_spec.rb +0 -148
- data/spec/spec_helper.rb +0 -14
- data/spec/support/db.rb +0 -14
- data/spec/support/env.rb +0 -8
- data/spec/support/models.rb +0 -12
- data/store_schema.gemspec +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e0d5a3940a73ebbeb967b4911715c13956da65f788e109001d470109e0062a5
|
4
|
+
data.tar.gz: 23edb9b000020a42596536807f688782dbcd81f66bed585c5b3a7735089d7afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d01a28c7a68a6dfcb6b6c91b95e2b1e76f35fcd04e827f3ebf24f46acd3f3696d6b1983a7776b71333fd04ec68d2cc0136c263ded640e08248c170a964c970
|
7
|
+
data.tar.gz: 443ef25604487eebd51c0287be8f7031d8364d6300648dd0926ba1bf3f54dff6b2f160470d0ea898e73171aa1dfb60fdbfa0ff622cfa5ce8a3ab4707f2b6ad41
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# Store Schema
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/store_schema.svg)](
|
4
|
-
[![Code Climate](https://codeclimate.com/github/mrrooijen/store_schema.png)](https://codeclimate.com/github/mrrooijen/store_schema)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/store_schema.svg)](https://badge.fury.io/rb/store_schema)
|
5
4
|
[![Build Status](https://travis-ci.org/mrrooijen/store_schema.svg)](https://travis-ci.org/mrrooijen/store_schema)
|
6
5
|
|
7
|
-
StoreSchema
|
6
|
+
StoreSchema enhances `ActiveRecord::Base.store_accessor` with data type conversion capabilities.
|
8
7
|
|
9
8
|
This library was developed for- and extracted from [HireFire].
|
10
9
|
|
@@ -13,8 +12,8 @@ The documentation can be found on [RubyDoc].
|
|
13
12
|
|
14
13
|
### Compatibility
|
15
14
|
|
16
|
-
-
|
17
|
-
-
|
15
|
+
- Ruby (MRI) 2.5 ~ 2.6
|
16
|
+
- ActiveRecord 5.1 ~ 6.0
|
18
17
|
|
19
18
|
|
20
19
|
### Installation
|
@@ -28,8 +27,7 @@ gem "store_schema"
|
|
28
27
|
|
29
28
|
### Example
|
30
29
|
|
31
|
-
This example assumes you have a `websites` table with a column
|
32
|
-
`config` of type `text`.
|
30
|
+
This example assumes that you have a `websites` table with a `config` column of type `text`.
|
33
31
|
|
34
32
|
Define a model and use `store_schema`.
|
35
33
|
|
@@ -39,11 +37,11 @@ class Website < ActiveRecord::Base
|
|
39
37
|
# Tell ActiveRecord that we want to serialize the :config attribute
|
40
38
|
# and store the serialized data as text in the config column.
|
41
39
|
#
|
42
|
-
# By default, `store` serializes your data
|
43
|
-
#
|
40
|
+
# By default, `store` serializes your data using the YAML coder. You can
|
41
|
+
# swap the YAML coder out for other coders, such as JSON.
|
44
42
|
#
|
45
|
-
# If you're using
|
46
|
-
# text column
|
43
|
+
# Note: If you're using PostgresSQL hstore- or json instead of a
|
44
|
+
# plain text column type, don't define `store :config`.
|
47
45
|
#
|
48
46
|
store :config, coder: JSON
|
49
47
|
|
@@ -51,10 +49,10 @@ class Website < ActiveRecord::Base
|
|
51
49
|
# ActiveRecord::Migration.
|
52
50
|
#
|
53
51
|
store_schema :config do |s|
|
54
|
-
s.string
|
55
|
-
s.integer
|
56
|
-
s.float
|
57
|
-
s.boolean
|
52
|
+
s.string :name
|
53
|
+
s.integer :visitors
|
54
|
+
s.float :apdex
|
55
|
+
s.boolean :ssl
|
58
56
|
s.datetime :published_at
|
59
57
|
end
|
60
58
|
end
|
@@ -65,90 +63,100 @@ the generated accessors.
|
|
65
63
|
|
66
64
|
```rb
|
67
65
|
website = Website.create(
|
68
|
-
name
|
69
|
-
visitors
|
70
|
-
apdex
|
71
|
-
ssl
|
72
|
-
published_at
|
66
|
+
:name => "Example Website",
|
67
|
+
:visitors => 9001,
|
68
|
+
:apdex => 1.0,
|
69
|
+
:ssl => true,
|
70
|
+
:published_at => Time.now
|
73
71
|
)
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
website.name # => (String) "Example Website"
|
74
|
+
website.visitors # => (Integer) 9001
|
75
|
+
website.apdex # => (Float) 1.0
|
76
|
+
website.ssl # => (TrueClass) true
|
77
|
+
website.published_at # => (DateTime) "Thu, 18 Sep 2014 23:18:11 +0000"
|
80
78
|
|
81
|
-
|
79
|
+
website.config
|
82
80
|
# =>
|
83
81
|
# {
|
84
|
-
# "name"
|
85
|
-
# "visitors"
|
86
|
-
# "apdex"
|
87
|
-
# "ssl"
|
82
|
+
# "name" => "Example Website",
|
83
|
+
# "visitors" => "9001",
|
84
|
+
# "apdex" => "1.0",
|
85
|
+
# "ssl" => "t",
|
88
86
|
# "published_at" => "2014-09-18 23:18:11.583168000"
|
89
87
|
# }
|
90
88
|
```
|
91
89
|
|
92
|
-
|
93
|
-
`store_schema` is more strict
|
94
|
-
to
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
90
|
+
This is similar to using ActiveRecord's built-in `store_accessor`, except
|
91
|
+
that `store_schema` is more strict about which data types are stored. It attempts
|
92
|
+
to remain consistent with ActiveRecord's regular column storage conventions.
|
93
|
+
|
94
|
+
* String
|
95
|
+
* Assigned as: `String`
|
96
|
+
* Stored as: `String`
|
97
|
+
* Retrieved as: `String`
|
98
|
+
* Integer
|
99
|
+
* Assigned as: `Integer`
|
100
|
+
* Stored as: `String`
|
101
|
+
* Retrieved as: `Integer`
|
102
|
+
* Float
|
103
|
+
* Assigned as: `Float`
|
104
|
+
* Stored as: `String`
|
105
|
+
* Retrieved as: `Float`
|
106
|
+
* Boolean (TrueClass)
|
107
|
+
* Assigned as: `1`, `"1"`, `"t"`, `"T"`, `true`, `"true"`, `"TRUE"`, `"on"`, `"ON"`
|
108
|
+
* Stored as: `"t"`
|
109
|
+
* Retrieved as: `true`
|
110
|
+
* Boolean (FalseClass)
|
111
|
+
* Assigned as: `0`, `"0"`, `"f"`, `"F"`, `false`, `"false"`, `"FALSE"`, `"off"`, `"OFF"`
|
112
|
+
* Stored as: `"f"`
|
113
|
+
* Retrieved as: `false`
|
114
|
+
* DateTime
|
115
|
+
* Assigned as: `Date`, `Time`, `DateTime`
|
116
|
+
* Stored as: `"2014-09-18 23:18:11.583168000"` (using UTC time zone)
|
117
|
+
* Retrieved as: `DateTime`
|
118
|
+
|
119
|
+
If you need to be able to query these serialized attributes, consider using
|
120
|
+
the PostgreSQL hstore extension. Otherwise, you can simply use a text column type
|
121
|
+
and define `store <column>[, coder: JSON]` in your model and it should work with
|
122
|
+
any ActiveRecord-compatible database.
|
110
123
|
|
111
124
|
|
112
125
|
### Contributing
|
113
126
|
|
114
127
|
Contributions are welcome, but please conform to these requirements:
|
115
128
|
|
116
|
-
- Ruby (MRI) 2.
|
117
|
-
- ActiveRecord 5.1.0
|
118
|
-
- 100%
|
119
|
-
|
120
|
-
- 100%
|
121
|
-
|
122
|
-
- 4.0 [Code Climate Score]
|
123
|
-
- Run `$ rubycritic lib` to generate the score locally and receive tips
|
124
|
-
- No code smells
|
125
|
-
- No duplication
|
129
|
+
- Ruby (MRI) 2.5 ~ 2.6
|
130
|
+
- ActiveRecord 5.1 ~ 6.0
|
131
|
+
- 100% Test Coverage
|
132
|
+
- Coverage results are generated after each test run at `coverage/index.html`
|
133
|
+
- 100% Passing Tests
|
134
|
+
- Run test suite with `$ rake test`
|
126
135
|
|
127
136
|
To start contributing, fork the project, clone it, and install the development dependencies:
|
128
137
|
|
129
138
|
```
|
130
|
-
git clone git@github.com:USERNAME/store_schema.git
|
131
|
-
cd store_schema
|
132
|
-
bundle
|
139
|
+
$ git clone git@github.com:USERNAME/store_schema.git
|
140
|
+
$ cd store_schema
|
141
|
+
$ bundle
|
133
142
|
```
|
134
143
|
|
135
|
-
|
144
|
+
To run the tests:
|
136
145
|
|
137
146
|
```
|
138
|
-
|
139
|
-
rubycritic lib
|
147
|
+
$ rake test
|
140
148
|
```
|
141
149
|
|
142
150
|
To run the local documentation server:
|
143
151
|
|
144
152
|
```
|
145
|
-
|
153
|
+
$ rake doc
|
146
154
|
```
|
147
155
|
|
148
|
-
Create a new branch
|
156
|
+
Create a new branch to start contributing:
|
149
157
|
|
150
158
|
```
|
151
|
-
git checkout -b my-
|
159
|
+
$ git checkout -b my-contribution master
|
152
160
|
```
|
153
161
|
|
154
162
|
Submit a pull request.
|
@@ -159,10 +167,7 @@ Submit a pull request.
|
|
159
167
|
Released under the [MIT License] by [Michael van Rooijen].
|
160
168
|
|
161
169
|
[Michael van Rooijen]: https://twitter.com/mrrooijen
|
162
|
-
[HireFire]:
|
170
|
+
[HireFire]: https://www.hirefire.io
|
163
171
|
[Passing Specs]: https://travis-ci.org/mrrooijen/store_schema
|
164
|
-
[
|
165
|
-
[RubyDoc]: http://rubydoc.info/github/mrrooijen/store_schema/master/frames
|
172
|
+
[RubyDoc]: https://rubydoc.info/github/mrrooijen/store_schema/master/frames
|
166
173
|
[MIT License]: https://github.com/mrrooijen/store_schema/blob/master/LICENSE
|
167
|
-
[RubyGems.org]: https://rubygems.org/gems/store_schema
|
168
|
-
[PostgreSQL's HStore Extension]: http://www.postgresql.org/docs/9.3/static/hstore.html
|
@@ -22,9 +22,9 @@ class StoreSchema::AccessorDefiner
|
|
22
22
|
# @param attribute [Symbol] the name of the {#column}'s attribute
|
23
23
|
#
|
24
24
|
def initialize(klass, column, type, attribute)
|
25
|
-
@klass
|
26
|
-
@column
|
27
|
-
@type
|
25
|
+
@klass = klass
|
26
|
+
@column = column
|
27
|
+
@type = type
|
28
28
|
@attribute = attribute
|
29
29
|
end
|
30
30
|
|
@@ -9,11 +9,11 @@ class StoreSchema::Converter
|
|
9
9
|
# and the converter classes.
|
10
10
|
#
|
11
11
|
MAPPING = {
|
12
|
-
string
|
13
|
-
integer
|
14
|
-
float
|
15
|
-
datetime
|
16
|
-
boolean
|
12
|
+
:string => String,
|
13
|
+
:integer => Integer,
|
14
|
+
:float => Float,
|
15
|
+
:datetime => DateTime,
|
16
|
+
:boolean => Boolean,
|
17
17
|
}
|
18
18
|
|
19
19
|
# @return [Object]
|
@@ -29,7 +29,7 @@ class StoreSchema::Converter
|
|
29
29
|
#
|
30
30
|
def initialize(value, type)
|
31
31
|
@value = value
|
32
|
-
@type
|
32
|
+
@type = type
|
33
33
|
end
|
34
34
|
|
35
35
|
# Converts {#value} from a Ruby-type value to a database-storable value.
|
data/lib/store_schema/module.rb
CHANGED
@@ -11,14 +11,14 @@ module StoreSchema::Module
|
|
11
11
|
# # Gemfile
|
12
12
|
# gem "store_schema"
|
13
13
|
#
|
14
|
-
# # app/models/
|
14
|
+
# # app/models/website.rb
|
15
15
|
# class Website < ActiveRecord::Base
|
16
16
|
#
|
17
17
|
# store_schema :config do |s|
|
18
|
-
# s.string
|
19
|
-
# s.integer
|
20
|
-
# s.float
|
21
|
-
# s.boolean
|
18
|
+
# s.string :name
|
19
|
+
# s.integer :visitors
|
20
|
+
# s.float :apdex
|
21
|
+
# s.boolean :ssl
|
22
22
|
# s.datetime :published_at
|
23
23
|
# end
|
24
24
|
# end
|
data/lib/store_schema/version.rb
CHANGED
data/lib/store_schema.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module StoreSchema
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
require_relative "store_schema/accessor_definer"
|
3
|
+
require_relative "store_schema/configuration"
|
4
|
+
require_relative "store_schema/converter"
|
5
|
+
require_relative "store_schema/module"
|
6
|
+
require_relative "store_schema/version"
|
7
7
|
end
|
8
8
|
|
9
9
|
if defined?(ActiveRecord::Base)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -80,48 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: json
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: database_cleaner
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: pry
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
83
|
- !ruby/object:Gem::Dependency
|
126
84
|
name: simplecov
|
127
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,14 +115,9 @@ executables: []
|
|
157
115
|
extensions: []
|
158
116
|
extra_rdoc_files: []
|
159
117
|
files:
|
160
|
-
-
|
161
|
-
- ".gitignore"
|
162
|
-
- ".rspec"
|
163
|
-
- ".travis.yml"
|
164
|
-
- Gemfile
|
118
|
+
- CHANGELOG.md
|
165
119
|
- LICENSE
|
166
120
|
- README.md
|
167
|
-
- Rakefile
|
168
121
|
- lib/store_schema.rb
|
169
122
|
- lib/store_schema/accessor_definer.rb
|
170
123
|
- lib/store_schema/configuration.rb
|
@@ -177,13 +130,7 @@ files:
|
|
177
130
|
- lib/store_schema/converter/string.rb
|
178
131
|
- lib/store_schema/module.rb
|
179
132
|
- lib/store_schema/version.rb
|
180
|
-
|
181
|
-
- spec/spec_helper.rb
|
182
|
-
- spec/support/db.rb
|
183
|
-
- spec/support/env.rb
|
184
|
-
- spec/support/models.rb
|
185
|
-
- store_schema.gemspec
|
186
|
-
homepage: http://mrrooijen.github.io/store_schema/
|
133
|
+
homepage: https://github.com/mrrooijen/store_schema
|
187
134
|
licenses:
|
188
135
|
- MIT
|
189
136
|
metadata: {}
|
@@ -195,21 +142,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
142
|
requirements:
|
196
143
|
- - ">="
|
197
144
|
- !ruby/object:Gem::Version
|
198
|
-
version:
|
145
|
+
version: 2.5.0
|
199
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
147
|
requirements:
|
201
148
|
- - ">="
|
202
149
|
- !ruby/object:Gem::Version
|
203
150
|
version: '0'
|
204
151
|
requirements: []
|
205
|
-
|
206
|
-
rubygems_version: 2.6.8
|
152
|
+
rubygems_version: 3.0.3
|
207
153
|
signing_key:
|
208
154
|
specification_version: 4
|
209
|
-
summary: Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.
|
210
|
-
test_files:
|
211
|
-
- spec/lib/store_schema_spec.rb
|
212
|
-
- spec/spec_helper.rb
|
213
|
-
- spec/support/db.rb
|
214
|
-
- spec/support/env.rb
|
215
|
-
- spec/support/models.rb
|
155
|
+
summary: Enhances `ActiveRecord::Base.store_accessor` with data type conversion capabilities.
|
156
|
+
test_files: []
|
data/.gemfiles/5.1.gemfile
DELETED
data/.gitignore
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
23
|
-
.DS_Store
|
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe "StoreSchema" do
|
4
|
-
|
5
|
-
let(:website) { Website.create }
|
6
|
-
|
7
|
-
describe "nil" do
|
8
|
-
|
9
|
-
it "should stay nil" do
|
10
|
-
website.update_attribute(:name, nil)
|
11
|
-
expect(website.reload.name).to be_nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "string" do
|
16
|
-
|
17
|
-
it "should remain a string" do
|
18
|
-
website.update_attribute(:name, "Store Schema")
|
19
|
-
expect(website.reload.name).to eq("Store Schema")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should convert to nil if incompatible type" do
|
23
|
-
website.update_attribute(:name, true)
|
24
|
-
expect(website.name).to eq(nil)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "integer" do
|
29
|
-
|
30
|
-
it "should cast to string and back to integer" do
|
31
|
-
website.update_attribute(:visitors, 1337)
|
32
|
-
expect(website.config["visitors"]).to eq("1337")
|
33
|
-
expect(website.visitors).to eq(1337)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should accept a string value of a digit" do
|
37
|
-
website.update_attribute(:visitors, "1337")
|
38
|
-
expect(website.config["visitors"]).to eq("1337")
|
39
|
-
expect(website.visitors).to eq(1337)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should convert to nil if incompatible value" do
|
43
|
-
website.update_attribute(:visitors, "abc")
|
44
|
-
expect(website.visitors).to eq(nil)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should convert to nil if incompatible type" do
|
48
|
-
website.update_attribute(:visitors, true)
|
49
|
-
expect(website.visitors).to eq(nil)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "float" do
|
54
|
-
|
55
|
-
it "should cast to string and back to float" do
|
56
|
-
website.update_attribute(:apdex, 0.9)
|
57
|
-
expect(website.config["apdex"]).to eq("0.9")
|
58
|
-
expect(website.apdex).to eq(0.9)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should accept a string value of a float" do
|
62
|
-
website.update_attribute(:apdex, "0.9")
|
63
|
-
expect(website.config["apdex"]).to eq("0.9")
|
64
|
-
expect(website.apdex).to eq(0.9)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should accept an integer value" do
|
68
|
-
website.update_attribute(:apdex, 1)
|
69
|
-
expect(website.config["apdex"]).to eq("1.0")
|
70
|
-
expect(website.apdex).to eq(1.0)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should accept a string value of an integer" do
|
74
|
-
website.update_attribute(:apdex, "1")
|
75
|
-
expect(website.config["apdex"]).to eq("1.0")
|
76
|
-
expect(website.apdex).to eq(1.0)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should convert to nil if incompatible value" do
|
80
|
-
website.update_attribute(:apdex, "abc")
|
81
|
-
expect(website.apdex).to eq(nil)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should convert to nil if incompatible type" do
|
85
|
-
website.update_attribute(:apdex, true)
|
86
|
-
expect(website.apdex).to eq(nil)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "boolean" do
|
91
|
-
|
92
|
-
it "should cast to string and back to boolean" do
|
93
|
-
StoreSchema::Converter::Boolean::TRUE_VALUES.each do |value|
|
94
|
-
website.update_attribute(:ssl, value)
|
95
|
-
expect(website.config["ssl"]).to eq("t")
|
96
|
-
expect(website.ssl).to eq(true)
|
97
|
-
end
|
98
|
-
|
99
|
-
StoreSchema::Converter::Boolean::FALSE_VALUES.each do |value|
|
100
|
-
website.update_attribute(:ssl, value)
|
101
|
-
expect(website.config["ssl"]).to eq("f")
|
102
|
-
expect(website.ssl).to eq(false)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should convert to nil if incompatible type" do
|
107
|
-
website.update_attribute(:ssl, "abc")
|
108
|
-
expect(website.ssl).to eq(nil)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "datetime" do
|
113
|
-
|
114
|
-
it "should cast Date to string and back to datetime" do
|
115
|
-
value = Date.new(2020)
|
116
|
-
website.update_attribute(:published_at, value)
|
117
|
-
expect(website.config["published_at"]).to eq("2020-01-01 00:00:00.000000000")
|
118
|
-
expect(website.published_at).to eq("Wed, 01 Jan 2020 00:00:00.000000000 +0000")
|
119
|
-
expect(website.published_at.class).to eq(DateTime)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should cast Time to string and back to datetime" do
|
123
|
-
value = Time.utc(2020)
|
124
|
-
website.update_attribute(:published_at, value)
|
125
|
-
expect(website.config["published_at"]).to eq("2020-01-01 00:00:00.000000000")
|
126
|
-
expect(website.published_at).to eq("Wed, 01 Jan 2020 00:00:00.000000000 +0000")
|
127
|
-
expect(website.published_at.class).to eq(DateTime)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should cast DateTime to string and back to datetime" do
|
131
|
-
value = DateTime.new(2020)
|
132
|
-
website.update_attribute(:published_at, value)
|
133
|
-
expect(website.config["published_at"]).to eq("2020-01-01 00:00:00.000000000")
|
134
|
-
expect(website.published_at).to eq("Wed, 01 Jan 2020 00:00:00.000000000 +0000")
|
135
|
-
expect(website.published_at.class).to eq(DateTime)
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should convert to nil if incompatible value" do
|
139
|
-
website.update_attribute(:published_at, "abc")
|
140
|
-
expect(website.published_at).to eq(nil)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should convert to nil if incompatible type" do
|
144
|
-
website.update_attribute(:published_at, true)
|
145
|
-
expect(website.published_at).to eq(nil)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
2
|
-
require File.expand_path("../support/env", __FILE__)
|
3
|
-
|
4
|
-
require "database_cleaner"
|
5
|
-
require "simplecov"
|
6
|
-
SimpleCov.start
|
7
|
-
|
8
|
-
require "store_schema"
|
9
|
-
require File.expand_path("../support/models", __FILE__)
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
12
|
-
config.before { DatabaseCleaner.start }
|
13
|
-
config.after { DatabaseCleaner.clean }
|
14
|
-
end
|
data/spec/support/db.rb
DELETED
data/spec/support/env.rb
DELETED
data/spec/support/models.rb
DELETED
data/store_schema.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "store_schema/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "store_schema"
|
7
|
-
spec.version = StoreSchema::VERSION
|
8
|
-
spec.authors = ["Michael van Rooijen"]
|
9
|
-
spec.email = ["michael@vanrooijen.io"]
|
10
|
-
spec.summary = %q{Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.}
|
11
|
-
spec.homepage = "http://mrrooijen.github.io/store_schema/"
|
12
|
-
spec.license = "MIT"
|
13
|
-
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
-
spec.require_paths = ["lib"]
|
18
|
-
|
19
|
-
spec.add_dependency "activerecord", ">= 5.1.0"
|
20
|
-
spec.add_development_dependency "bundler"
|
21
|
-
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec"
|
23
|
-
spec.add_development_dependency "sqlite3"
|
24
|
-
spec.add_development_dependency "json"
|
25
|
-
spec.add_development_dependency "database_cleaner"
|
26
|
-
spec.add_development_dependency "pry"
|
27
|
-
spec.add_development_dependency "simplecov"
|
28
|
-
spec.add_development_dependency "yard"
|
29
|
-
end
|