scimitar 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/scimitar/active_record_backed_resources_controller.rb +2 -2
- data/app/models/scimitar/complex_types/base.rb +43 -1
- data/app/models/scimitar/errors.rb +1 -1
- data/app/models/scimitar/resources/base.rb +22 -4
- data/app/models/scimitar/resources/mixin.rb +34 -26
- data/app/models/scimitar/schema/attribute.rb +1 -1
- data/app/models/scimitar/schema/base.rb +6 -2
- data/config/initializers/scimitar.rb +71 -67
- data/lib/scimitar/support/hash_with_indifferent_case_insensitive_access.rb +86 -0
- data/lib/scimitar/version.rb +2 -2
- data/lib/scimitar.rb +1 -0
- data/spec/apps/dummy/config/application.rb +1 -0
- data/spec/apps/dummy/config/environments/test.rb +28 -5
- data/spec/apps/dummy/config/initializers/scimitar.rb +10 -8
- data/spec/models/scimitar/resources/base_spec.rb +108 -58
- data/spec/models/scimitar/resources/mixin_spec.rb +316 -264
- data/spec/models/scimitar/resources/user_spec.rb +17 -4
- data/spec/requests/active_record_backed_resources_controller_spec.rb +172 -127
- data/spec/requests/application_controller_spec.rb +0 -1
- data/spec/requests/engine_spec.rb +26 -1
- data/spec/spec_helper.rb +27 -0
- data/spec/spec_helper_spec.rb +30 -0
- data/spec/support/hash_with_indifferent_case_insensitive_access_spec.rb +61 -0
- metadata +58 -50
@@ -1,14 +1,16 @@
|
|
1
1
|
# Test app configuration.
|
2
2
|
#
|
3
|
-
|
3
|
+
Rails.application.config.to_prepare do
|
4
|
+
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
|