diff --git a/.rubocop.yml b/.rubocop.yml index 18682165d..3c7513949 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,10 @@ AllCops: Layout/CaseIndentation: EnforcedStyle: end -Layout/IndentArray: +Layout/IndentFirstArrayElement: + EnforcedStyle: consistent + +Layout/IndentFirstHashElement: EnforcedStyle: consistent # This can be re-enabled once we're 2.3+ only and can use the squiggly heredoc @@ -16,9 +19,6 @@ Layout/IndentArray: Layout/IndentHeredoc: Enabled: false -Layout/IndentHash: - EnforcedStyle: consistent - Metrics/LineLength: Exclude: - "test/**/*.rb" diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8d96346ef..cd8c6f5c5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,27 +1,25 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-05-24 10:18:48 -0700 using RuboCop version 0.57.2. +# on 2019-07-30 09:56:31 +0800 using RuboCop version 0.73.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 20 +# Offense count: 23 Metrics/AbcSize: - Max: 53 + Max: 48 +# Offense count: 33 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine Metrics/BlockLength: - Max: 39 + Max: 509 - # Test `context` is a block and generates all kinds of false positives - # without exclusion. - Exclude: - - 'test/**/*' - -# Offense count: 11 +# Offense count: 12 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 700 + Max: 694 # Offense count: 12 Metrics/CyclomaticComplexity: @@ -32,10 +30,10 @@ Metrics/CyclomaticComplexity: Metrics/ParameterLists: Max: 7 -# Offense count: 7 +# Offense count: 8 Metrics/PerceivedComplexity: Max: 17 -# Offense count: 84 +# Offense count: 86 Style/Documentation: Enabled: false diff --git a/Gemfile b/Gemfile index 3dd44ad77..342b74b8e 100644 --- a/Gemfile +++ b/Gemfile @@ -18,9 +18,7 @@ group :development do # `Gemfile.lock` checked in, so to prevent good builds from suddenly going # bad, pin to a specific version number here. Try to keep this relatively # up-to-date, but it's not the end of the world if it's not. - # Note that 0.57.2 is the most recent version we can use until we drop - # support for Ruby 2.1. - gem "rubocop", "0.57.2" + gem "rubocop", "0.73" # Rack 2.0+ requires Ruby >= 2.2.2 which is problematic for the test suite on # older Ruby versions. Check Ruby the version here and put a maximum diff --git a/lib/stripe/list_object.rb b/lib/stripe/list_object.rb index 8322ba1f5..2394e506e 100644 --- a/lib/stripe/list_object.rb +++ b/lib/stripe/list_object.rb @@ -83,6 +83,7 @@ def retrieve(id, opts = {}) # was given, the default limit will be fetched again. def next_page(params = {}, opts = {}) return self.class.empty_list(opts) unless has_more + last_id = data.last.id params = filters.merge(starting_after: last_id).merge(params) diff --git a/lib/stripe/multipart_encoder.rb b/lib/stripe/multipart_encoder.rb index 6f498f68c..0df93460d 100644 --- a/lib/stripe/multipart_encoder.rb +++ b/lib/stripe/multipart_encoder.rb @@ -51,6 +51,7 @@ def initialize # Gets the encoded body. `#close` must be called first. def body raise "object must be closed before getting body" unless @closed + @body end diff --git a/lib/stripe/resources/usage_record.rb b/lib/stripe/resources/usage_record.rb index 1dd332a2e..f34987940 100644 --- a/lib/stripe/resources/usage_record.rb +++ b/lib/stripe/resources/usage_record.rb @@ -8,6 +8,7 @@ def self.create(params = {}, opts = {}) unless params.key?(:subscription_item) raise ArgumentError, "Params must have a subscription_item key" end + req_params = params.clone.delete_if do |key, _value| key == :subscription_item end diff --git a/lib/stripe/stripe_client.rb b/lib/stripe/stripe_client.rb index bbf4efe4c..52c42bdb6 100644 --- a/lib/stripe/stripe_client.rb +++ b/lib/stripe/stripe_client.rb @@ -214,11 +214,11 @@ def execute_request(method, path, # The original error message is also appended onto the final exception for # full transparency. NETWORK_ERROR_MESSAGES_MAP = { - Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION, - SocketError => ERROR_MESSAGE_CONNECTION, + Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION, + SocketError => ERROR_MESSAGE_CONNECTION, - Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT, - Net::ReadTimeout => ERROR_MESSAGE_TIMEOUT_READ, + Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT, + Net::ReadTimeout => ERROR_MESSAGE_TIMEOUT_READ, OpenSSL::SSL::SSLError => ERROR_MESSAGE_SSL, }.freeze diff --git a/lib/stripe/stripe_object.rb b/lib/stripe/stripe_object.rb index e37b0257d..f0f16b579 100644 --- a/lib/stripe/stripe_object.rb +++ b/lib/stripe/stripe_object.rb @@ -193,6 +193,7 @@ def as_json(*opts) def to_hash maybe_to_hash = lambda do |value| return nil if value.nil? + value.respond_to?(:to_hash) ? value.to_hash : value end @@ -257,6 +258,7 @@ def serialize_params(options = {}) # unsaved = @unsaved_values.include?(k) next unless options[:force] || unsaved || v.is_a?(StripeObject) + update_hash[k.to_sym] = serialize_params_value( @values[k], @original_values[k], unsaved, options[:force], key: k ) diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index 9da5bfaaf..f2d4fa4d3 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -198,11 +198,13 @@ def self.normalize_opts(opts) def self.check_string_argument!(key) raise TypeError, "argument must be a string" unless key.is_a?(String) + key end def self.check_api_key!(key) raise TypeError, "api_key must be a string" unless key.is_a?(String) + key end @@ -245,14 +247,14 @@ def self.secure_compare(str_a, str_b) # COLOR_CODES = { - black: 0, light_black: 60, - red: 1, light_red: 61, - green: 2, light_green: 62, - yellow: 3, light_yellow: 63, - blue: 4, light_blue: 64, + black: 0, light_black: 60, + red: 1, light_red: 61, + green: 2, light_green: 62, + yellow: 3, light_yellow: 63, + blue: 4, light_blue: 64, magenta: 5, light_magenta: 65, - cyan: 6, light_cyan: 66, - white: 7, light_white: 67, + cyan: 6, light_cyan: 66, + white: 7, light_white: 67, default: 9, }.freeze private_constant :COLOR_CODES diff --git a/stripe.gemspec b/stripe.gemspec index 63172b493..e8eab921f 100644 --- a/stripe.gemspec +++ b/stripe.gemspec @@ -17,13 +17,13 @@ Gem::Specification.new do |s| s.license = "MIT" s.metadata = { - "bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues", - "changelog_uri" => + "bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues", + "changelog_uri" => "https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md", "documentation_uri" => "https://stripe.com/docs/api/ruby", - "github_repo" => "ssh://github.com/stripe/stripe-ruby", - "homepage_uri" => "https://stripe.com/docs/api/ruby", - "source_code_uri" => "https://github.com/stripe/stripe-ruby", + "github_repo" => "ssh://github.com/stripe/stripe-ruby", + "homepage_uri" => "https://stripe.com/docs/api/ruby", + "source_code_uri" => "https://github.com/stripe/stripe-ruby", } s.files = `git ls-files`.split("\n") diff --git a/test/stripe/login_link_test.rb b/test/stripe/login_link_test.rb index 053052217..8682e2616 100644 --- a/test/stripe/login_link_test.rb +++ b/test/stripe/login_link_test.rb @@ -12,7 +12,7 @@ class LoginLinkTest < Test::Unit::TestCase "data" => [], "has_more" => false, "object" => "list", - "url" => "/v1/accounts/acct_123/login_links", + "url" => "/v1/accounts/acct_123/login_links", }, } @account = Stripe::Account.construct_from(account_fixture) diff --git a/test/stripe/stripe_object_test.rb b/test/stripe/stripe_object_test.rb index 3bb44e800..d22b50468 100644 --- a/test/stripe/stripe_object_test.rb +++ b/test/stripe/stripe_object_test.rb @@ -302,14 +302,14 @@ def to_hash end should "#serialize_params on an array that shortens" do - obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"]) + obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index]) obj.foo = ["new-value"] assert_equal({ foo: ["new-value"] }, obj.serialize_params) end should "#serialize_params on an array that lengthens" do - obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"]) + obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index]) obj.foo = ["new-value"] * 4 assert_equal({ foo: ["new-value"] * 4 }, obj.serialize_params) @@ -331,8 +331,8 @@ def to_hash end should "#serialize_params on an array that is unchanged" do - obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"]) - obj.foo = ["0-index", "1-index", "2-index"] + obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index]) + obj.foo = %w[0-index 1-index 2-index] assert_equal({}, obj.serialize_params) end diff --git a/test/stripe_mock.rb b/test/stripe_mock.rb index 9118f119c..edb3835e4 100644 --- a/test/stripe_mock.rb +++ b/test/stripe_mock.rb @@ -29,7 +29,7 @@ def self.start @stderr, @child_stderr = ::IO.pipe @pid = ::Process.spawn( - ["stripe-mock", "stripe-mock"], + %w[stripe-mock stripe-mock], "-http-port", "0", # have stripe-mock select a port "-spec", @@ -66,6 +66,7 @@ def self.start # Stops stripe-mock, if necessary. def self.stop return if @pid.nil? + puts("Stopping stripe-mock...") ::Process.kill(:SIGTERM, @pid) ::Process.waitpid2(@pid)