commons_yellowme 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +234 -0
- data/bin/test +5 -0
- data/commons.gemspec +43 -0
- data/lib/commons/version.rb +1 -1
- data/spec/commons/authentication/authenticate_by_jwt_spec.rb +37 -0
- data/spec/commons/authentication/json_web_token_spec.rb +41 -0
- data/spec/commons/concerns/attributes/sex_spec.rb +24 -0
- data/spec/commons/concerns/extensions/deleted_spec.rb +42 -0
- data/spec/commons/concerns/guard/capitalizable_spec.rb +13 -0
- data/spec/commons/concerns/validations/undestroyable_spec.rb +9 -0
- data/spec/commons/errors/bad_request_spec.rb +62 -0
- data/spec/commons/errors/conflict_spec.rb +62 -0
- data/spec/commons/errors/forbidden_spec.rb +62 -0
- data/spec/commons/errors/internal_server_error_spec.rb +62 -0
- data/spec/commons/errors/invalid_resource_spec.rb +62 -0
- data/spec/commons/errors/maintenance_mode_spec.rb +49 -0
- data/spec/commons/errors/missing_parameter_spec.rb +49 -0
- data/spec/commons/errors/not_unique_spec.rb +62 -0
- data/spec/commons/errors/payment_required_spec.rb +62 -0
- data/spec/commons/errors/precondition_failed_spec.rb +62 -0
- data/spec/commons/errors/resource_not_found_spec.rb +49 -0
- data/spec/commons/errors/route_not_found_spec.rb +49 -0
- data/spec/commons/errors/unauthorized_spec.rb +62 -0
- data/spec/commons/errors/unprocessable_entity_spec.rb +62 -0
- data/spec/commons/formatter/e164_phone_spec.rb +155 -0
- data/spec/commons/formatter/regex_constants_spec.rb +102 -0
- data/spec/commons/formatter/string_utils_spec.rb +19 -0
- data/spec/commons/repositories/base_repository_spec.rb +504 -0
- data/spec/commons/repositories/catalogs/base_catalog_spec.rb +55 -0
- data/spec/commons/serializers/bad_request_spec.rb +46 -0
- data/spec/commons/serializers/conflict_spec.rb +46 -0
- data/spec/commons/serializers/forbidden_spec.rb +46 -0
- data/spec/commons/serializers/internal_server_error_spec.rb +46 -0
- data/spec/commons/serializers/invalid_resource_spec.rb +46 -0
- data/spec/commons/serializers/maintenance_mode_spec.rb +46 -0
- data/spec/commons/serializers/missing_parameter_spec.rb +44 -0
- data/spec/commons/serializers/not_unique_spec.rb +46 -0
- data/spec/commons/serializers/payment_required_spec.rb +46 -0
- data/spec/commons/serializers/precondition_failed_spec.rb +46 -0
- data/spec/commons/serializers/route_not_found_spec.rb +46 -0
- data/spec/commons/serializers/unauthorized_spec.rb +46 -0
- data/spec/commons/serializers/unprocessable_entity_spec.rb +46 -0
- data/spec/commons/shared-examples/user_spec.rb +18 -0
- data/spec/dummy/.ruby-version +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/miscellaneous_controller.rb +13 -0
- data/spec/dummy/app/errors/default_handling.rb +35 -0
- data/spec/dummy/app/errors/error_notifier.rb +12 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/packs/application.js +15 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/catalogs/application_parameter.rb +6 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/employee.rb +3 -0
- data/spec/dummy/app/models/user.rb +16 -0
- data/spec/dummy/app/repositories/catalogs/application_parameter_repository.rb +4 -0
- data/spec/dummy/app/repositories/employee_repository.rb +2 -0
- data/spec/dummy/app/repositories/user_repository.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +62 -0
- data/spec/dummy/config/environments/production.rb +112 -0
- data/spec/dummy/config/environments/test.rb +48 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +12 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20191212233443_create_user.rb +13 -0
- data/spec/dummy/db/migrate/20191213072543_create_application_parameters.rb +8 -0
- data/spec/dummy/db/migrate/20200101204534_create_employee.rb +8 -0
- data/spec/dummy/db/schema.rb +35 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/catalogs/application_parameters.rb +6 -0
- data/spec/factories/employees.rb +6 -0
- data/spec/factories/users.rb +7 -0
- data/spec/rails_helper.rb +68 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/support/.DS_Store +0 -0
- data/spec/support/shared-examples/capitalizable.rb +16 -0
- data/spec/support/shared-examples/deletable.rb +39 -0
- data/spec/support/shared-examples/dimorphic.rb +28 -0
- data/spec/support/shared-examples/stripable.rb +17 -0
- data/spec/support/shared-examples/undestroyable.rb +8 -0
- metadata +240 -3
@@ -0,0 +1,55 @@
|
|
1
|
+
describe Commons::Repositories::Catalogs::BaseCatalog, type: :repository do
|
2
|
+
# memory store is per process and therefore no conflicts in parallel tests
|
3
|
+
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
|
4
|
+
let(:cache) { Rails.cache }
|
5
|
+
let(:value) { true }
|
6
|
+
let(:app_param) { create(:application_parameter, value: value) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(Rails).to receive(:cache).and_return(memory_store)
|
10
|
+
Rails.cache.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'create_from_params!' do
|
14
|
+
let(:params) { { name: 'limit_money', value: 40_000 } }
|
15
|
+
subject { Catalogs::ApplicationParameterRepository.instance.create_from_params!(params) }
|
16
|
+
it do
|
17
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
18
|
+
is_expected.to be_an_instance_of Catalogs::ApplicationParameter
|
19
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'find_or_create_by!' do
|
24
|
+
context 'when exists' do
|
25
|
+
let(:params) { { name: app_param.name, value: app_param.value } }
|
26
|
+
subject { Catalogs::ApplicationParameterRepository.instance.find_or_create_by!(params) }
|
27
|
+
it do
|
28
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
29
|
+
is_expected.to be_an_instance_of Catalogs::ApplicationParameter
|
30
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when does not exist' do
|
35
|
+
let(:params) { { name: 'new_limit_money', value: 40_000 } }
|
36
|
+
subject { Catalogs::ApplicationParameterRepository.instance.find_or_create_by!(params) }
|
37
|
+
it do
|
38
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
39
|
+
is_expected.to be_an_instance_of Catalogs::ApplicationParameter
|
40
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'update_from_params!' do
|
46
|
+
let(:params) { { id: app_param.id, value: 40_000 } }
|
47
|
+
subject { Catalogs::ApplicationParameterRepository.instance.update_from_params!(params) }
|
48
|
+
it do
|
49
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
50
|
+
is_expected.to be_an_instance_of Catalogs::ApplicationParameter
|
51
|
+
expect(subject.value).to eq params[:value].to_s
|
52
|
+
expect(cache.exist?('cached_catalogs_application_parameter_repository')).to be(false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::BadRequest, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::Conflict, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::Forbidden, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::InternalServerError, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::InvalidResource, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:validation_errors) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, validation_errors: validation_errors) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:validation_errors]).to eq validation_errors
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::MaintenanceMode, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
RSpec.describe Commons::Errors::MissingParameter, type: :serializer do
|
2
|
+
let(:param) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:error) { described_class.new }
|
5
|
+
subject do
|
6
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
7
|
+
serializer.serializable_hash
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'serialize the model' do
|
11
|
+
context 'should validate required attributes' do
|
12
|
+
it do
|
13
|
+
serialized = subject
|
14
|
+
expect(serialized.keys).to include :status
|
15
|
+
expect(serialized.keys).to include :code
|
16
|
+
expect(serialized.keys).to include :title
|
17
|
+
expect(serialized.keys).to include :detail
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'should work with default values' do
|
22
|
+
it do
|
23
|
+
serialized = subject
|
24
|
+
expect(serialized[:status]).to eq error.status
|
25
|
+
expect(serialized[:code]).to eq error.code
|
26
|
+
expect(serialized[:title]).to eq error.title
|
27
|
+
expect(serialized[:detail]).to eq error.detail
|
28
|
+
expect(serialized[:meta]).to eq error.meta
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'should work with custom values' do
|
33
|
+
let(:error) { described_class.new(message, param: param) }
|
34
|
+
it do
|
35
|
+
serialized = subject
|
36
|
+
expect(serialized[:status]).to eq error.status
|
37
|
+
expect(serialized[:title]).to eq error.title
|
38
|
+
expect(serialized[:detail]).to eq error.detail
|
39
|
+
expect(serialized[:meta][:message]).to eq message
|
40
|
+
expect(serialized[:meta][:param]).to eq param.to_s.camelize(:lower)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::NotUnique, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Commons::Errors::PaymentRequired, type: :serializer do
|
2
|
+
let(:title) { Faker::Name.name }
|
3
|
+
let(:message) { Faker::Name.name }
|
4
|
+
let(:detail) { Faker::Name.name }
|
5
|
+
let(:meta) { { data: Faker::Name.name } }
|
6
|
+
let(:error) { described_class.new }
|
7
|
+
subject do
|
8
|
+
serializer = Commons::Errors::ErrorSerializer.new(error)
|
9
|
+
serializer.serializable_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'serialize the model' do
|
13
|
+
context 'should validate required attributes' do
|
14
|
+
it do
|
15
|
+
serialized = subject
|
16
|
+
expect(serialized.keys).to include :status
|
17
|
+
expect(serialized.keys).to include :code
|
18
|
+
expect(serialized.keys).to include :title
|
19
|
+
expect(serialized.keys).to include :detail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'should work with default values' do
|
24
|
+
it do
|
25
|
+
serialized = subject
|
26
|
+
expect(serialized[:status]).to eq error.status
|
27
|
+
expect(serialized[:code]).to eq error.code
|
28
|
+
expect(serialized[:title]).to eq error.title
|
29
|
+
expect(serialized[:detail]).to eq error.detail
|
30
|
+
expect(serialized[:meta]).to eq error.meta
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'should work with custom values' do
|
35
|
+
let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
|
36
|
+
it do
|
37
|
+
serialized = subject
|
38
|
+
expect(serialized[:status]).to eq error.status
|
39
|
+
expect(serialized[:title]).to eq title
|
40
|
+
expect(serialized[:detail]).to eq detail
|
41
|
+
expect(serialized[:meta][:message]).to eq message
|
42
|
+
expect(serialized[:meta][:data]).to eq meta[:data]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|