Skip to content

Commit

Permalink
Merge pull request #9760 from imtayadeway/refactor/expect-hash-to-hav…
Browse files Browse the repository at this point in the history
…e-keys

Refactor/expect hash to have keys
  • Loading branch information
abellotti committed Jul 14, 2016
2 parents b15e327 + 13c0d7e commit b096604
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
5 changes: 3 additions & 2 deletions spec/requests/api/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@
run_get entrypoint_url, :attributes => "authorization"

expect(response).to have_http_status(:ok)
expect_result_to_have_keys(ENTRYPOINT_KEYS + %w(authorization))
expect_hash_to_have_keys(response_hash["authorization"], %w(product_features))
expected = {"authorization" => hash_including("product_features")}
ENTRYPOINT_KEYS.each { |k| expected[k] = anything }
expect(response_hash).to include(expected)
end
end

Expand Down
21 changes: 12 additions & 9 deletions spec/requests/api/custom_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ def expect_result_to_have_custom_actions_hash

run_get services_url(svc2.id), :attributes => "custom_actions"

expect_result_to_have_keys(%w(custom_actions))
custom_actions = response_hash["custom_actions"]
expect_hash_to_have_only_keys(custom_actions, %w(buttons button_groups))
expect(custom_actions["buttons"].size).to eq(1)
button = response_hash["custom_actions"]["buttons"].first
expect_hash_to_have_keys(button, %w(id resource_action))
ra = button["resource_action"]
expect_hash_to_have_keys(ra, %w(id dialog_id))
expect_result_to_match_hash(ra, "id" => ra2.id, "dialog_id" => ra2.dialog_id)
expected = {
"custom_actions" => {
"button_groups" => anything,
"buttons" => [
hash_including(
"id" => anything,
"resource_action" => hash_including("id" => ra2.id, "dialog_id" => ra2.dialog_id)
)
]
}
}
expect(response_hash).to include(expected)
end
end
end
13 changes: 10 additions & 3 deletions spec/requests/api/service_catalogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,16 @@ def init_st_dialog

run_post(sc_templates_url(sc.id, st1.id), gen_request(:refresh_dialog_fields, "fields" => %w(text1)))

expect_single_action_result(:success => true, :message => /refreshing dialog fields/i)
expect_hash_to_have_keys(response_hash, %w(success href service_template_id service_template_href result))
expect_hash_to_have_keys(response_hash["result"], %w(text1))
expected = {
"success" => true,
"message" => a_string_matching(/refreshing dialog fields/i),
"href" => anything,
"service_template_id" => anything,
"service_template_href" => anything,
"result" => hash_including("text1")
}
expect(response_hash).to include(expected)
expect(response).to have_http_status(:ok)
end
end
end
6 changes: 1 addition & 5 deletions spec/support/api_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ def expect_result_resources_to_match_key_data(collection, key, values)
end

def expect_result_to_have_keys(keys)
expect_hash_to_have_keys(response_hash, keys)
end

def expect_hash_to_have_keys(hash, keys)
fetch_value(keys).each { |key| expect(hash).to have_key(key) }
expect(response_hash).to include(*keys)
end

def expect_result_to_have_only_keys(keys)
Expand Down

0 comments on commit b096604

Please sign in to comment.