Skip to content

Commit

Permalink
Merge pull request #206 from AparnaKarve/add_deep_symbolizations_to_c…
Browse files Browse the repository at this point in the history
…b_visibility

Add deep symbolization to CustomButton `visibility` field
(cherry picked from commit 85c9383)
  • Loading branch information
abellotti authored and simaishi committed Nov 14, 2017
1 parent 2450b78 commit d03bc5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/custom_buttons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def create_resource(_type, _id, data)
custom_button = CustomButton.new(data.except("resource_action", "options"))
custom_button.userid = User.current_user.userid
custom_button.options = data["options"].deep_symbolize_keys if data["options"]
custom_button.visibility = data["visibility"].deep_symbolize_keys if data["visibility"]
custom_button.resource_action = find_or_create_resource_action(data["resource_action"]) if data.key?("resource_action")
if custom_button.save
custom_button
Expand Down
9 changes: 6 additions & 3 deletions spec/requests/custom_buttons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@
'resource_action' => {
'ae_namespace' => 'SYSTEM',
'ae_class' => 'PROCESS'
}
},
'visibility' => {'roles' => ['_ALL_']}
}
post(api_custom_buttons_url, :params => cb_rec)

expect(response).to have_http_status(:ok)
custom_button = CustomButton.find(response.parsed_body['results'].first["id"])
expect(custom_button.options[:button_icon]).to eq("ff ff-view-expanded")
expect(custom_button.visibility[:roles]).to eq(['_ALL_'])
expect(response.parsed_body['results'].first).to include(cb_rec.except('resource_action'))
end

Expand All @@ -85,18 +87,19 @@
request = {
'action' => 'edit',
'resources' => [
{ 'id' => cb.id.to_s, 'resource' => {'name' => 'updated 1', 'resource_action' => {'ae_namespace' => 'SYSTEM2'}}},
{ 'id' => cb.id.to_s, 'resource' => {'name' => 'updated 1', 'resource_action' => {'ae_namespace' => 'SYSTEM2'}, 'visibility' => {'roles' => ['_ALL_']}}},
]
}
post(api_custom_buttons_url, :params => request)

expected = {
'results' => a_collection_including(
a_hash_including('id' => cb.id.to_s, 'name' => 'updated 1'),
a_hash_including('id' => cb.id.to_s, 'name' => 'updated 1', 'visibility' => {'roles' => ['_ALL_']}),
)
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
expect(cb.reload.visibility[:roles]).to eq(['_ALL_'])
end
end

Expand Down

0 comments on commit d03bc5d

Please sign in to comment.