wcc-data 0.3.3 → 0.3.7
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 +4 -4
- data/lib/wcc/data/nucleus/campus.rb +25 -3
- data/lib/wcc/data/version.rb +1 -1
- data/wcc-data.gemspec +2 -3
- metadata +9 -49
- data/.env.example +0 -3
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/Gemfile +0 -6
- data/Rakefile +0 -36
- data/bin/rspec +0 -17
- data/circle.yml +0 -6
- data/spec/spec_helper.rb +0 -24
- data/spec/support/inheritable_class_attribute_examples.rb +0 -16
- data/spec/wcc/data/config_spec.rb +0 -113
- data/spec/wcc/data/enumerated_type_spec.rb +0 -176
- data/spec/wcc/data/faraday_client_app_token_auth_spec.rb +0 -237
- data/spec/wcc/data/mapper/attributes_spec.rb +0 -94
- data/spec/wcc/data/mapper/json_response_spec.rb +0 -57
- data/spec/wcc/data/mapper/rest_configuration_spec.rb +0 -43
- data/spec/wcc/data/mapper/rest_query_spec.rb +0 -50
- data/spec/wcc/data/model_spec.rb +0 -33
- data/spec/wcc/data/nucleus/campus_spec.rb +0 -34
- data/spec/wcc/data/rack_client_app_token_auth_spec.rb +0 -219
- data/spec/wcc/data/response_spec.rb +0 -57
- data/spec/wcc/data/rest_endpoint_spec.rb +0 -71
- data/spec/wcc/data/service_spec.rb +0 -128
- data/spec/wcc/data_spec.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac996b83630b767c8a4134ee303d153f4771f588
|
4
|
+
data.tar.gz: 074ebcbe7dce878fb5f749ebcf633c5ae8ac4f1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc11f891060cc230021cb267e9abecb731a03a12d2bdc68fdc54b6b2340a642b80f6e59ae3bd7717b1526bd9a1a01aca53444855f9d1a531a92548dca6023c0c
|
7
|
+
data.tar.gz: 846ab48767df6df24f9b57ef349583f357adcc098f5e4cdc8c182b7a9612dbc02311e48feeebf419622deb8a327f1988541b1f1863f9b93471bef78c745d318f
|
@@ -27,11 +27,11 @@ module WCC::Data::Nucleus
|
|
27
27
|
code: 'FTW',
|
28
28
|
name: 'Fort Worth',
|
29
29
|
key: :ft_worth,
|
30
|
-
street: '
|
30
|
+
street: '8000 Western Hills Blvd',
|
31
31
|
city: 'Fort Worth',
|
32
32
|
state: 'TX',
|
33
|
-
zip: '
|
34
|
-
geo: [32.
|
33
|
+
zip: '76108',
|
34
|
+
geo: [32.739972, -97.455414]
|
35
35
|
},
|
36
36
|
{
|
37
37
|
id: 3,
|
@@ -54,6 +54,28 @@ module WCC::Data::Nucleus
|
|
54
54
|
state: 'TX',
|
55
55
|
zip: '75034',
|
56
56
|
geo: [33.130761, -96.822322]
|
57
|
+
},
|
58
|
+
{
|
59
|
+
id: 5,
|
60
|
+
code: 'SDL',
|
61
|
+
name: 'South Dallas',
|
62
|
+
key: :south_dallas,
|
63
|
+
street: '3400 Garden Ln',
|
64
|
+
city: 'Dallas',
|
65
|
+
state: 'TX',
|
66
|
+
zip: '75215',
|
67
|
+
geo: [32.758418, -96.743966]
|
68
|
+
},
|
69
|
+
{
|
70
|
+
id: 6,
|
71
|
+
code: 'ROC',
|
72
|
+
name: 'Cornerstone Rockwall',
|
73
|
+
key: :rockwall,
|
74
|
+
street: '1565 Airpot Rd',
|
75
|
+
city: 'Rockwall',
|
76
|
+
state: 'TX',
|
77
|
+
zip: '75087',
|
78
|
+
geo: [32.926936, -96.439255]
|
57
79
|
}
|
58
80
|
]
|
59
81
|
end
|
data/lib/wcc/data/version.rb
CHANGED
data/wcc-data.gemspec
CHANGED
@@ -13,10 +13,9 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files =
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.files = Dir['lib/**/*'] + %w[LICENSE.txt README.md wcc-data.gemspec]
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
20
|
spec.required_ruby_version = '~> 2.2'
|
22
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wcc-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -97,20 +97,12 @@ dependencies:
|
|
97
97
|
description: Watermark's library for interapp communication via APIs
|
98
98
|
email:
|
99
99
|
- dev@watermark.org
|
100
|
-
executables:
|
101
|
-
- rspec
|
100
|
+
executables: []
|
102
101
|
extensions: []
|
103
102
|
extra_rdoc_files: []
|
104
103
|
files:
|
105
|
-
- ".env.example"
|
106
|
-
- ".gitignore"
|
107
|
-
- ".rspec"
|
108
|
-
- Gemfile
|
109
104
|
- LICENSE.txt
|
110
105
|
- README.md
|
111
|
-
- Rakefile
|
112
|
-
- bin/rspec
|
113
|
-
- circle.yml
|
114
106
|
- lib/wcc/data.rb
|
115
107
|
- lib/wcc/data/config.rb
|
116
108
|
- lib/wcc/data/enumerated_type.rb
|
@@ -136,28 +128,12 @@ files:
|
|
136
128
|
- lib/wcc/data/rest_endpoint.rb
|
137
129
|
- lib/wcc/data/service.rb
|
138
130
|
- lib/wcc/data/version.rb
|
139
|
-
- spec/spec_helper.rb
|
140
|
-
- spec/support/inheritable_class_attribute_examples.rb
|
141
|
-
- spec/wcc/data/config_spec.rb
|
142
|
-
- spec/wcc/data/enumerated_type_spec.rb
|
143
|
-
- spec/wcc/data/faraday_client_app_token_auth_spec.rb
|
144
|
-
- spec/wcc/data/mapper/attributes_spec.rb
|
145
|
-
- spec/wcc/data/mapper/json_response_spec.rb
|
146
|
-
- spec/wcc/data/mapper/rest_configuration_spec.rb
|
147
|
-
- spec/wcc/data/mapper/rest_query_spec.rb
|
148
|
-
- spec/wcc/data/model_spec.rb
|
149
|
-
- spec/wcc/data/nucleus/campus_spec.rb
|
150
|
-
- spec/wcc/data/rack_client_app_token_auth_spec.rb
|
151
|
-
- spec/wcc/data/response_spec.rb
|
152
|
-
- spec/wcc/data/rest_endpoint_spec.rb
|
153
|
-
- spec/wcc/data/service_spec.rb
|
154
|
-
- spec/wcc/data_spec.rb
|
155
131
|
- wcc-data.gemspec
|
156
132
|
homepage: ''
|
157
133
|
licenses:
|
158
134
|
- MIT
|
159
135
|
metadata: {}
|
160
|
-
post_install_message:
|
136
|
+
post_install_message:
|
161
137
|
rdoc_options: []
|
162
138
|
require_paths:
|
163
139
|
- lib
|
@@ -172,25 +148,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
148
|
- !ruby/object:Gem::Version
|
173
149
|
version: '0'
|
174
150
|
requirements: []
|
175
|
-
rubyforge_project:
|
176
|
-
rubygems_version: 2.5.2
|
177
|
-
signing_key:
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.5.2.3
|
153
|
+
signing_key:
|
178
154
|
specification_version: 4
|
179
155
|
summary: Watermark's library for interapp communication via APIs
|
180
|
-
test_files:
|
181
|
-
- spec/spec_helper.rb
|
182
|
-
- spec/support/inheritable_class_attribute_examples.rb
|
183
|
-
- spec/wcc/data/config_spec.rb
|
184
|
-
- spec/wcc/data/enumerated_type_spec.rb
|
185
|
-
- spec/wcc/data/faraday_client_app_token_auth_spec.rb
|
186
|
-
- spec/wcc/data/mapper/attributes_spec.rb
|
187
|
-
- spec/wcc/data/mapper/json_response_spec.rb
|
188
|
-
- spec/wcc/data/mapper/rest_configuration_spec.rb
|
189
|
-
- spec/wcc/data/mapper/rest_query_spec.rb
|
190
|
-
- spec/wcc/data/model_spec.rb
|
191
|
-
- spec/wcc/data/nucleus/campus_spec.rb
|
192
|
-
- spec/wcc/data/rack_client_app_token_auth_spec.rb
|
193
|
-
- spec/wcc/data/response_spec.rb
|
194
|
-
- spec/wcc/data/rest_endpoint_spec.rb
|
195
|
-
- spec/wcc/data/service_spec.rb
|
196
|
-
- spec/wcc/data_spec.rb
|
156
|
+
test_files: []
|
data/.env.example
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'dotenv/tasks'
|
3
|
-
|
4
|
-
PROJECT_PATH = File.dirname(__FILE__)
|
5
|
-
LIB_PATH = File.join(PROJECT_PATH, "lib")
|
6
|
-
|
7
|
-
task :default => :test
|
8
|
-
|
9
|
-
desc 'run test examples'
|
10
|
-
task :test do
|
11
|
-
exec 'rspec .'
|
12
|
-
end
|
13
|
-
|
14
|
-
task :environment => :dotenv do
|
15
|
-
$LOAD_PATH.unshift(LIB_PATH)
|
16
|
-
require 'wcc/data'
|
17
|
-
end
|
18
|
-
|
19
|
-
task :development => [:environment] do
|
20
|
-
WCC::Data.setup do |config|
|
21
|
-
conn = config.applications[:nucleus].connection
|
22
|
-
conn.use Faraday::Response::Logger
|
23
|
-
conn.basic_auth(ENV['NUCLEUS_CLIENT_ID'], ENV['NUCLEUS_CLIENT_SECRET'])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'launch IRB shell with base environment loaded'
|
28
|
-
task :irb => :environment do
|
29
|
-
require 'irb'
|
30
|
-
ARGV.clear
|
31
|
-
IRB.start
|
32
|
-
end
|
33
|
-
|
34
|
-
desc 'launch IRB shell with development environment loaded'
|
35
|
-
task :console => [:development, :irb]
|
36
|
-
|
data/bin/rspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
#
|
4
|
-
# This file was generated by Bundler.
|
5
|
-
#
|
6
|
-
# The application 'rspec' is installed as part of a gem, and
|
7
|
-
# this file is here to facilitate running it.
|
8
|
-
#
|
9
|
-
|
10
|
-
require "pathname"
|
11
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
-
Pathname.new(__FILE__).realpath)
|
13
|
-
|
14
|
-
require "rubygems"
|
15
|
-
require "bundler/setup"
|
16
|
-
|
17
|
-
load Gem.bin_path("rspec-core", "rspec")
|
data/circle.yml
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
SPEC_DIR = File.dirname(__FILE__)
|
2
|
-
FIXTURES_DIR = File.join(SPEC_DIR, "fixtures")
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift File.join(SPEC_DIR, "..", "lib")
|
5
|
-
$LOAD_PATH.unshift SPEC_DIR
|
6
|
-
|
7
|
-
require 'dotenv'
|
8
|
-
Dotenv.load
|
9
|
-
|
10
|
-
require 'wcc/data'
|
11
|
-
require 'sidekiq'
|
12
|
-
|
13
|
-
Dir[File.join(SPEC_DIR, "support", "*.rb")].each do |support_file|
|
14
|
-
require "support/#{File.basename(support_file, ".rb")}"
|
15
|
-
end
|
16
|
-
|
17
|
-
RSpec.configure do |config|
|
18
|
-
config.run_all_when_everything_filtered = true
|
19
|
-
config.filter_run :focus
|
20
|
-
|
21
|
-
config.order = 'random'
|
22
|
-
|
23
|
-
ENV['NUCLEUS_URL'] ||= 'http://login.wcc'
|
24
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
shared_examples_for :inheritable_class_attributes do |name|
|
2
|
-
let(:subclass) { Class.new(subject) }
|
3
|
-
|
4
|
-
it "inherited value is the same as parent class" do
|
5
|
-
subject.send(:instance_variable_set, :"@#{name}", foo: :bar)
|
6
|
-
expect(subject.send(name)).to eq(foo: :bar)
|
7
|
-
expect(subclass.send(name)).to eq(foo: :bar)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "inherited reference is unique from the parent class" do
|
11
|
-
subject.send(:instance_variable_set, :"@#{name}", foo: :bar)
|
12
|
-
subclass.send(name)[:bar] = :baz
|
13
|
-
expect(subject.send(name)).to eq(foo: :bar)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WCC::Data::Config::Application do
|
4
|
-
let(:unit) { WCC::Data::Config::Application }
|
5
|
-
subject { unit.new(:name) }
|
6
|
-
|
7
|
-
describe "#initialize" do
|
8
|
-
it "takes a single name symbol and stores in @name" do
|
9
|
-
obj = unit.new(:name)
|
10
|
-
expect(obj.name).to eq(:name)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "takes a connection option and stores it in @connection" do
|
14
|
-
obj = unit.new(:name, connection: "foo")
|
15
|
-
expect(obj.connection).to eq("foo")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "sets to a blank Faraday::Connection" do
|
19
|
-
obj = unit.new(:name)
|
20
|
-
expect(obj.connection).to be_a(Faraday::Connection)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#uri=" do
|
25
|
-
it "converts a string to a URI and stores in @uri" do
|
26
|
-
subject.uri = "http://test"
|
27
|
-
expect(subject.uri).to be_a(URI)
|
28
|
-
expect(subject.uri.scheme).to eq("http")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "uses the URI object if set with a URI" do
|
32
|
-
subject.uri = test_value = URI("http://test")
|
33
|
-
expect(subject.uri).to eq(test_value)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#service" do
|
38
|
-
before(:each) do
|
39
|
-
subject.uri = "http://test.com/"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns a service object based on the URI" do
|
43
|
-
obj = subject.service
|
44
|
-
expect(obj).to be_a(WCC::Data::Service)
|
45
|
-
expect(obj.uri).to eq(subject.uri)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "passes the application connection through to the service" do
|
49
|
-
obj = subject.service
|
50
|
-
expect(obj.connection).to eq(subject.connection)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "@connection" do
|
55
|
-
it "gets and sets" do
|
56
|
-
subject.connection = "foo"
|
57
|
-
expect(subject.connection).to eq("foo")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe WCC::Data::Config do
|
63
|
-
let(:unit) { WCC::Data::Config }
|
64
|
-
subject { unit.new }
|
65
|
-
|
66
|
-
|
67
|
-
describe "#applications" do
|
68
|
-
it "returns a hash" do
|
69
|
-
expect(subject.applications).to be_a(Hash)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "defaults empty keys to an application" do
|
73
|
-
expect(subject.applications[:foo]).to be_a(WCC::Data::Config::Application)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "contains a default entry for :nucleus" do
|
77
|
-
expect(subject.applications[:nucleus].uri).to eq(
|
78
|
-
URI(ENV['NUCLEUS_URL'])
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
context "with APP_CLIENT_ID and APP_CLIENT_SECRET ENV vars set" do
|
83
|
-
after do
|
84
|
-
ENV['APP_CLIENT_ID'] = ENV['APP_CLIENT_SECRET'] = nil
|
85
|
-
end
|
86
|
-
|
87
|
-
it "sets the connection's basic auth for nucleus" do
|
88
|
-
ENV['APP_CLIENT_ID'] = "test"
|
89
|
-
ENV['APP_CLIENT_SECRET'] = "value"
|
90
|
-
|
91
|
-
header = subject.applications[:nucleus].connection.headers["Authorization"]
|
92
|
-
|
93
|
-
expect(header)
|
94
|
-
.to eq(Faraday::Request::BasicAuthentication.header("test", "value"))
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "with APP_CLIENT_ID and APP_CLIENT_SECRET not both set" do
|
99
|
-
it "does not set the basic auth for nucleus" do
|
100
|
-
header = subject.applications[:nucleus].connection.headers["Authorization"]
|
101
|
-
|
102
|
-
expect(header).to be_nil
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "#apps alias" do
|
108
|
-
it "aliases to #applications" do
|
109
|
-
expect(subject.apps).to eq(subject.applications)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe WCC::Data::EnumeratedType do
|
4
|
-
|
5
|
-
context "with configured attributes" do
|
6
|
-
let(:type) {
|
7
|
-
Class.new(described_class) do
|
8
|
-
attributes :test1, :test2
|
9
|
-
end
|
10
|
-
}
|
11
|
-
let(:object) { type.new(data) }
|
12
|
-
let(:data) {
|
13
|
-
{
|
14
|
-
test1: "test data 1",
|
15
|
-
test2: "test data 2",
|
16
|
-
ignored: "",
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
it "adds a method for all arguments passed" do
|
21
|
-
expect(object).to respond_to(:test1)
|
22
|
-
expect(object).to respond_to(:test2)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sets values from initialize hash" do
|
26
|
-
expect(object.test1).to eq("test data 1")
|
27
|
-
expect(object.test2).to eq("test data 2")
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "::defined_attributes" do
|
31
|
-
it "should return attributes" do
|
32
|
-
expect(type.defined_attributes).to eq([:test1, :test2])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "with child classes" do
|
38
|
-
let(:parent) {
|
39
|
-
Class.new(described_class) do
|
40
|
-
attributes :attr1
|
41
|
-
attributes :attr2
|
42
|
-
end
|
43
|
-
}
|
44
|
-
let(:child) {
|
45
|
-
Class.new(parent) do
|
46
|
-
attributes :attr3, :attr4
|
47
|
-
end
|
48
|
-
}
|
49
|
-
let(:parent_object) { parent.new(data) }
|
50
|
-
let(:child_object) { child.new(data) }
|
51
|
-
let(:data) {
|
52
|
-
{
|
53
|
-
attr1: "data1",
|
54
|
-
attr2: "data2",
|
55
|
-
attr3: "data3",
|
56
|
-
attr4: "data4",
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
describe "parent class" do
|
61
|
-
it "does not include child attributes" do
|
62
|
-
expect(parent_object).to_not respond_to(:attr3)
|
63
|
-
expect(parent_object).to_not respond_to(:attr4)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "includes both attributes" do
|
67
|
-
expect(parent_object).to respond_to(:attr1)
|
68
|
-
expect(parent_object).to respond_to(:attr2)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sets both attributes on initialize" do
|
72
|
-
expect(parent_object.attr1).to eq("data1")
|
73
|
-
expect(parent_object.attr2).to eq("data2")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "child class" do
|
78
|
-
it "includes all defined_attributes" do
|
79
|
-
expect(child.defined_attributes).to eq([:attr1, :attr2, :attr3, :attr4])
|
80
|
-
end
|
81
|
-
|
82
|
-
it "includes parent attributes and child attributes readers" do
|
83
|
-
expect(child_object.attr1).to eq("data1")
|
84
|
-
expect(child_object.attr2).to eq("data2")
|
85
|
-
expect(child_object.attr3).to eq("data3")
|
86
|
-
expect(child_object.attr4).to eq("data4")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
context "with db, matches?, and attributes configured" do
|
93
|
-
let(:type) {
|
94
|
-
Class.new(described_class) do
|
95
|
-
attributes :id, :name, :key
|
96
|
-
|
97
|
-
def matches?(value)
|
98
|
-
[id, key].include?(value)
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.db
|
102
|
-
[
|
103
|
-
{ id: 1, name: "One", key: :one },
|
104
|
-
{ id: 2, name: "Two", key: :two },
|
105
|
-
{ id: 3, name: "Three", key: :three },
|
106
|
-
{ id: 4, name: "Four", key: :three },
|
107
|
-
]
|
108
|
-
end
|
109
|
-
end
|
110
|
-
}
|
111
|
-
|
112
|
-
describe "::[]" do
|
113
|
-
it "returns an instance of type if match found" do
|
114
|
-
expect(type[1]).to be_a(type)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "returns nil if no match found" do
|
118
|
-
expect(type[:nil]).to be_nil
|
119
|
-
end
|
120
|
-
|
121
|
-
it "returns first match when multiple matches present" do
|
122
|
-
expect(type[:three]).to eq(type.all[2])
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "::all" do
|
127
|
-
it "returns instances of EnumeratedType for each item in db" do
|
128
|
-
expect(type.all.size).to eq(4)
|
129
|
-
expect(type.all[0]).to be_a(type)
|
130
|
-
expect(type.all[1]).to be_a(type)
|
131
|
-
expect(type.all[2]).to be_a(type)
|
132
|
-
expect(type.all[3]).to be_a(type)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "sets attributes for each record properly" do
|
136
|
-
expect(type.all[0].id).to eq(1)
|
137
|
-
expect(type.all[0].name).to eq("One")
|
138
|
-
expect(type.all[0].key).to eq(:one)
|
139
|
-
expect(type.all[1].key).to eq(:two)
|
140
|
-
expect(type.all[2].key).to eq(:three)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "caches the results" do
|
144
|
-
expect(type.all[0].object_id).to eq(type.all[0].object_id)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "::reset" do
|
149
|
-
it "clears out all and forces new object creation" do
|
150
|
-
first_id = type.all[0].object_id
|
151
|
-
type.reset
|
152
|
-
expect(type.all[0].object_id).to_not eq(first_id)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "#initialize" do
|
158
|
-
it "allows passing no argument" do
|
159
|
-
expect { described_class.new }.to_not raise_error
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "::db" do
|
164
|
-
it "raises NotImplementedError with instructions" do
|
165
|
-
expect { described_class.db }.to raise_error(NotImplementedError, /subclass/i)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "#matches?" do
|
170
|
-
it "raises NotImplementedError with instructions" do
|
171
|
-
object = described_class.new({})
|
172
|
-
expect { object.matches?(:val) }.to raise_error(NotImplementedError, /subclass/i)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|