Skip to content

Commit

Permalink
Merge pull request #436 from bdunne/symbolize_schedule_data
Browse files Browse the repository at this point in the history
Symbolize schedule data
  • Loading branch information
gtanzillo authored Jul 30, 2018
2 parents 62de390 + a3db9ee commit 73b98a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/subcollections/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def schedules_delete_resource(_parent, type, id, data)

def schedules_edit_resource(_parent, _type, id, data)
# We need to hit #edit_resource from the BaseController, not any of the override methods in child controllers
BaseController.instance_method(:edit_resource).bind(self).call(:schedules, id, data)
BaseController.instance_method(:edit_resource).bind(self).call(:schedules, id, data.deep_symbolize_keys)
rescue => err
raise BadRequestError, "Could not update Schedule - #{err}"
end
Expand Down
19 changes: 15 additions & 4 deletions spec/requests/service_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@
end

describe "POST /api/service_templates/:id/schedules/:id with edit action" do
it "can queue a flavor for deletion" do
it "can edit a single schedule" do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :edit))

post(api_service_template_schedule_url(nil, service_template, schedule_1), :params => gen_request(:edit, "name" => "Updated Schedule Name"))
Expand All @@ -811,7 +811,18 @@
expect(schedule_1.reload.name).to eq("Updated Schedule Name")
end

it "will not delete a schedule unless authorized" do
it "can edit a single schedule run_at" do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :edit))

t = Time.zone.now.utc
post(api_service_template_schedule_url(nil, service_template, schedule_1), :params => gen_request(:edit, "run_at" => {"start_time" => t.to_s, "interval" => {"unit" => "daily", "value" => "12"}}))

schedule_1.reload
expect(schedule_1.run_at[:interval]).to eq(:unit => "daily", :value => "12")
expect(schedule_1.run_at[:start_time]).to be_within(1).of(t)
end

it "will not edit a schedule unless authorized" do
api_basic_authorize

post(api_service_template_schedule_url(nil, service_template, schedule_1), :params => gen_request(:edit, "name" => "Updated Schedule Name"))
Expand All @@ -821,7 +832,7 @@
end

describe "POST /api/service_templates/:id/schedules/ with edit action" do
it "can delete multiple schedules" do
it "can edit multiple schedules" do
api_basic_authorize(subcollection_action_identifier(:service_templates, :schedules, :edit))

post(api_service_template_schedules_url(nil, service_template), :params => gen_request(:edit, [{:id => schedule_1.id, :name => "Schedule1"}, {:id => schedule_2.id, :name => "Schedule2"}]))
Expand All @@ -831,7 +842,7 @@
expect(MiqSchedule.pluck(:name)).to match_array(%w(Schedule1 Schedule2))
end

it "forbids multiple schedule deletion without an appropriate role" do
it "forbids multiple schedule edit without an appropriate role" do
api_basic_authorize

post(api_service_template_schedules_url(nil, service_template), :params => gen_request(:edit, [{:id => schedule_1.id, :name => "Schedule1"}, {:id => schedule_2.id, :name => "Schedule2"}]))
Expand Down

0 comments on commit 73b98a3

Please sign in to comment.