scimitar 1.0.3 → 2.0.0

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.
@@ -1,14 +1,16 @@
1
1
  # Test app configuration.
2
2
  #
3
- Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
3
+ Rails.application.config.to_prepare do
4
+ Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
4
5
 
5
- application_controller_mixin: Module.new do
6
- def self.included(base)
7
- base.class_eval do
8
- def test_hook; end
9
- before_action :test_hook
6
+ application_controller_mixin: Module.new do
7
+ def self.included(base)
8
+ base.class_eval do
9
+ def test_hook; end
10
+ before_action :test_hook
11
+ end
10
12
  end
11
13
  end
12
- end
13
14
 
14
- })
15
+ })
16
+ end
@@ -24,53 +24,78 @@ RSpec.describe Scimitar::Resources::Base do
24
24
  end
25
25
 
26
26
  context '#initialize' do
27
- it 'builds the nested type' do
28
- resource = CustomResourse.new(name: {
29
- givenName: 'John',
30
- familyName: 'Smith'
31
- })
27
+ shared_examples 'an initializer' do | force_upper_case: |
28
+ it 'which builds the nested type' do
29
+ attributes = {
30
+ name: {
31
+ givenName: 'John',
32
+ familyName: 'Smith'
33
+ }
34
+ }
32
35
 
33
- expect(resource.name.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
34
- expect(resource.name.givenName).to eql('John')
35
- expect(resource.name.familyName).to eql('Smith')
36
- end
36
+ attributes = spec_helper_hupcase(attributes) if force_upper_case
37
+ resource = CustomResourse.new(attributes)
38
+
39
+ expect(resource.name.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
40
+ expect(resource.name.givenName).to eql('John')
41
+ expect(resource.name.familyName).to eql('Smith')
42
+ end
37
43
 
38
- it 'builds an array of nested resources' do
39
- resource = CustomResourse.new(names: [
40
- {
41
- givenName: 'John',
42
- familyName: 'Smith'
43
- },
44
- {
45
- givenName: 'Jane',
46
- familyName: 'Snow'
44
+ it 'which builds an array of nested resources' do
45
+ attributes = {
46
+ names:[
47
+ {
48
+ givenName: 'John',
49
+ familyName: 'Smith'
50
+ },
51
+ {
52
+ givenName: 'Jane',
53
+ familyName: 'Snow'
54
+ }
55
+ ]
47
56
  }
48
- ])
49
-
50
- expect(resource.names.is_a?(Array)).to be(true)
51
- expect(resource.names.first.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
52
- expect(resource.names.first.givenName).to eql('John')
53
- expect(resource.names.first.familyName).to eql('Smith')
54
- expect(resource.names.second.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
55
- expect(resource.names.second.givenName).to eql('Jane')
56
- expect(resource.names.second.familyName).to eql('Snow')
57
- expect(resource.valid?).to be(true)
58
- end
59
57
 
60
- it 'builds an array of nested resources which is invalid if the hash does not follow the schema of the complex type' do
61
- resource = CustomResourse.new(names: [
62
- {
63
- givenName: 'John',
64
- familyName: 123
58
+ attributes = spec_helper_hupcase(attributes) if force_upper_case
59
+ resource = CustomResourse.new(attributes)
60
+
61
+ expect(resource.names.is_a?(Array)).to be(true)
62
+ expect(resource.names.first.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
63
+ expect(resource.names.first.givenName).to eql('John')
64
+ expect(resource.names.first.familyName).to eql('Smith')
65
+ expect(resource.names.second.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
66
+ expect(resource.names.second.givenName).to eql('Jane')
67
+ expect(resource.names.second.familyName).to eql('Snow')
68
+ expect(resource.valid?).to be(true)
69
+ end
70
+
71
+ it 'which builds an array of nested resources which is invalid if the hash does not follow the schema of the complex type' do
72
+ attributes = {
73
+ names: [
74
+ {
75
+ givenName: 'John',
76
+ familyName: 123
77
+ }
78
+ ]
65
79
  }
66
- ])
67
80
 
68
- expect(resource.names.is_a?(Array)).to be(true)
69
- expect(resource.names.first.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
70
- expect(resource.names.first.givenName).to eql('John')
71
- expect(resource.names.first.familyName).to eql(123)
72
- expect(resource.valid?).to be(false)
73
- end
81
+ attributes = spec_helper_hupcase(attributes) if force_upper_case
82
+ resource = CustomResourse.new(attributes)
83
+
84
+ expect(resource.names.is_a?(Array)).to be(true)
85
+ expect(resource.names.first.is_a?(Scimitar::ComplexTypes::Name)).to be(true)
86
+ expect(resource.names.first.givenName).to eql('John')
87
+ expect(resource.names.first.familyName).to eql(123)
88
+ expect(resource.valid?).to be(false)
89
+ end
90
+ end # "shared_examples 'an initializer' do | force_upper_case: |"
91
+
92
+ context 'using schema-matched case' do
93
+ it_behaves_like 'an initializer', force_upper_case: false
94
+ end # "context 'using schema-matched case' do"
95
+
96
+ context 'using upper case' do
97
+ it_behaves_like 'an initializer', force_upper_case: true
98
+ end # "context 'using upper case' do"
74
99
  end # "context '#initialize' do"
75
100
 
76
101
  context '#as_json' do
@@ -88,26 +113,51 @@ RSpec.describe Scimitar::Resources::Base do
88
113
  end # "context '#as_json' do"
89
114
 
90
115
  context '.find_attribute' do
91
- it 'finds in complex type' do
92
- found = CustomResourse.find_attribute('name', 'givenName')
93
- expect(found).to be_present
94
- expect(found.name).to eql('givenName')
95
- expect(found.type).to eql('string')
96
- end
116
+ shared_examples 'a finder' do | force_upper_case: |
117
+ it 'which finds in complex type' do
118
+ args = ['name', 'givenName']
119
+ args.map!(&:upcase) if force_upper_case
97
120
 
98
- it 'finds in multi-value type, without index' do
99
- found = CustomResourse.find_attribute('names', 'givenName')
100
- expect(found).to be_present
101
- expect(found.name).to eql('givenName')
102
- expect(found.type).to eql('string')
103
- end
121
+ found = CustomResourse.find_attribute(*args)
104
122
 
105
- it 'finds in multi-value type, ignoring index' do
106
- found = CustomResourse.find_attribute('names', 42, 'givenName')
107
- expect(found).to be_present
108
- expect(found.name).to eql('givenName')
109
- expect(found.type).to eql('string')
123
+ expect(found).to be_present
124
+ expect(found.name).to eql('givenName')
125
+ expect(found.type).to eql('string')
126
+ end
127
+
128
+ it 'which finds in multi-value type, without index' do
129
+ args = ['names', 'givenName']
130
+ args.map!(&:upcase) if force_upper_case
131
+
132
+ found = CustomResourse.find_attribute(*args)
133
+
134
+ expect(found).to be_present
135
+ expect(found.name).to eql('givenName')
136
+ expect(found.type).to eql('string')
137
+ end
138
+
139
+ it 'which finds in multi-value type, ignoring index' do
140
+ args = if force_upper_case
141
+ ['NAMES', 42, 'GIVENNAME']
142
+ else
143
+ ['names', 42, 'givenName']
144
+ end
145
+
146
+ found = CustomResourse.find_attribute(*args)
147
+
148
+ expect(found).to be_present
149
+ expect(found.name).to eql('givenName')
150
+ expect(found.type).to eql('string')
151
+ end # "shared_examples 'a finder' do | force_upper_case: |"
110
152
  end
153
+
154
+ context 'using schema-matched case' do
155
+ it_behaves_like 'a finder', force_upper_case: false
156
+ end # "context 'using schema-matched case' do"
157
+
158
+ context 'using upper case' do
159
+ it_behaves_like 'a finder', force_upper_case: true
160
+ end # "context 'using upper case' do"
111
161
  end # "context '.find_attribute' do"
112
162
  end # "context 'basic operation' do"
113
163