pvdgm_services 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/Rakefile +40 -0
- data/app/contexts/services/accept_hl7_message_context.rb +32 -0
- data/app/contexts/services/application_mds_context.rb +21 -0
- data/app/contexts/services/complete_sltc_registration_process_context.rb +23 -0
- data/app/contexts/services/create_account_mapping_context.rb +23 -0
- data/app/contexts/services/create_configured_account_context.rb +26 -0
- data/app/contexts/services/create_configured_facility_context.rb +26 -0
- data/app/contexts/services/create_credential_context.rb +23 -0
- data/app/contexts/services/create_facility_mapping_context.rb +23 -0
- data/app/contexts/services/create_public_key_context.rb +22 -0
- data/app/contexts/services/create_service_context.rb +22 -0
- data/app/contexts/services/create_service_definition_context.rb +26 -0
- data/app/contexts/services/create_sltc_registration_context.rb +24 -0
- data/app/contexts/services/create_third_party_context.rb +22 -0
- data/app/contexts/services/hl7_message_trimming_context.rb +19 -0
- data/app/contexts/services/invoke_service_context.rb +21 -0
- data/app/contexts/services/list_sltc_providers_context.rb +22 -0
- data/app/contexts/services/mds_file_processing_context.rb +27 -0
- data/app/contexts/services/mds_file_upload_context.rb +25 -0
- data/app/contexts/services/mds_pull_context.rb +21 -0
- data/app/contexts/services/monthly_service_table_cleanup_context.rb +19 -0
- data/app/contexts/services/notify_new_registration_context.rb +22 -0
- data/app/contexts/services/notify_sltc_provider_change_context.rb +19 -0
- data/app/contexts/services/request_sltc_baseline_context.rb +23 -0
- data/app/contexts/services/update_account_mapping_context.rb +23 -0
- data/app/contexts/services/update_configured_account_context.rb +26 -0
- data/app/contexts/services/update_configured_facility_context.rb +26 -0
- data/app/contexts/services/update_credential_context.rb +23 -0
- data/app/contexts/services/update_facility_mapping_context.rb +23 -0
- data/app/contexts/services/update_public_key_context.rb +23 -0
- data/app/contexts/services/update_service_context.rb +23 -0
- data/app/contexts/services/update_service_definition_context.rb +26 -0
- data/app/contexts/services/update_third_party_context.rb +23 -0
- data/app/controllers/services/account_mappings_controller.rb +54 -0
- data/app/controllers/services/adts_controller.rb +35 -0
- data/app/controllers/services/application_controller.rb +17 -0
- data/app/controllers/services/assessment_requests_controller.rb +48 -0
- data/app/controllers/services/available_files_controller.rb +19 -0
- data/app/controllers/services/configured_account_base_controller.rb +17 -0
- data/app/controllers/services/configured_accounts_controller.rb +59 -0
- data/app/controllers/services/configured_facilities_controller.rb +65 -0
- data/app/controllers/services/facility_mappings_controller.rb +58 -0
- data/app/controllers/services/mds_files_controller.rb +75 -0
- data/app/controllers/services/mds_pull_accounts_controller.rb +57 -0
- data/app/controllers/services/public_keys_controller.rb +50 -0
- data/app/controllers/services/service_base_controller.rb +18 -0
- data/app/controllers/services/service_definition_base_controller.rb +31 -0
- data/app/controllers/services/service_definitions_controller.rb +59 -0
- data/app/controllers/services/services_controller.rb +56 -0
- data/app/controllers/services/sltc_providers_controller.rb +15 -0
- data/app/controllers/services/sltc_registrations_controller.rb +74 -0
- data/app/controllers/services/status_masking.rb +17 -0
- data/app/controllers/services/third_parties_controller.rb +47 -0
- data/app/controllers/services/third_party_base_controller.rb +17 -0
- data/app/controllers/services/validation_controller.rb +17 -0
- data/app/helpers/services/application_helper.rb +8 -0
- data/app/helpers/services/assessment_request_helper.rb +19 -0
- data/app/helpers/services/available_files_helper.rb +27 -0
- data/app/helpers/services/mds_pull_accounts_helper.rb +27 -0
- data/app/helpers/services/sltc_registrations_helper.rb +15 -0
- data/app/mailers/services_mailer.rb +57 -0
- data/app/models/services/abaqis_mds_push.rb +51 -0
- data/app/models/services/account_mapping.rb +10 -0
- data/app/models/services/application_api.rb +19 -0
- data/app/models/services/assessment_request.rb +18 -0
- data/app/models/services/available_file.rb +73 -0
- data/app/models/services/configured_account.rb +26 -0
- data/app/models/services/configured_facility.rb +16 -0
- data/app/models/services/credential.rb +9 -0
- data/app/models/services/facility_mapping.rb +12 -0
- data/app/models/services/ftp_server.rb +69 -0
- data/app/models/services/hl7_inbound_service.rb +47 -0
- data/app/models/services/hl7_message.rb +27 -0
- data/app/models/services/isc_code.rb +15 -0
- data/app/models/services/isc_code_lookup.rb +75 -0
- data/app/models/services/mds_assessment.rb +371 -0
- data/app/models/services/mds_content.rb +55 -0
- data/app/models/services/mds_pull.rb +41 -0
- data/app/models/services/mds_pull_account.rb +192 -0
- data/app/models/services/mds_push.rb +24 -0
- data/app/models/services/mds_upload.rb +64 -0
- data/app/models/services/mds_upload_content.rb +148 -0
- data/app/models/services/mds_ws_response.rb +21 -0
- data/app/models/services/mds_ws_response_handler.rb +31 -0
- data/app/models/services/pcc_mds_pull.rb +77 -0
- data/app/models/services/provider_change.rb +26 -0
- data/app/models/services/public_key.rb +11 -0
- data/app/models/services/service.rb +20 -0
- data/app/models/services/service_definition.rb +37 -0
- data/app/models/services/service_implementation.rb +29 -0
- data/app/models/services/sltc_api.rb +179 -0
- data/app/models/services/sltc_api_exception.rb +54 -0
- data/app/models/services/sltc_mds_pull.rb +230 -0
- data/app/models/services/sltc_registration.rb +23 -0
- data/app/models/services/third_party.rb +18 -0
- data/app/roles/services/account_mapping_creator.rb +13 -0
- data/app/roles/services/account_mapping_updator.rb +12 -0
- data/app/roles/services/configured_account_creator.rb +13 -0
- data/app/roles/services/configured_account_updater.rb +12 -0
- data/app/roles/services/configured_facility_creator.rb +13 -0
- data/app/roles/services/configured_facility_updater.rb +12 -0
- data/app/roles/services/credential_creator.rb +11 -0
- data/app/roles/services/credential_updater.rb +20 -0
- data/app/roles/services/facility_mapping_creator.rb +13 -0
- data/app/roles/services/facility_mapping_updater.rb +11 -0
- data/app/roles/services/hl7_adt_message_saver.rb +15 -0
- data/app/roles/services/hl7_message_trimmer.rb +14 -0
- data/app/roles/services/mds_assessment_categorizer.rb +71 -0
- data/app/roles/services/mds_file_processor.rb +86 -0
- data/app/roles/services/mds_notifications.rb +44 -0
- data/app/roles/services/monthly_service_table_cleaner.rb +19 -0
- data/app/roles/services/new_registration_notifier.rb +11 -0
- data/app/roles/services/public_key_creator.rb +14 -0
- data/app/roles/services/public_key_updater.rb +12 -0
- data/app/roles/services/service_creator.rb +13 -0
- data/app/roles/services/service_definition_creator.rb +13 -0
- data/app/roles/services/service_definition_updater.rb +12 -0
- data/app/roles/services/service_invoker.rb +25 -0
- data/app/roles/services/service_updater.rb +11 -0
- data/app/roles/services/sltc_baseline_requestor.rb +19 -0
- data/app/roles/services/sltc_provider_change_notifier.rb +25 -0
- data/app/roles/services/sltc_provider_lister.rb +13 -0
- data/app/roles/services/sltc_registration_completer.rb +81 -0
- data/app/roles/services/sltc_registration_saver.rb +13 -0
- data/app/roles/services/submit_mds_file_for_processing.rb +28 -0
- data/app/roles/services/third_party_creator.rb +13 -0
- data/app/roles/services/third_party_updater.rb +12 -0
- data/app/utils/services/file_upload_handler.rb +33 -0
- data/app/utils/services/mds_upload_filters.rb +26 -0
- data/app/utils/services/mds_xml_file_parser.rb +104 -0
- data/app/utils/services/upload_file.rb +13 -0
- data/app/validators/isc_code_validator.rb +42 -0
- data/app/validators/mds_birthdate_validator.rb +37 -0
- data/app/validators/mds_date_validator.rb +8 -0
- data/app/validators/mds_integer_validator.rb +15 -0
- data/app/validators/mds_version_validator.rb +16 -0
- data/app/validators/state_code_validator.rb +9 -0
- data/app/views/layouts/services/application.html.erb +14 -0
- data/app/views/services/account_mappings/index.json.jbuilder +9 -0
- data/app/views/services/account_mappings/show.json.jbuilder +7 -0
- data/app/views/services/assessment_requests/index.json.jbuilder +11 -0
- data/app/views/services/available_files/index.json.jbuilder +13 -0
- data/app/views/services/configured_accounts/index.json.jbuilder +13 -0
- data/app/views/services/configured_accounts/show.json.jbuilder +11 -0
- data/app/views/services/configured_facilities/index.json.jbuilder +13 -0
- data/app/views/services/configured_facilities/show.json.jbuilder +11 -0
- data/app/views/services/facility_mappings/index.json.jbuilder +10 -0
- data/app/views/services/facility_mappings/show.json.jbuilder +8 -0
- data/app/views/services/mds_files/create.builder +10 -0
- data/app/views/services/mds_pull_accounts/index.json.jbuilder +11 -0
- data/app/views/services/public_keys/index.json.jbuilder +8 -0
- data/app/views/services/public_keys/show.json.jbuilder +6 -0
- data/app/views/services/service_definitions/index.json.jbuilder +17 -0
- data/app/views/services/service_definitions/show.json.jbuilder +16 -0
- data/app/views/services/services/index.json.jbuilder +6 -0
- data/app/views/services/services/show.json.jbuilder +4 -0
- data/app/views/services/sltc_providers/index.json.jbuilder +10 -0
- data/app/views/services/sltc_registrations/index.json.jbuilder +10 -0
- data/app/views/services/third_parties/index.json.jbuilder +7 -0
- data/app/views/services/third_parties/show.json.jbuilder +5 -0
- data/app/views/services_mailer/burying_job.html.erb +20 -0
- data/app/views/services_mailer/delaying_job.html.erb +20 -0
- data/app/views/services_mailer/notify_sltc_client_registration.html.erb +39 -0
- data/app/views/services_mailer/notify_sltc_client_registration_invalid_request_type.html.erb +8 -0
- data/app/views/services_mailer/notify_sltc_client_registration_request_invalid.html.erb +10 -0
- data/app/views/services_mailer/notify_sltc_client_registration_validation_errors.html.erb +13 -0
- data/app/views/services_mailer/notify_sltc_provider_changes.html.erb +26 -0
- data/app/views/services_mailer/notify_support_about_no_mds_pull.html.erb +6 -0
- data/config/routes.rb +48 -0
- data/db/migrate/20140102000000_create_services_engine_tables.rb +131 -0
- data/db/migrate/20140517184450_new_services_columns.rb +24 -0
- data/db/migrate/20140525142842_new_configured_provider_table.rb +18 -0
- data/db/migrate/20140714172442_add_error_column_to_hl7_messages.rb +5 -0
- data/db/migrate/20140730164152_mds_upload_tables.rb +78 -0
- data/db/sql_data/service_data_setup.sql +24 -0
- data/lib/services/engine.rb +40 -0
- data/lib/services/version.rb +3 -0
- data/lib/services.rb +4 -0
- data/lib/tasks/services_tasks.rake +40 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +60 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +29 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +35 -0
- data/spec/dummy/config/environments/production.rb +68 -0
- data/spec/dummy/config/environments/test.rb +32 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/email.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +237 -0
- data/spec/dummy/db/sql_data/services_isc_codes.sql +878 -0
- data/spec/dummy/log/test.log +3498 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/models/abaqis_mds_push_spec.rb +120 -0
- data/spec/models/available_file_spec.rb +234 -0
- data/spec/models/configured_account_spec.rb +39 -0
- data/spec/models/ftp_server_spec.rb +221 -0
- data/spec/models/isc_code_lookup_spec.rb +125 -0
- data/spec/models/isc_code_spec.rb +5 -0
- data/spec/models/mds_assessment_spec.rb +1070 -0
- data/spec/models/mds_pull_account_spec.rb +468 -0
- data/spec/models/mds_pull_spec.rb +48 -0
- data/spec/models/mds_push_spec.rb +43 -0
- data/spec/models/mds_ws_response_spec.rb +54 -0
- data/spec/models/pcc_mds_pull_spec.rb +273 -0
- data/spec/models/service_implementation_spec.rb +88 -0
- data/spec/models/sltc_api_exception_spec.rb +136 -0
- data/spec/models/sltc_api_spec.rb +192 -0
- data/spec/models/sltc_mds_pull_spec.rb +776 -0
- data/spec/roles/account_mapping_creator_spec.rb +40 -0
- data/spec/roles/account_mapping_updator_spec.rb +16 -0
- data/spec/roles/configured_account_creator_spec.rb +40 -0
- data/spec/roles/configured_account_updater_spec.rb +16 -0
- data/spec/roles/configured_facility_creator_spec.rb +40 -0
- data/spec/roles/configured_facility_updater_spec.rb +16 -0
- data/spec/roles/credential_creator_spec.rb +23 -0
- data/spec/roles/credential_updater_spec.rb +38 -0
- data/spec/roles/facility_mapping_creator_spec.rb +40 -0
- data/spec/roles/facility_mapping_updater_spec.rb +16 -0
- data/spec/roles/hl7_adt_message_saver_spec.rb +35 -0
- data/spec/roles/hl7_message_trimmer_spec.rb +31 -0
- data/spec/roles/monthly_service_table_cleaner_spec.rb +27 -0
- data/spec/roles/new_registration_notifier_spec.rb +18 -0
- data/spec/roles/service_ceator_spec.rb +34 -0
- data/spec/roles/service_definition_creator_spec.rb +40 -0
- data/spec/roles/service_definition_updater_spec.rb +16 -0
- data/spec/roles/service_invoker_spec.rb +22 -0
- data/spec/roles/service_updater_spec.rb +17 -0
- data/spec/roles/sltc_baseline_requestor_spec.rb +30 -0
- data/spec/roles/sltc_provider_lister_spec.rb +27 -0
- data/spec/roles/sltc_registration_completer_spec.rb +187 -0
- data/spec/roles/sltc_registration_saver_spec.rb +34 -0
- data/spec/roles/third_party_creator_spec.rb +34 -0
- data/spec/roles/third_party_updater_spec.rb +17 -0
- data/spec/spec_helper.rb +72 -0
- metadata +581 -0
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Services::SltcRegistrationCompleter do
|
4
|
+
let(:registration) { Services::SltcRegistration.new.tap { | reg | reg.extend Services::SltcRegistrationCompleter } }
|
5
|
+
|
6
|
+
context 'Public Methods' do
|
7
|
+
context '#complete' do
|
8
|
+
|
9
|
+
it "should complete the registration and request baselines for all the configured facilities" do
|
10
|
+
params = {
|
11
|
+
third_party_id: 12,
|
12
|
+
account_id: 2,
|
13
|
+
service_definition_id: 18
|
14
|
+
}
|
15
|
+
|
16
|
+
m_si = double("ServiceImplementation")
|
17
|
+
|
18
|
+
m_fm = mock_model(Services::FacilityMapping)
|
19
|
+
m_fm.should_receive(:facility_code).and_return('a_221')
|
20
|
+
|
21
|
+
m_facility_mappings = double("FacilityMappings")
|
22
|
+
m_facility_mappings.should_receive(:where).with(facility_id: [ 221 ]).and_return([ m_fm ])
|
23
|
+
|
24
|
+
m_tp = mock_model(Services::ThirdParty)
|
25
|
+
m_tp.should_receive(:facility_mappings).and_return(m_facility_mappings)
|
26
|
+
|
27
|
+
m_sd = mock_model(Services::ServiceDefinition)
|
28
|
+
m_sd.should_receive(:service_implementation).and_return(m_si)
|
29
|
+
m_sd.should_receive(:third_party).and_return(m_tp)
|
30
|
+
|
31
|
+
m_am = mock_model(Services::AccountMapping)
|
32
|
+
|
33
|
+
registration.
|
34
|
+
should_receive(:find_or_create_account_mapping).
|
35
|
+
with(12, 2).
|
36
|
+
and_return(m_am)
|
37
|
+
|
38
|
+
m_ca = mock_model(Services::ConfiguredAccount)
|
39
|
+
m_ca.should_receive(:service_definition).exactly(2).times.and_return(m_sd)
|
40
|
+
|
41
|
+
m_si.should_receive(:identify_providers).with(m_ca)
|
42
|
+
m_si.
|
43
|
+
should_receive(:request_baseline).
|
44
|
+
with(m_ca, 'a_221', anything(), anything())
|
45
|
+
|
46
|
+
m_fac = double("Facility")
|
47
|
+
|
48
|
+
facilities = [ m_fac ]
|
49
|
+
facilities.should_receive(:pluck).and_return([ 221 ])
|
50
|
+
|
51
|
+
m_app_api = double("ApplicationApi")
|
52
|
+
m_app_api.should_receive(:enabled_facilities_for_account_id).with(2).and_return(facilities)
|
53
|
+
|
54
|
+
registration.
|
55
|
+
should_receive(:update_attributes).
|
56
|
+
with(status: Services::SltcRegistration::STATUS_REGISTERED)
|
57
|
+
|
58
|
+
Services::ApplicationApi.should_receive(:api_impl).and_return(m_app_api)
|
59
|
+
|
60
|
+
registration.
|
61
|
+
should_receive(:find_or_create_configured_account).
|
62
|
+
with(18, 2, false).
|
63
|
+
and_return(m_ca)
|
64
|
+
|
65
|
+
registration.complete(params)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'Private Methods' do
|
73
|
+
|
74
|
+
context '#find_or_create_account_mapping' do
|
75
|
+
|
76
|
+
it "should return the found account mapping and not attempt to create one" do
|
77
|
+
|
78
|
+
registration.should_receive(:account_code).and_return('ab_2')
|
79
|
+
|
80
|
+
m_am = mock_model(Services::AccountMapping)
|
81
|
+
|
82
|
+
Services::AccountMapping.
|
83
|
+
should_receive(:where).
|
84
|
+
with(third_party_id: 12, account_id: 2, account_code: 'ab_2').
|
85
|
+
and_return([ m_am ])
|
86
|
+
|
87
|
+
Services::AccountMapping.should_not_receive(:create!)
|
88
|
+
|
89
|
+
expect(registration.send(:find_or_create_account_mapping, 12, 2)).to be(m_am)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should a new account mapping if not found" do
|
93
|
+
|
94
|
+
registration.stub(:account_code).and_return('ab_2')
|
95
|
+
|
96
|
+
m_am = mock_model(Services::AccountMapping)
|
97
|
+
|
98
|
+
Services::AccountMapping.
|
99
|
+
should_receive(:where).
|
100
|
+
with(third_party_id: 12, account_id: 2, account_code: 'ab_2').
|
101
|
+
and_return([ ])
|
102
|
+
|
103
|
+
Services::AccountMapping.
|
104
|
+
should_receive(:create!).
|
105
|
+
with(third_party_id: 12, account_id: 2, account_code: 'ab_2').
|
106
|
+
and_return(m_am)
|
107
|
+
|
108
|
+
expect(registration.send(:find_or_create_account_mapping, 12, 2)).to be(m_am)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
context '#find_or_create_configured_account' do
|
114
|
+
|
115
|
+
it "should update the credentials of a found CA that already had credentials" do
|
116
|
+
registration.stub(:auth_password).and_return('test1234')
|
117
|
+
|
118
|
+
m_cred = mock_model(Services::Credential)
|
119
|
+
m_cred.should_receive(:update_attributes).with(password: 'test1234')
|
120
|
+
|
121
|
+
m_ca = mock_model(Services::ConfiguredAccount)
|
122
|
+
m_ca.should_receive(:credentials).and_return([ m_cred ])
|
123
|
+
m_ca.should_receive(:update_attribute).with(:enabled, true)
|
124
|
+
|
125
|
+
Services::ConfiguredAccount.
|
126
|
+
should_receive(:where).
|
127
|
+
with(service_definition_id: 22, account_id: 2).
|
128
|
+
and_return([ m_ca ])
|
129
|
+
|
130
|
+
expect(registration.send(:find_or_create_configured_account, 22, 2)).to be(m_ca)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should create the credentials of a found CA that does not already have credentials" do
|
134
|
+
registration.stub(:auth_password).and_return('test1234')
|
135
|
+
|
136
|
+
m_cred = mock_model(Services::Credential)
|
137
|
+
|
138
|
+
Services::Credential.should_receive(:new).with(password: 'test1234').and_return(m_cred)
|
139
|
+
|
140
|
+
m_credentials = double("Credentials")
|
141
|
+
m_credentials.should_receive(:first).and_return(nil)
|
142
|
+
m_credentials.should_receive(:<<).with(m_cred)
|
143
|
+
|
144
|
+
m_ca = mock_model(Services::ConfiguredAccount)
|
145
|
+
m_ca.stub(:credentials).and_return(m_credentials)
|
146
|
+
m_ca.should_receive(:update_attribute).with(:enabled, true)
|
147
|
+
|
148
|
+
Services::ConfiguredAccount.
|
149
|
+
should_receive(:where).
|
150
|
+
with(service_definition_id: 22, account_id: 2).
|
151
|
+
and_return([ m_ca ])
|
152
|
+
|
153
|
+
expect(registration.send(:find_or_create_configured_account, 22, 2)).to be(m_ca)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "create a new configured account with credentials if not found" do
|
157
|
+
registration.stub(:auth_password).and_return('test1234')
|
158
|
+
registration.stub(:username).and_return('joe')
|
159
|
+
|
160
|
+
m_cred = mock_model(Services::Credential)
|
161
|
+
|
162
|
+
Services::Credential.should_receive(:new).with(password: 'test1234').and_return(m_cred)
|
163
|
+
|
164
|
+
m_credentials = double("Credentials")
|
165
|
+
m_credentials.should_receive(:<<).with(m_cred)
|
166
|
+
|
167
|
+
m_ca = mock_model(Services::ConfiguredAccount)
|
168
|
+
m_ca.stub(:credentials).and_return(m_credentials)
|
169
|
+
|
170
|
+
Services::ConfiguredAccount.
|
171
|
+
should_receive(:create!).
|
172
|
+
with(service_definition_id: 22, account_id: 2, enabled: true, username: 'joe').
|
173
|
+
and_return(m_ca)
|
174
|
+
|
175
|
+
Services::ConfiguredAccount.
|
176
|
+
should_receive(:where).
|
177
|
+
with(service_definition_id: 22, account_id: 2).
|
178
|
+
and_return([ ])
|
179
|
+
|
180
|
+
expect(registration.send(:find_or_create_configured_account, 22, 2)).to be(m_ca)
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Services::SltcRegistrationSaver do
|
4
|
+
let(:context) { Object.new.tap { | obj | obj.extend Services::SltcRegistrationSaver } }
|
5
|
+
|
6
|
+
context '#create' do
|
7
|
+
|
8
|
+
it "should create the registration and save it if is valid" do
|
9
|
+
params = {}
|
10
|
+
|
11
|
+
m_reg = mock_model(Services::SltcRegistration)
|
12
|
+
m_reg.should_receive(:valid?).and_return(true)
|
13
|
+
m_reg.should_receive(:save)
|
14
|
+
|
15
|
+
Services::SltcRegistration.should_receive(:new).with(params).and_return(m_reg)
|
16
|
+
|
17
|
+
expect(context.save_registration(params)).to be(m_reg)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create the registration but not save it if is invalid" do
|
21
|
+
params = {}
|
22
|
+
|
23
|
+
m_reg = mock_model(Services::SltcRegistration)
|
24
|
+
m_reg.should_receive(:valid?).and_return(false)
|
25
|
+
m_reg.should_not_receive(:save)
|
26
|
+
|
27
|
+
Services::SltcRegistration.should_receive(:new).with(params).and_return(m_reg)
|
28
|
+
|
29
|
+
expect(context.save_registration(params)).to be(m_reg)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Services::ThirdPartyCreator do
|
4
|
+
let(:context) { Object.new.tap { | tp | tp.extend Services::ThirdPartyCreator } }
|
5
|
+
|
6
|
+
context '#create' do
|
7
|
+
|
8
|
+
it "should create the service and save it if is valid" do
|
9
|
+
params = {}
|
10
|
+
|
11
|
+
m_tp = mock_model(Services::ThirdParty)
|
12
|
+
m_tp.should_receive(:valid?).and_return(true)
|
13
|
+
m_tp.should_receive(:save)
|
14
|
+
|
15
|
+
Services::ThirdParty.should_receive(:new).with(params).and_return(m_tp)
|
16
|
+
|
17
|
+
expect(context.create(params)).to be(m_tp)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create the service but not save it if is invalid" do
|
21
|
+
params = {}
|
22
|
+
|
23
|
+
m_tp = mock_model(Services::ThirdParty)
|
24
|
+
m_tp.should_receive(:valid?).and_return(false)
|
25
|
+
m_tp.should_not_receive(:save)
|
26
|
+
|
27
|
+
Services::ThirdParty.should_receive(:new).with(params).and_return(m_tp)
|
28
|
+
|
29
|
+
expect(context.create(params)).to be(m_tp)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Services::ThirdPartyUpdater do
|
4
|
+
let(:third_party) { Services::ThirdParty.new.tap { | svc | svc.extend Services::ThirdPartyUpdater } }
|
5
|
+
|
6
|
+
context '#update' do
|
7
|
+
|
8
|
+
it "should update the attributes of the third_parties from the parameters" do
|
9
|
+
params = { name: 'the third_party' }
|
10
|
+
|
11
|
+
third_party.should_receive(:update_attributes).with(params)
|
12
|
+
|
13
|
+
expect(third_party.update(params)).to be(third_party)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
|
4
|
+
# DS: I'm putting this here because we need to have the compact
|
5
|
+
# method available to get the tests to run. However, the actual
|
6
|
+
# compact method is added to String in the
|
7
|
+
# abaqis2/config/initializers/extensions.rb file.
|
8
|
+
# I don't want to have any conflicts with abaqis, so this
|
9
|
+
# method extension only exists in the tests.
|
10
|
+
#
|
11
|
+
# Let me know if you think there's a better place for this.
|
12
|
+
# I'm all ears.
|
13
|
+
#
|
14
|
+
module ServicesStringFunctions
|
15
|
+
def compact
|
16
|
+
self.gsub(/\s+/, " ").strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class String
|
21
|
+
include ServicesStringFunctions
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'active_support'
|
25
|
+
require 'active_support/core_ext'
|
26
|
+
require 'pry'
|
27
|
+
require 'pry-rescue'
|
28
|
+
require 'pry-byebug'
|
29
|
+
require 'attr_encryption'
|
30
|
+
require 'singleton'
|
31
|
+
require 'libxml'
|
32
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
33
|
+
require 'rspec/rails'
|
34
|
+
require 'rspec/autorun'
|
35
|
+
require 'rest-client'
|
36
|
+
require 'ayl'
|
37
|
+
require 'ayl-beanstalk'
|
38
|
+
require 'net/sftp'
|
39
|
+
require 'mds_file_utils'
|
40
|
+
|
41
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
42
|
+
# in spec/support/ and its subdirectories.
|
43
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
44
|
+
|
45
|
+
RSpec.configure do |config|
|
46
|
+
# ## Mock Framework
|
47
|
+
#
|
48
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
49
|
+
#
|
50
|
+
# config.mock_with :mocha
|
51
|
+
# config.mock_with :flexmock
|
52
|
+
# config.mock_with :rr
|
53
|
+
|
54
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
55
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
56
|
+
|
57
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
58
|
+
# examples within a transaction, remove the following line or assign false
|
59
|
+
# instead of true.
|
60
|
+
config.use_transactional_fixtures = true
|
61
|
+
|
62
|
+
# If true, the base class of anonymous controllers will be inferred
|
63
|
+
# automatically. This will be the default behavior in future versions of
|
64
|
+
# rspec-rails.
|
65
|
+
config.infer_base_class_for_anonymous_controllers = false
|
66
|
+
|
67
|
+
# Run specs in random order to surface order dependencies. If you find an
|
68
|
+
# order dependency and want to debug it, you can fix the order by providing
|
69
|
+
# the seed, which is printed after each run.
|
70
|
+
# --seed 1234
|
71
|
+
config.order = "random"
|
72
|
+
end
|