flapjack 1.6.0 → 2.0.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -6
- data/.gitmodules +1 -1
- data/.rspec +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +12 -13
- data/CHANGELOG.md +2 -9
- data/CONTRIBUTING.md +7 -2
- data/Gemfile +4 -13
- data/LICENCE +1 -0
- data/README.md +8 -2
- data/Rakefile +2 -2
- data/bin/flapjack +3 -12
- data/build.sh +4 -2
- data/etc/flapjack_config.toml.example +273 -0
- data/features/ack_after_sched_maint.feature +18 -21
- data/features/cli.feature +11 -71
- data/features/cli_flapjack-feed-events.feature +14 -15
- data/features/cli_flapjack-nagios-receiver.feature +12 -41
- data/features/cli_flapper.feature +12 -41
- data/features/cli_purge.feature +5 -6
- data/features/cli_receive-events.feature +6 -7
- data/features/cli_simulate-failed-check.feature +5 -6
- data/features/events.feature +206 -181
- data/features/events_check_names.feature +4 -7
- data/features/notification_rules.feature +144 -223
- data/features/notifications.feature +65 -57
- data/features/rollup.feature +45 -47
- data/features/steps/cli_steps.rb +4 -5
- data/features/steps/events_steps.rb +163 -373
- data/features/steps/notifications_steps.rb +408 -264
- data/features/steps/packaging-lintian_steps.rb +0 -4
- data/features/steps/time_travel_steps.rb +0 -26
- data/features/support/daemons.rb +6 -31
- data/features/support/env.rb +65 -74
- data/flapjack.gemspec +22 -24
- data/lib/flapjack.rb +14 -7
- data/lib/flapjack/cli/flapper.rb +74 -173
- data/lib/flapjack/cli/maintenance.rb +278 -109
- data/lib/flapjack/cli/migrate.rb +950 -0
- data/lib/flapjack/cli/purge.rb +19 -22
- data/lib/flapjack/cli/receiver.rb +150 -326
- data/lib/flapjack/cli/server.rb +8 -235
- data/lib/flapjack/cli/simulate.rb +42 -57
- data/lib/flapjack/configuration.rb +51 -37
- data/lib/flapjack/coordinator.rb +138 -129
- data/lib/flapjack/data/acknowledgement.rb +177 -0
- data/lib/flapjack/data/alert.rb +97 -158
- data/lib/flapjack/data/check.rb +611 -0
- data/lib/flapjack/data/condition.rb +70 -0
- data/lib/flapjack/data/contact.rb +226 -456
- data/lib/flapjack/data/event.rb +96 -184
- data/lib/flapjack/data/extensions/associations.rb +59 -0
- data/lib/flapjack/data/extensions/short_name.rb +25 -0
- data/lib/flapjack/data/medium.rb +428 -0
- data/lib/flapjack/data/metrics.rb +194 -0
- data/lib/flapjack/data/notification.rb +22 -281
- data/lib/flapjack/data/rule.rb +473 -0
- data/lib/flapjack/data/scheduled_maintenance.rb +244 -0
- data/lib/flapjack/data/state.rb +221 -0
- data/lib/flapjack/data/statistic.rb +112 -0
- data/lib/flapjack/data/tag.rb +277 -0
- data/lib/flapjack/data/test_notification.rb +182 -0
- data/lib/flapjack/data/unscheduled_maintenance.rb +159 -0
- data/lib/flapjack/data/validators/id_validator.rb +20 -0
- data/lib/flapjack/exceptions.rb +6 -0
- data/lib/flapjack/filters/acknowledgement.rb +23 -16
- data/lib/flapjack/filters/base.rb +0 -5
- data/lib/flapjack/filters/delays.rb +53 -43
- data/lib/flapjack/filters/ok.rb +23 -14
- data/lib/flapjack/filters/scheduled_maintenance.rb +3 -3
- data/lib/flapjack/filters/unscheduled_maintenance.rb +12 -3
- data/lib/flapjack/gateways/aws_sns.rb +65 -49
- data/lib/flapjack/gateways/aws_sns/alert.text.erb +2 -2
- data/lib/flapjack/gateways/aws_sns/alert_subject.text.erb +2 -2
- data/lib/flapjack/gateways/aws_sns/rollup_subject.text.erb +1 -1
- data/lib/flapjack/gateways/email.rb +107 -90
- data/lib/flapjack/gateways/email/alert.html.erb +19 -18
- data/lib/flapjack/gateways/email/alert.text.erb +20 -14
- data/lib/flapjack/gateways/email/alert_subject.text.erb +2 -1
- data/lib/flapjack/gateways/email/rollup.html.erb +14 -13
- data/lib/flapjack/gateways/email/rollup.text.erb +13 -10
- data/lib/flapjack/gateways/jabber.rb +679 -671
- data/lib/flapjack/gateways/jabber/alert.text.erb +9 -6
- data/lib/flapjack/gateways/jsonapi.rb +164 -350
- data/lib/flapjack/gateways/jsonapi/data/join_descriptor.rb +44 -0
- data/lib/flapjack/gateways/jsonapi/data/method_descriptor.rb +21 -0
- data/lib/flapjack/gateways/jsonapi/helpers/headers.rb +63 -0
- data/lib/flapjack/gateways/jsonapi/helpers/miscellaneous.rb +136 -0
- data/lib/flapjack/gateways/jsonapi/helpers/resources.rb +227 -0
- data/lib/flapjack/gateways/jsonapi/helpers/serialiser.rb +313 -0
- data/lib/flapjack/gateways/jsonapi/helpers/swagger_docs.rb +322 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_delete.rb +115 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_get.rb +288 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_patch.rb +178 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_post.rb +116 -0
- data/lib/flapjack/gateways/jsonapi/methods/metrics.rb +71 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_delete.rb +119 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_get.rb +186 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_patch.rb +239 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_post.rb +197 -0
- data/lib/flapjack/gateways/jsonapi/middleware/array_param_fixer.rb +27 -0
- data/lib/flapjack/gateways/jsonapi/{rack → middleware}/json_params_parser.rb +7 -6
- data/lib/flapjack/gateways/jsonapi/middleware/request_timestamp.rb +18 -0
- data/lib/flapjack/gateways/oobetet.rb +222 -170
- data/lib/flapjack/gateways/pager_duty.rb +388 -0
- data/lib/flapjack/gateways/pager_duty/alert.text.erb +13 -0
- data/lib/flapjack/gateways/slack.rb +56 -48
- data/lib/flapjack/gateways/slack/alert.text.erb +1 -1
- data/lib/flapjack/gateways/slack/rollup.text.erb +1 -1
- data/lib/flapjack/gateways/sms_aspsms.rb +155 -0
- data/lib/flapjack/gateways/sms_aspsms/alert.text.erb +7 -0
- data/lib/flapjack/gateways/sms_aspsms/rollup.text.erb +2 -0
- data/lib/flapjack/gateways/sms_messagenet.rb +77 -57
- data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +3 -2
- data/lib/flapjack/gateways/sms_nexmo.rb +53 -51
- data/lib/flapjack/gateways/sms_nexmo/alert.text.erb +2 -2
- data/lib/flapjack/gateways/sms_nexmo/rollup.text.erb +1 -1
- data/lib/flapjack/gateways/sms_twilio.rb +79 -62
- data/lib/flapjack/gateways/sms_twilio/alert.text.erb +3 -2
- data/lib/flapjack/gateways/web.rb +437 -345
- data/lib/flapjack/gateways/web/middleware/request_timestamp.rb +18 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.css +3793 -4340
- data/lib/flapjack/gateways/web/public/css/bootstrap.css.map +1 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +273 -214
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/flapjack/gateways/web/public/js/bootstrap.js +1637 -1607
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -2
- data/lib/flapjack/gateways/web/views/_pagination.html.erb +19 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +159 -121
- data/lib/flapjack/gateways/web/views/checks.html.erb +82 -41
- data/lib/flapjack/gateways/web/views/contact.html.erb +59 -71
- data/lib/flapjack/gateways/web/views/contacts.html.erb +32 -8
- data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/{layout.erb → layout.html.erb} +7 -23
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +32 -33
- data/lib/flapjack/gateways/web/views/tag.html.erb +32 -0
- data/lib/flapjack/gateways/web/views/tags.html.erb +51 -0
- data/lib/flapjack/logger.rb +34 -3
- data/lib/flapjack/notifier.rb +180 -112
- data/lib/flapjack/patches.rb +8 -63
- data/lib/flapjack/pikelet.rb +185 -143
- data/lib/flapjack/processor.rb +323 -191
- data/lib/flapjack/record_queue.rb +33 -0
- data/lib/flapjack/redis_proxy.rb +66 -0
- data/lib/flapjack/utility.rb +21 -15
- data/lib/flapjack/version.rb +2 -1
- data/libexec/httpbroker.go +218 -14
- data/libexec/oneoff.go +13 -10
- data/spec/lib/flapjack/configuration_spec.rb +286 -0
- data/spec/lib/flapjack/coordinator_spec.rb +103 -157
- data/spec/lib/flapjack/data/check_spec.rb +175 -0
- data/spec/lib/flapjack/data/contact_spec.rb +26 -349
- data/spec/lib/flapjack/data/event_spec.rb +76 -291
- data/spec/lib/flapjack/data/medium_spec.rb +19 -0
- data/spec/lib/flapjack/data/rule_spec.rb +43 -0
- data/spec/lib/flapjack/data/scheduled_maintenance_spec.rb +976 -0
- data/spec/lib/flapjack/data/unscheduled_maintenance_spec.rb +34 -0
- data/spec/lib/flapjack/gateways/aws_sns_spec.rb +111 -60
- data/spec/lib/flapjack/gateways/email_spec.rb +194 -161
- data/spec/lib/flapjack/gateways/jabber_spec.rb +961 -162
- data/spec/lib/flapjack/gateways/jsonapi/methods/check_links_spec.rb +155 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/checks_spec.rb +426 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/contact_links_spec.rb +217 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/contacts_spec.rb +425 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/events_spec.rb +271 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/media_spec.rb +257 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/medium_links_spec.rb +163 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/metrics_spec.rb +8 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/rule_links_spec.rb +212 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/rules_spec.rb +289 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/scheduled_maintenance_links_spec.rb +49 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/scheduled_maintenances_spec.rb +242 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/tag_links_spec.rb +274 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/tags_spec.rb +302 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/unscheduled_maintenance_links_spec.rb +49 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/unscheduled_maintenances_spec.rb +339 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +151 -79
- data/spec/lib/flapjack/gateways/pager_duty_spec.rb +353 -0
- data/spec/lib/flapjack/gateways/slack_spec.rb +53 -53
- data/spec/lib/flapjack/gateways/sms_aspsms_spec.rb +106 -0
- data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +111 -54
- data/spec/lib/flapjack/gateways/sms_nexmo_spec.rb +50 -51
- data/spec/lib/flapjack/gateways/sms_twilio_spec.rb +108 -48
- data/spec/lib/flapjack/gateways/web_spec.rb +144 -216
- data/spec/lib/flapjack/notifier_spec.rb +132 -1
- data/spec/lib/flapjack/pikelet_spec.rb +111 -50
- data/spec/lib/flapjack/processor_spec.rb +210 -40
- data/spec/lib/flapjack/redis_proxy_spec.rb +45 -0
- data/spec/lib/flapjack/utility_spec.rb +11 -15
- data/spec/service_consumers/fixture_data.rb +547 -0
- data/spec/service_consumers/pact_helper.rb +21 -32
- data/spec/service_consumers/pacts/flapjack-diner_v2.0.json +4652 -0
- data/spec/service_consumers/provider_states_for_flapjack-diner.rb +279 -322
- data/spec/service_consumers/provider_support.rb +8 -0
- data/spec/spec_helper.rb +34 -44
- data/spec/support/erb_view_helper.rb +1 -1
- data/spec/support/factories.rb +58 -0
- data/spec/support/jsonapi_helper.rb +15 -26
- data/spec/support/mock_logger.rb +43 -0
- data/spec/support/xmpp_comparable.rb +24 -0
- data/src/flapjack/transport_test.go +30 -1
- data/tasks/dump_keys.rake +82 -0
- data/tasks/events.rake +7 -7
- data/tasks/support/flapjack_config_benchmark.toml +28 -0
- data/tasks/support/flapjack_config_benchmark.yaml +0 -2
- metadata +175 -222
- data/Guardfile +0 -14
- data/etc/flapjack_config.yaml.example +0 -477
- data/features/cli_flapjack-populator.feature +0 -90
- data/features/support/silent_system.rb +0 -4
- data/lib/flapjack/cli/import.rb +0 -108
- data/lib/flapjack/data/entity.rb +0 -652
- data/lib/flapjack/data/entity_check.rb +0 -1044
- data/lib/flapjack/data/message.rb +0 -56
- data/lib/flapjack/data/migration.rb +0 -234
- data/lib/flapjack/data/notification_rule.rb +0 -425
- data/lib/flapjack/data/semaphore.rb +0 -44
- data/lib/flapjack/data/tagged.rb +0 -48
- data/lib/flapjack/gateways/jsonapi/check_methods.rb +0 -206
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +0 -221
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +0 -186
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +0 -223
- data/lib/flapjack/gateways/jsonapi/medium_methods.rb +0 -185
- data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +0 -132
- data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +0 -141
- data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +0 -139
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +0 -146
- data/lib/flapjack/gateways/pagerduty.rb +0 -318
- data/lib/flapjack/gateways/pagerduty/alert.text.erb +0 -10
- data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +0 -87
- data/lib/flapjack/gateways/web/public/css/select2.css +0 -615
- data/lib/flapjack/gateways/web/public/css/tablesort.css +0 -67
- data/lib/flapjack/gateways/web/public/img/select2-spinner.gif +0 -0
- data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
- data/lib/flapjack/gateways/web/public/js/backbone.js +0 -1581
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +0 -322
- data/lib/flapjack/gateways/web/public/js/flapjack.js +0 -82
- data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.js +0 -1640
- data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.widgets.js +0 -1390
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +0 -520
- data/lib/flapjack/gateways/web/public/js/modules/entity.js +0 -28
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +0 -40
- data/lib/flapjack/gateways/web/public/js/select2.js +0 -3397
- data/lib/flapjack/gateways/web/public/js/tablesort.js +0 -44
- data/lib/flapjack/gateways/web/public/js/underscore.js +0 -1276
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +0 -173
- data/lib/flapjack/gateways/web/views/entities.html.erb +0 -30
- data/lib/flapjack/gateways/web/views/entity.html.erb +0 -51
- data/lib/flapjack/rack_logger.rb +0 -47
- data/lib/flapjack/redis_pool.rb +0 -42
- data/spec/lib/flapjack/data/entity_check_spec.rb +0 -1418
- data/spec/lib/flapjack/data/entity_spec.rb +0 -872
- data/spec/lib/flapjack/data/message_spec.rb +0 -30
- data/spec/lib/flapjack/data/migration_spec.rb +0 -104
- data/spec/lib/flapjack/data/notification_rule_spec.rb +0 -232
- data/spec/lib/flapjack/data/notification_spec.rb +0 -53
- data/spec/lib/flapjack/data/semaphore_spec.rb +0 -24
- data/spec/lib/flapjack/filters/acknowledgement_spec.rb +0 -6
- data/spec/lib/flapjack/filters/delays_spec.rb +0 -6
- data/spec/lib/flapjack/filters/ok_spec.rb +0 -6
- data/spec/lib/flapjack/filters/scheduled_maintenance_spec.rb +0 -6
- data/spec/lib/flapjack/filters/unscheduled_maintenance_spec.rb +0 -6
- data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +0 -315
- data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +0 -223
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +0 -131
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +0 -389
- data/spec/lib/flapjack/gateways/jsonapi/medium_methods_spec.rb +0 -231
- data/spec/lib/flapjack/gateways/jsonapi/notification_rule_methods_spec.rb +0 -169
- data/spec/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods_spec.rb +0 -114
- data/spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb +0 -590
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +0 -249
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +0 -21
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +0 -24
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +0 -16
- data/spec/lib/flapjack/redis_pool_spec.rb +0 -29
- data/spec/service_consumers/pacts/flapjack-diner_v1.0.json +0 -4702
- data/tasks/entities.rake +0 -151
- data/tasks/profile.rake +0 -282
- data/tmp/acknowledge.rb +0 -13
- data/tmp/create_config_yaml.rb +0 -16
- data/tmp/create_event_ok.rb +0 -30
- data/tmp/create_event_unknown.rb +0 -30
- data/tmp/create_events_failure.rb +0 -34
- data/tmp/create_events_ok.rb +0 -32
- data/tmp/create_events_ok_fail_ack_ok.rb +0 -53
- data/tmp/create_events_ok_failure.rb +0 -41
- data/tmp/create_events_ok_failure_ack.rb +0 -53
- data/tmp/dummy_contacts.json +0 -43
- data/tmp/dummy_entities.json +0 -37
- data/tmp/generate_nagios_test_hosts.rb +0 -16
- data/tmp/notification_rules.rb +0 -73
- data/tmp/parse_config_yaml.rb +0 -7
- data/tmp/redis_find_spurious_unknown_states.rb +0 -52
- data/tmp/test_json_post.rb +0 -19
- data/tmp/test_notification_rules_api.rb +0 -171
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack/gateways/jsonapi'
|
3
|
+
|
4
|
+
describe 'Flapjack::Gateways::JSONAPI::Methods::ScheduledMaintenanceLinks', :sinatra => true, :logger => true, :pact_fixture => true do
|
5
|
+
|
6
|
+
include_context "jsonapi"
|
7
|
+
|
8
|
+
let(:scheduled_maintenance) { double(Flapjack::Data::ScheduledMaintenance,
|
9
|
+
:id => scheduled_maintenance_data[:id]) }
|
10
|
+
let(:check) { double(Flapjack::Data::Check, :id => check_data[:id]) }
|
11
|
+
|
12
|
+
it 'shows the check for a scheduled maintenance period' do
|
13
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).with(Flapjack::Data::Check).and_yield
|
14
|
+
|
15
|
+
expect(scheduled_maintenance).to receive(:check).and_return(check)
|
16
|
+
|
17
|
+
scheduled_maintenances = double('scheduled_maintenances', :all => [scheduled_maintenance])
|
18
|
+
expect(scheduled_maintenances).to receive(:empty?).and_return(false)
|
19
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:intersect).
|
20
|
+
with(:id => scheduled_maintenance.id).and_return(scheduled_maintenances)
|
21
|
+
|
22
|
+
get "/scheduled_maintenances/#{scheduled_maintenance.id}/check"
|
23
|
+
expect(last_response.status).to eq(200)
|
24
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
25
|
+
:data => {:type => 'check', :id => check.id},
|
26
|
+
:links => {
|
27
|
+
:self => "http://example.org/scheduled_maintenances/#{scheduled_maintenance.id}/relationships/check",
|
28
|
+
:related => "http://example.org/scheduled_maintenances/#{scheduled_maintenance.id}/check",
|
29
|
+
}
|
30
|
+
))
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'cannot change the check for a scheduled maintenance period' do
|
34
|
+
patch "/scheduled_maintenances/#{scheduled_maintenance.id}/relationships/check",
|
35
|
+
Flapjack.dump_json(:data => {
|
36
|
+
:type => 'check', :id => check.id
|
37
|
+
}), jsonapi_env
|
38
|
+
expect(last_response.status).to eq(404)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'cannot clear the check for a scheduled maintenance period' do
|
42
|
+
patch "/scheduled_maintenances/#{scheduled_maintenance.id}/relationships/check",
|
43
|
+
Flapjack.dump_json(:data => {
|
44
|
+
:type => 'check', :id => nil
|
45
|
+
}), jsonapi_env
|
46
|
+
expect(last_response.status).to eq(404)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack/gateways/jsonapi'
|
3
|
+
|
4
|
+
describe 'Flapjack::Gateways::JSONAPI::Methods::ScheduledMaintenances', :sinatra => true, :logger => true, :pact_fixture => true do
|
5
|
+
|
6
|
+
include_context "jsonapi"
|
7
|
+
|
8
|
+
let(:scheduled_maintenance) { double(Flapjack::Data::ScheduledMaintenance, :id => scheduled_maintenance_data[:id]) }
|
9
|
+
let(:scheduled_maintenance_2) { double(Flapjack::Data::ScheduledMaintenance,
|
10
|
+
:id => scheduled_maintenance_2_data[:id]) }
|
11
|
+
|
12
|
+
let(:check) { double(Flapjack::Data::Check, :id => check_data[:id]) }
|
13
|
+
|
14
|
+
it "creates a scheduled maintenance period" do
|
15
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
16
|
+
with(no_args).
|
17
|
+
and_yield
|
18
|
+
|
19
|
+
empty_ids = double('empty_ids')
|
20
|
+
expect(empty_ids).to receive(:ids).and_return([])
|
21
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:intersect).
|
22
|
+
with(:id => [scheduled_maintenance_data[:id]]).
|
23
|
+
and_return(empty_ids)
|
24
|
+
|
25
|
+
smd = scheduled_maintenance_data.dup
|
26
|
+
[:start_time, :end_time].each {|t| smd[t] = Time.parse(smd[t]) }
|
27
|
+
|
28
|
+
expect(scheduled_maintenance).to receive(:invalid?).and_return(false)
|
29
|
+
expect(scheduled_maintenance).to receive(:save!).and_return(true)
|
30
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:new).with(smd).
|
31
|
+
and_return(scheduled_maintenance)
|
32
|
+
|
33
|
+
expect(scheduled_maintenance).to receive(:as_json).
|
34
|
+
with(:only => an_instance_of(Array)).
|
35
|
+
and_return(scheduled_maintenance_data.reject {|k,v| :id.eql?(k)})
|
36
|
+
|
37
|
+
req_data = maintenance_json('scheduled', scheduled_maintenance_data)
|
38
|
+
resp_data = req_data.merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_data))
|
39
|
+
|
40
|
+
post "/scheduled_maintenances", Flapjack.dump_json(:data => req_data), jsonapi_env
|
41
|
+
expect(last_response.status).to eq(201)
|
42
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(:data =>
|
43
|
+
resp_data))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "doesn't create a scheduled maintenance period if the start time isn't passed" do
|
47
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
48
|
+
with(no_args).
|
49
|
+
and_yield
|
50
|
+
|
51
|
+
empty_ids = double('empty_ids')
|
52
|
+
expect(empty_ids).to receive(:ids).and_return([])
|
53
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:intersect).
|
54
|
+
with(:id => [scheduled_maintenance_data[:id]]).and_return(empty_ids)
|
55
|
+
|
56
|
+
errors = double('errors', :full_messages => ['err'])
|
57
|
+
expect(scheduled_maintenance).to receive(:errors).and_return(errors)
|
58
|
+
|
59
|
+
req_data = maintenance_json('scheduled', scheduled_maintenance_data)
|
60
|
+
|
61
|
+
smd = scheduled_maintenance_data.dup
|
62
|
+
[:start_time, :end_time].each {|t| smd[t] = Time.parse(smd[t]) }
|
63
|
+
|
64
|
+
expect(scheduled_maintenance).to receive(:invalid?).and_return(true)
|
65
|
+
expect(scheduled_maintenance).not_to receive(:save!)
|
66
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:new).with(smd).
|
67
|
+
and_return(scheduled_maintenance)
|
68
|
+
|
69
|
+
post "/scheduled_maintenances", Flapjack.dump_json(:data => req_data),
|
70
|
+
jsonapi_env
|
71
|
+
expect(last_response.status).to eq(403)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns a single scheduled maintenance period' do
|
75
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
76
|
+
with(no_args).
|
77
|
+
and_yield
|
78
|
+
|
79
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:intersect).
|
80
|
+
with(:id => Set.new([scheduled_maintenance.id])).and_return([scheduled_maintenance])
|
81
|
+
|
82
|
+
expect(scheduled_maintenance).to receive(:as_json).with(:only => an_instance_of(Array)).
|
83
|
+
and_return(scheduled_maintenance_data.reject {|k,v| :id.eql?(k)})
|
84
|
+
|
85
|
+
resp_data = maintenance_json('scheduled', scheduled_maintenance_data).
|
86
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_data))
|
87
|
+
|
88
|
+
get "/scheduled_maintenances/#{scheduled_maintenance.id}"
|
89
|
+
expect(last_response).to be_ok
|
90
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
91
|
+
:data => resp_data,
|
92
|
+
:links => {:self => "http://example.org/scheduled_maintenances/#{scheduled_maintenance.id}"})
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns multiple scheduled_maintenance periods' do
|
97
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
98
|
+
with(no_args).
|
99
|
+
and_yield
|
100
|
+
|
101
|
+
meta = {
|
102
|
+
:pagination => {
|
103
|
+
:page => 1,
|
104
|
+
:per_page => 20,
|
105
|
+
:total_pages => 1,
|
106
|
+
:total_count => 2
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
links = {
|
111
|
+
:self => "http://example.org/scheduled_maintenances?filter%5B%5D=id%3A#{scheduled_maintenance.id}%7C#{scheduled_maintenance_2.id}",
|
112
|
+
:first => "http://example.org/scheduled_maintenances?filter%5B%5D=id%3A#{scheduled_maintenance.id}%7C#{scheduled_maintenance_2.id}&page=1",
|
113
|
+
:last => "http://example.org/scheduled_maintenances?filter%5B%5D=id%3A#{scheduled_maintenance.id}%7C#{scheduled_maintenance_2.id}&page=1"
|
114
|
+
}
|
115
|
+
|
116
|
+
page = double('page')
|
117
|
+
expect(page).to receive(:empty?).and_return(false)
|
118
|
+
expect(page).to receive(:ids).and_return([scheduled_maintenance.id, scheduled_maintenance_2.id])
|
119
|
+
expect(page).to receive(:collect) {|&arg| [arg.call(scheduled_maintenance), arg.call(scheduled_maintenance_2)] }
|
120
|
+
|
121
|
+
sorted = double('sorted')
|
122
|
+
expect(sorted).to receive(:page).with(1, :per_page => 20).and_return(page)
|
123
|
+
expect(sorted).to receive(:count).and_return(2)
|
124
|
+
|
125
|
+
filtered = double('filtered')
|
126
|
+
expect(filtered).to receive(:sort).with(:id).and_return(sorted)
|
127
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:intersect).with(:id => [scheduled_maintenance.id, scheduled_maintenance_2.id]).
|
128
|
+
and_return(filtered)
|
129
|
+
|
130
|
+
expect(scheduled_maintenance).to receive(:as_json).with(:only => an_instance_of(Array)).
|
131
|
+
and_return(scheduled_maintenance_data.reject {|k,v| :id.eql?(k)})
|
132
|
+
|
133
|
+
expect(scheduled_maintenance_2).to receive(:as_json).with(:only => an_instance_of(Array)).
|
134
|
+
and_return(scheduled_maintenance_2_data.reject {|k,v| :id.eql?(k)})
|
135
|
+
|
136
|
+
resp_data = [
|
137
|
+
maintenance_json('scheduled', scheduled_maintenance_data).
|
138
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_data)),
|
139
|
+
maintenance_json('scheduled', scheduled_maintenance_2_data).
|
140
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_2_data))
|
141
|
+
]
|
142
|
+
|
143
|
+
get "/scheduled_maintenances?filter=id%3A#{scheduled_maintenance.id}%7C#{scheduled_maintenance_2.id}"
|
144
|
+
expect(last_response).to be_ok
|
145
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
146
|
+
:data => resp_data,
|
147
|
+
:links => links, :meta => meta))
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'returns paginated scheduled maintenance periods' do
|
151
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
152
|
+
with(no_args).
|
153
|
+
and_yield
|
154
|
+
|
155
|
+
meta = {
|
156
|
+
:pagination => {
|
157
|
+
:page => 1,
|
158
|
+
:per_page => 20,
|
159
|
+
:total_pages => 1,
|
160
|
+
:total_count => 1
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
links = {
|
165
|
+
:self => 'http://example.org/scheduled_maintenances',
|
166
|
+
:first => 'http://example.org/scheduled_maintenances?page=1',
|
167
|
+
:last => 'http://example.org/scheduled_maintenances?page=1'
|
168
|
+
}
|
169
|
+
|
170
|
+
page = double('page')
|
171
|
+
expect(page).to receive(:empty?).and_return(false)
|
172
|
+
expect(page).to receive(:ids).and_return([scheduled_maintenance.id])
|
173
|
+
expect(page).to receive(:collect) {|&arg| [arg.call(scheduled_maintenance)] }
|
174
|
+
sorted = double('sorted')
|
175
|
+
expect(sorted).to receive(:page).with(1, :per_page => 20).
|
176
|
+
and_return(page)
|
177
|
+
expect(sorted).to receive(:count).and_return(1)
|
178
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:sort).
|
179
|
+
with(:id).and_return(sorted)
|
180
|
+
|
181
|
+
expect(scheduled_maintenance).to receive(:as_json).with(:only => an_instance_of(Array)).
|
182
|
+
and_return(scheduled_maintenance_data.reject {|k,v| :id.eql?(k)})
|
183
|
+
|
184
|
+
resp_data = [maintenance_json('scheduled', scheduled_maintenance_data).
|
185
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_data))]
|
186
|
+
|
187
|
+
get '/scheduled_maintenances'
|
188
|
+
expect(last_response).to be_ok
|
189
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
190
|
+
:data => resp_data, :links => links, :meta => meta))
|
191
|
+
end
|
192
|
+
|
193
|
+
it "deletes a scheduled maintenance period" do
|
194
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
195
|
+
with(Flapjack::Data::Check,
|
196
|
+
Flapjack::Data::Tag).
|
197
|
+
and_yield
|
198
|
+
|
199
|
+
expect(scheduled_maintenance).to receive(:destroy)
|
200
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:find_by_id!).
|
201
|
+
with(scheduled_maintenance.id).and_return(scheduled_maintenance)
|
202
|
+
|
203
|
+
delete "/scheduled_maintenances/#{scheduled_maintenance.id}"
|
204
|
+
expect(last_response.status).to eq(204)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "deletes multiple scheduled maintenance periods" do
|
208
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
209
|
+
with(Flapjack::Data::Check,
|
210
|
+
Flapjack::Data::Tag).
|
211
|
+
and_yield
|
212
|
+
|
213
|
+
scheduled_maintenances = double('scheduled_maintenances')
|
214
|
+
expect(scheduled_maintenances).to receive(:count).and_return(2)
|
215
|
+
expect(scheduled_maintenances).to receive(:destroy_all)
|
216
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:intersect).
|
217
|
+
with(:id => [scheduled_maintenance.id, scheduled_maintenance_2.id]).
|
218
|
+
and_return(scheduled_maintenances)
|
219
|
+
|
220
|
+
delete "/scheduled_maintenances",
|
221
|
+
Flapjack.dump_json(:data => [
|
222
|
+
{:id => scheduled_maintenance.id, :type => 'scheduled_maintenance'},
|
223
|
+
{:id => scheduled_maintenance_2.id, :type => 'scheduled_maintenance'}
|
224
|
+
]),
|
225
|
+
jsonapi_bulk_env
|
226
|
+
expect(last_response.status).to eq(204)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "does not delete a scheduled maintenance period that's not found" do
|
230
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:lock).
|
231
|
+
with(Flapjack::Data::Check,
|
232
|
+
Flapjack::Data::Tag).
|
233
|
+
and_yield
|
234
|
+
|
235
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:find_by_id!).
|
236
|
+
with(scheduled_maintenance.id).and_raise(Zermelo::Records::Errors::RecordNotFound.new(Flapjack::Data::ScheduledMaintenance, scheduled_maintenance.id))
|
237
|
+
|
238
|
+
delete "/scheduled_maintenances/#{scheduled_maintenance.id}"
|
239
|
+
expect(last_response).to be_not_found
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack/gateways/jsonapi'
|
3
|
+
|
4
|
+
describe 'Flapjack::Gateways::JSONAPI::Methods::TagLinks', :sinatra => true, :logger => true, :pact_fixture => true do
|
5
|
+
|
6
|
+
include_context "jsonapi"
|
7
|
+
|
8
|
+
let(:tag) { double(Flapjack::Data::Tag, :id => tag_data[:id]) }
|
9
|
+
let(:check) { double(Flapjack::Data::Check, :id => check_data[:id]) }
|
10
|
+
let(:contact) { double(Flapjack::Data::Contact, :id => contact_data[:id]) }
|
11
|
+
let(:rule) { double(Flapjack::Data::Rule, :id => rule_data[:id]) }
|
12
|
+
|
13
|
+
let(:tag_checks) { double('tag_checks') }
|
14
|
+
let(:tag_contacts) { double('tag_contacts') }
|
15
|
+
let(:tag_rules) { double('tag_rules') }
|
16
|
+
|
17
|
+
let(:meta) {
|
18
|
+
{
|
19
|
+
:pagination => {
|
20
|
+
:page => 1,
|
21
|
+
:per_page => 20,
|
22
|
+
:total_pages => 1,
|
23
|
+
:total_count => 1
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
it 'adds a check to a tag' do
|
29
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
30
|
+
with(Flapjack::Data::Check).
|
31
|
+
and_yield
|
32
|
+
|
33
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
34
|
+
and_return(tag)
|
35
|
+
|
36
|
+
expect(tag_checks).to receive(:add_ids).with(check.id)
|
37
|
+
expect(tag).to receive(:checks).and_return(tag_checks)
|
38
|
+
|
39
|
+
post "/tags/#{tag.id}/relationships/checks", Flapjack.dump_json(:data => [{
|
40
|
+
:type => 'check', :id => check.id
|
41
|
+
}]), jsonapi_env
|
42
|
+
expect(last_response.status).to eq(204)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'lists checks for a tag' do
|
46
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
47
|
+
with(Flapjack::Data::Check).
|
48
|
+
and_yield
|
49
|
+
|
50
|
+
sorted = double('sorted')
|
51
|
+
paged = double('paged')
|
52
|
+
expect(paged).to receive(:ids).and_return([check.id])
|
53
|
+
expect(sorted).to receive(:page).with(1, :per_page => 20).and_return(paged)
|
54
|
+
expect(sorted).to receive(:count).and_return(1)
|
55
|
+
expect(tag_checks).to receive(:sort).with(:id => :asc).and_return(sorted)
|
56
|
+
expect(tag).to receive(:checks).and_return(tag_checks)
|
57
|
+
|
58
|
+
tags = double('tags', :all => [tag])
|
59
|
+
expect(tags).to receive(:empty?).and_return(false)
|
60
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
61
|
+
with(:id => tag.id).and_return(tags)
|
62
|
+
|
63
|
+
get "/tags/#{tag.id}/checks"
|
64
|
+
expect(last_response.status).to eq(200)
|
65
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
66
|
+
:data => [{:type => 'check', :id => check.id}],
|
67
|
+
:links => {
|
68
|
+
:self => "http://example.org/tags/#{tag.id}/relationships/checks",
|
69
|
+
:related => "http://example.org/tags/#{tag.id}/checks",
|
70
|
+
},
|
71
|
+
:meta => meta
|
72
|
+
))
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'updates checks for a tag' do
|
76
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
77
|
+
with(Flapjack::Data::Check).
|
78
|
+
and_yield
|
79
|
+
|
80
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
81
|
+
and_return(tag)
|
82
|
+
|
83
|
+
expect(tag_checks).to receive(:ids).and_return([])
|
84
|
+
expect(tag_checks).to receive(:add_ids).with(check.id)
|
85
|
+
expect(tag).to receive(:checks).twice.and_return(tag_checks)
|
86
|
+
|
87
|
+
patch "/tags/#{tag.id}/relationships/checks", Flapjack.dump_json(:data => [{
|
88
|
+
:type => 'check', :id => check.id
|
89
|
+
}]), jsonapi_env
|
90
|
+
expect(last_response.status).to eq(204)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'deletes a check from a tag' do
|
94
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
95
|
+
with(Flapjack::Data::Check).
|
96
|
+
and_yield
|
97
|
+
|
98
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
99
|
+
and_return(tag)
|
100
|
+
|
101
|
+
expect(tag_checks).to receive(:remove_ids).with(check.id)
|
102
|
+
expect(tag).to receive(:checks).and_return(tag_checks)
|
103
|
+
|
104
|
+
delete "/tags/#{tag.id}/relationships/checks", Flapjack.dump_json(:data => [{
|
105
|
+
:type => 'check', :id => check.id
|
106
|
+
}]), jsonapi_env
|
107
|
+
expect(last_response.status).to eq(204)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'adds a contact to a tag' do
|
111
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
112
|
+
with(Flapjack::Data::Contact).
|
113
|
+
and_yield
|
114
|
+
|
115
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
116
|
+
and_return(tag)
|
117
|
+
|
118
|
+
expect(tag_contacts).to receive(:add_ids).with(contact.id)
|
119
|
+
expect(tag).to receive(:contacts).and_return(tag_contacts)
|
120
|
+
|
121
|
+
post "/tags/#{tag.id}/relationships/contacts", Flapjack.dump_json(:data => [{
|
122
|
+
:type => 'contact', :id => contact.id
|
123
|
+
}]), jsonapi_env
|
124
|
+
expect(last_response.status).to eq(204)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'lists contacts for a tag' do
|
128
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
129
|
+
with(Flapjack::Data::Contact).
|
130
|
+
and_yield
|
131
|
+
|
132
|
+
sorted = double('sorted')
|
133
|
+
paged = double('paged')
|
134
|
+
expect(paged).to receive(:ids).and_return([contact.id])
|
135
|
+
expect(sorted).to receive(:page).with(1, :per_page => 20).and_return(paged)
|
136
|
+
expect(sorted).to receive(:count).and_return(1)
|
137
|
+
expect(tag_contacts).to receive(:sort).with(:id => :asc).and_return(sorted)
|
138
|
+
expect(tag).to receive(:contacts).and_return(tag_contacts)
|
139
|
+
|
140
|
+
tags = double('tags', :all => [tag])
|
141
|
+
expect(tags).to receive(:empty?).and_return(false)
|
142
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
143
|
+
with(:id => tag.id).and_return(tags)
|
144
|
+
|
145
|
+
get "/tags/#{tag.id}/contacts"
|
146
|
+
expect(last_response.status).to eq(200)
|
147
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
148
|
+
:data => [{:type => 'contact', :id => contact.id}],
|
149
|
+
:links => {
|
150
|
+
:self => "http://example.org/tags/#{tag.id}/relationships/contacts",
|
151
|
+
:related => "http://example.org/tags/#{tag.id}/contacts",
|
152
|
+
},
|
153
|
+
:meta => meta
|
154
|
+
))
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'updates contacts for a tag' do
|
158
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
159
|
+
with(Flapjack::Data::Contact).
|
160
|
+
and_yield
|
161
|
+
|
162
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
163
|
+
and_return(tag)
|
164
|
+
|
165
|
+
expect(tag_contacts).to receive(:ids).and_return([])
|
166
|
+
expect(tag_contacts).to receive(:add_ids).with(contact.id)
|
167
|
+
expect(tag).to receive(:contacts).twice.and_return(tag_contacts)
|
168
|
+
|
169
|
+
patch "/tags/#{tag.id}/relationships/contacts", Flapjack.dump_json(:data => [{
|
170
|
+
:type => 'contact', :id => contact.id
|
171
|
+
}]), jsonapi_env
|
172
|
+
expect(last_response.status).to eq(204)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'deletes a contact from a tag' do
|
176
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
177
|
+
with(Flapjack::Data::Contact).
|
178
|
+
and_yield
|
179
|
+
|
180
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
181
|
+
and_return(tag)
|
182
|
+
|
183
|
+
expect(tag_contacts).to receive(:remove_ids).with(contact.id)
|
184
|
+
expect(tag).to receive(:contacts).and_return(tag_contacts)
|
185
|
+
|
186
|
+
delete "/tags/#{tag.id}/relationships/contacts", Flapjack.dump_json(:data => [{
|
187
|
+
:type => 'contact', :id => contact.id
|
188
|
+
}]), jsonapi_env
|
189
|
+
expect(last_response.status).to eq(204)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'adds a rule to a tag' do
|
193
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
194
|
+
with(Flapjack::Data::Rule).
|
195
|
+
and_yield
|
196
|
+
|
197
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
198
|
+
and_return(tag)
|
199
|
+
|
200
|
+
expect(tag_rules).to receive(:add_ids).with(rule.id)
|
201
|
+
expect(tag).to receive(:rules).and_return(tag_rules)
|
202
|
+
|
203
|
+
post "/tags/#{tag.id}/relationships/rules", Flapjack.dump_json(:data => [{
|
204
|
+
:type => 'rule', :id => rule.id
|
205
|
+
}]), jsonapi_env
|
206
|
+
expect(last_response.status).to eq(204)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'lists rules for a tag' do
|
210
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
211
|
+
with(Flapjack::Data::Rule).
|
212
|
+
and_yield
|
213
|
+
|
214
|
+
sorted = double('sorted')
|
215
|
+
paged = double('paged')
|
216
|
+
expect(paged).to receive(:ids).and_return([rule.id])
|
217
|
+
expect(sorted).to receive(:page).with(1, :per_page => 20).and_return(paged)
|
218
|
+
expect(sorted).to receive(:count).and_return(1)
|
219
|
+
expect(tag_rules).to receive(:sort).with(:id => :asc).and_return(sorted)
|
220
|
+
expect(tag).to receive(:rules).and_return(tag_rules)
|
221
|
+
|
222
|
+
tags = double('tags', :all => [tag])
|
223
|
+
expect(tags).to receive(:empty?).and_return(false)
|
224
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
225
|
+
with(:id => tag.id).and_return(tags)
|
226
|
+
|
227
|
+
get "/tags/#{tag.id}/rules"
|
228
|
+
expect(last_response.status).to eq(200)
|
229
|
+
expect(last_response.body).to be_json_eql(Flapjack.dump_json(
|
230
|
+
:data => [{:type => 'rule', :id => rule.id}],
|
231
|
+
:links => {
|
232
|
+
:self => "http://example.org/tags/#{tag.id}/relationships/rules",
|
233
|
+
:related => "http://example.org/tags/#{tag.id}/rules",
|
234
|
+
},
|
235
|
+
:meta => meta
|
236
|
+
))
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'updates rules for a tag' do
|
240
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
241
|
+
with(Flapjack::Data::Rule).
|
242
|
+
and_yield
|
243
|
+
|
244
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
245
|
+
and_return(tag)
|
246
|
+
|
247
|
+
expect(tag_rules).to receive(:ids).and_return([])
|
248
|
+
expect(tag_rules).to receive(:add_ids).with(rule.id)
|
249
|
+
expect(tag).to receive(:rules).twice.and_return(tag_rules)
|
250
|
+
|
251
|
+
patch "/tags/#{tag.id}/relationships/rules", Flapjack.dump_json(:data => [{
|
252
|
+
:type => 'rule', :id => rule.id
|
253
|
+
}]), jsonapi_env
|
254
|
+
expect(last_response.status).to eq(204)
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'deletes a rule from a tag' do
|
258
|
+
expect(Flapjack::Data::Tag).to receive(:lock).
|
259
|
+
with(Flapjack::Data::Rule).
|
260
|
+
and_yield
|
261
|
+
|
262
|
+
expect(Flapjack::Data::Tag).to receive(:find_by_id!).with(tag.id).
|
263
|
+
and_return(tag)
|
264
|
+
|
265
|
+
expect(tag_rules).to receive(:remove_ids).with(rule.id)
|
266
|
+
expect(tag).to receive(:rules).and_return(tag_rules)
|
267
|
+
|
268
|
+
delete "/tags/#{tag.id}/relationships/rules", Flapjack.dump_json(:data => [{
|
269
|
+
:type => 'rule', :id => rule.id
|
270
|
+
}]), jsonapi_env
|
271
|
+
expect(last_response.status).to eq(204)
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|