Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refresh parameter to ResourceActionWorkflow initialization #365

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/api/service_dialogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def refresh_dialog_fields_service_dialog(dialog, data)
refresh_fields = data["fields"]
return action_result(false, "Must specify fields to refresh") if refresh_fields.blank?

service_dialog = define_service_dialog(dialog_fields, data)
service_dialog = define_service_dialog(dialog_fields, data, {:refresh => true})

if service_dialog.id != dialog.id
return action_result(
Expand All @@ -86,10 +86,10 @@ def refresh_dialog_fields_service_dialog(dialog, data)
action_result(false, err.to_s)
end

def define_service_dialog(dialog_fields, data)
def define_service_dialog(dialog_fields, data, options = {})
target, resource_action = validate_dialog_content_params(data, true)

workflow = ResourceActionWorkflow.new({}, User.current_user, resource_action, :target => target)
workflow = ResourceActionWorkflow.new({}, User.current_user, resource_action, {:target => target}.merge(options))

dialog_fields.each { |key, value| workflow.set_value(key, value) }
workflow.dialog
Expand Down
18 changes: 18 additions & 0 deletions spec/requests/service_dialogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,24 @@ def init_dialog
"result" => hash_including("text1")
)
end

it "creates a ResourceActionWorkflow by passing in a true refresh option" do
allow(ResourceActionWorkflow).to receive(:new).and_call_original
expect(ResourceActionWorkflow).to receive(:new).with(
{}, instance_of(User), instance_of(ResourceAction), hash_including(:refresh => true)
)

api_basic_authorize action_identifier(:service_dialogs, :refresh_dialog_fields)
init_dialog

post(api_service_dialog_url(nil, dialog1), :params => gen_request(
:refresh_dialog_fields,
"fields" => %w(text1),
"resource_action_id" => ra1.id,
"target_id" => template.id,
"target_type" => "service_template"
))
end
end

context 'Creates service dialogs' do
Expand Down