Skip to content

Commit

Permalink
Don't mutate parameters in a Command line interface to a user's defau…
Browse files Browse the repository at this point in the history
…lts.

Syntax:

'defaults' [-currentHost | -host <hostname>] followed by one of the following:

  read                                 shows all defaults
  read <domain>                        shows defaults for given domain
  read <domain> <key>                  shows defaults for given domain, key

  read-type <domain> <key>             shows the type for the given domain, key

  write <domain> <domain_rep>          writes domain (overwrites existing)
  write <domain> <key> <value>         writes key for domain

  rename <domain> <old_key> <new_key>  renames old_key to new_key

  delete <domain>                      deletes domain
  delete <domain> <key>                deletes key in domain
  delete-all <domain>                  deletes the domain from all containers
  delete-all <domain> Key>             deletes key in domain from all containers

  import <domain> <path to plist>      writes the plist at path to domain
  import <domain> -                    writes a plist from stdin to domain
  export <domain> <path to plist>      saves domain as a binary plist to path
  export <domain> -                    writes domain as an xml plist to stdout
  domains                              lists all domains
  find <word>                          lists all entries containing word
  help                                 print this help

<domain> is ( <domain_name> | -app <application_name> | -globalDomain )
         or a path to a file omitting the '.plist' extension

<value> is one of:
  <value_rep>
  -string <string_value>
  -data <hex_digits>
  -int[eger] <integer_value>
  -float  <floating-point_value>
  -bool[ean] (true | false | yes | no)
  -date <date_rep>
  -array <value1> <value2> ...
  -array-add <value1> <value2> ...
  -dict <key1> <value1> <key2> <value2> ...
  -dict-add <key1> <value1> ... Proc
  • Loading branch information
andyjeffries committed Jan 22, 2024
1 parent f5ed005 commit 325e110
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## 1.12.2

Bugfix:

- Changing the parameters in a `defaults` option to a mapping shouldn't mutate the parameters, meaning that retries should get the same as the original parameters (thanks to vskbjrn for the bug report)

## 1.12.1

Bugfix:
Expand Down
2 changes: 2 additions & 0 deletions lib/flexirest/request.rb
Expand Up @@ -344,6 +344,8 @@ def prepare_params
params = {id:params}
end

params = params.dup

# Format includes parameter for jsonapi
if proxy == :json_api
JsonAPIProxy::Request::Params.translate(params, @object._include_associations)
Expand Down
2 changes: 1 addition & 1 deletion lib/flexirest/version.rb
@@ -1,3 +1,3 @@
module Flexirest
VERSION = "1.12.1"
VERSION = "1.12.2"
end
14 changes: 14 additions & 0 deletions spec/lib/request_spec.rb
Expand Up @@ -173,6 +173,13 @@ def inner_call(name, response)
get :second_call, "/second_call"
end

class SimpleRetryingExampleClient < Flexirest::Base
base_url "http://www.example.com"
get :all, "/objects", defaults: proc { |params| { type: params.delete(:object_type) } }

after_request -> (name, response) { raise Flexirest::CallbackRetryRequestException.new }
end

class LazyLoadedExampleClient < ExampleClient
base_url "http://www.example.com"
lazy_load!
Expand Down Expand Up @@ -1395,6 +1402,13 @@ def verbose ; false ; end
expect(RetryingExampleClient.retries).to eq(2)
end

it "shouldn't destructively change params before retrying" do
stub_request(:get, "http://www.example.com/objects?type=foo").
to_return(status: 200, body: "", headers: {})
SimpleRetryingExampleClient.all(object_type: 'foo')

expect(WebMock).to have_requested(:get, "www.example.com/objects?type=foo").twice
end

context "Direct URL requests" do
class SameServerExampleClient < Flexirest::Base
Expand Down

0 comments on commit 325e110

Please sign in to comment.