stitches 3.7.0 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e779533d1ae845c15bec064ad589e32d2e29bca1b3b966144358735d26026248
4
- data.tar.gz: f9af71cd6d2bab7e70ef1d963c25f66a41aa76107b032dc409bb611c30bf7819
3
+ metadata.gz: ca2ab185c1ce66611e8a5fbf874bbbab5caa5ef2dffc760540401f7d1c03ca10
4
+ data.tar.gz: '087335206e8309b959da8965482d443db390543163b124a47c28636505a088bb'
5
5
  SHA512:
6
- metadata.gz: 5145e91908d5cd6f685b7389cf3cf2a17bca9f5355eb513c26f6bb5f2e66270ebdf9c649796b683f470014e12dae4b98b3c2b2ce151afc2c984c96f94aa38a2f
7
- data.tar.gz: 921734574b5e142f5786c1c7088e389e0d8d243111d5fcbfe7fded4f6e8dbb85fee11b1a25ffc2017f58c8b270ee46c41a6e0a554c130f9f09fa9c4c960cb544
6
+ metadata.gz: d42cba4d8621bd45022d12a859b420ac842312a0207dc33590f59eeafc74ef98760011b77169ba7c2408e9e89825c6021f4c44cb449787cd9f316ce1614a093d
7
+ data.tar.gz: c680ee5c6b9a41f7d9ac281e26a48477e3d7c6920f72334f378686fb4a7d2ae0718728716c8c84bd0c0a07b9a19163fd134ecfdf26f083b6bf3864253b3c456c
@@ -3,9 +3,9 @@
3
3
  ---
4
4
  version: 2
5
5
  jobs:
6
- ruby-2.5.1-rails-5.2:
6
+ ruby-2.5.3-rails-5.2:
7
7
  docker:
8
- - image: circleci/ruby:2.5.1
8
+ - image: circleci/ruby:2.5.3
9
9
  environment:
10
10
  BUNDLE_GEMFILE: Gemfile.rails-5.2
11
11
  working_directory: "~/stitches"
@@ -14,15 +14,19 @@ jobs:
14
14
  - run: bundle install --full-index
15
15
  - run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
16
16
  --format=doc
17
+ - run:
18
+ name: Run Additional CI Steps
19
+ command: if [ -e bin/additional-ci-steps ]; then bin/additional-ci-steps;
20
+ fi
17
21
  - run:
18
22
  name: Notify Pager Duty
19
- command: bundle exec y-notify eng-platform
23
+ command: 'bundle exec y-notify #eng-platform'
20
24
  when: on_fail
21
25
  - store_test_results:
22
26
  path: "/tmp/test-results"
23
- ruby-2.4.4-rails-5.2:
27
+ ruby-2.4.5-rails-5.2:
24
28
  docker:
25
- - image: circleci/ruby:2.4.4
29
+ - image: circleci/ruby:2.4.5
26
30
  environment:
27
31
  BUNDLE_GEMFILE: Gemfile.rails-5.2
28
32
  working_directory: "~/stitches"
@@ -31,15 +35,19 @@ jobs:
31
35
  - run: bundle install --full-index
32
36
  - run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
33
37
  --format=doc
38
+ - run:
39
+ name: Run Additional CI Steps
40
+ command: if [ -e bin/additional-ci-steps ]; then bin/additional-ci-steps;
41
+ fi
34
42
  - run:
35
43
  name: Notify Pager Duty
36
- command: bundle exec y-notify eng-platform
44
+ command: 'bundle exec y-notify #eng-platform'
37
45
  when: on_fail
38
46
  - store_test_results:
39
47
  path: "/tmp/test-results"
40
- ruby-2.5.1-rails-5.1:
48
+ ruby-2.5.3-rails-5.1:
41
49
  docker:
42
- - image: circleci/ruby:2.5.1
50
+ - image: circleci/ruby:2.5.3
43
51
  environment:
44
52
  BUNDLE_GEMFILE: Gemfile.rails-5.1
45
53
  working_directory: "~/stitches"
@@ -48,15 +56,19 @@ jobs:
48
56
  - run: bundle install --full-index
49
57
  - run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
50
58
  --format=doc
59
+ - run:
60
+ name: Run Additional CI Steps
61
+ command: if [ -e bin/additional-ci-steps ]; then bin/additional-ci-steps;
62
+ fi
51
63
  - run:
52
64
  name: Notify Pager Duty
53
- command: bundle exec y-notify eng-platform
65
+ command: 'bundle exec y-notify #eng-platform'
54
66
  when: on_fail
55
67
  - store_test_results:
56
68
  path: "/tmp/test-results"
57
- ruby-2.4.4-rails-5.1:
69
+ ruby-2.4.5-rails-5.1:
58
70
  docker:
59
- - image: circleci/ruby:2.4.4
71
+ - image: circleci/ruby:2.4.5
60
72
  environment:
61
73
  BUNDLE_GEMFILE: Gemfile.rails-5.1
62
74
  working_directory: "~/stitches"
@@ -65,9 +77,13 @@ jobs:
65
77
  - run: bundle install --full-index
66
78
  - run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
67
79
  --format=doc
80
+ - run:
81
+ name: Run Additional CI Steps
82
+ command: if [ -e bin/additional-ci-steps ]; then bin/additional-ci-steps;
83
+ fi
68
84
  - run:
69
85
  name: Notify Pager Duty
70
- command: bundle exec y-notify eng-platform
86
+ command: 'bundle exec y-notify #eng-platform'
71
87
  when: on_fail
72
88
  - store_test_results:
73
89
  path: "/tmp/test-results"
@@ -75,13 +91,13 @@ workflows:
75
91
  version: 2
76
92
  on-commit:
77
93
  jobs:
78
- - ruby-2.5.1-rails-5.2:
94
+ - ruby-2.5.3-rails-5.2:
79
95
  context: org-global
80
- - ruby-2.4.4-rails-5.2:
96
+ - ruby-2.4.5-rails-5.2:
81
97
  context: org-global
82
- - ruby-2.5.1-rails-5.1:
98
+ - ruby-2.5.3-rails-5.1:
83
99
  context: org-global
84
- - ruby-2.4.4-rails-5.1:
100
+ - ruby-2.4.5-rails-5.1:
85
101
  context: org-global
86
102
  scheduled:
87
103
  triggers:
@@ -92,11 +108,11 @@ workflows:
92
108
  only:
93
109
  - master
94
110
  jobs:
95
- - ruby-2.5.1-rails-5.2:
111
+ - ruby-2.5.3-rails-5.2:
96
112
  context: org-global
97
- - ruby-2.4.4-rails-5.2:
113
+ - ruby-2.4.5-rails-5.2:
98
114
  context: org-global
99
- - ruby-2.5.1-rails-5.1:
115
+ - ruby-2.5.3-rails-5.1:
100
116
  context: org-global
101
- - ruby-2.4.4-rails-5.1:
117
+ - ruby-2.4.5-rails-5.1:
102
118
  context: org-global
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.5.3
data/README.md CHANGED
@@ -100,7 +100,7 @@ See [the wiki](https://github.com/stitchfix/stitches/wiki/Setup) for how to setu
100
100
  - Deprecation using the `Sunset` header
101
101
  * The [Generator](https://github.com/stitchfix/stitches/wiki/Generator) sets up some code in your app, so you can start writing
102
102
  APIs using vanilla Rails idioms:
103
- - a "ping" controller that can vaidate your app is working
103
+ - a "ping" controller that can validate your app is working
104
104
  - version routing based on content-type (requests for V2 use the same URL, but are serviced by a different controller)
105
105
  - An ApiClient Active Record
106
106
  - Acceptance tests that can produce API documentation as they test your app.
@@ -118,5 +118,3 @@ any fancy refactors here, just keep it up to date.
118
118
  ---
119
119
 
120
120
  Provided with love by your friends at [Stitch Fix Engineering](http://technology.stitchfix.com)
121
-
122
- ![stitches](https://s3.amazonaws.com/stitchfix-stitches/stitches.png)
@@ -19,7 +19,7 @@ module Stitches
19
19
  # end
20
20
  def deprecated(gone_on:,&block)
21
21
  response.set_header("Sunset",Date.parse(gone_on).in_time_zone("GMT").midnight.strftime("%a, %e %b %Y %H:%M:%S %Z"))
22
- Rails.logger.info("Deprecated endpoint #{request.method} #{request.fullpath} requested by #{current_user.id}")
22
+ Rails.logger.info("DEPRECATED ENDPOINT #{request.method} to #{request.fullpath} requested by #{current_user.id}")
23
23
  block.()
24
24
  end
25
25
  end
@@ -70,7 +70,7 @@ module Stitches
70
70
  def self.from_active_record_object(object)
71
71
  errors = object.errors.to_hash.map { |field,errors|
72
72
  code = "#{field}_invalid".parameterize
73
- message = if object.send(field).respond_to?(:errors)
73
+ message = if object.respond_to?(field) && object.send(field).respond_to?(:errors)
74
74
  object.send(field).errors.full_messages.sort.join(', ')
75
75
  else
76
76
  object.errors.full_messages_for(field).sort.join(', ')
@@ -1,10 +1,19 @@
1
1
  class Api::ApiController < ActionController::Base
2
2
  include Stitches::Deprecation
3
+ #
4
+ # The order of the rescue_from blocks is important - ActiveRecord::RecordNotFound must come after StandardError,
5
+ # otherwise ActiveRecord::RecordNotFound exceptions will get rescued in the StandardError block.
6
+ # See the documentation for rescue_from for further explanation:
7
+ # https://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from
8
+ # Specifically, this part: "Handlers are inherited. They are searched from right to left, from bottom to top, and up
9
+ # the hierarchy."
10
+ #
11
+ rescue_from StandardError do |exception|
12
+ render json: { errors: Stitches::Errors.from_exception(exception) }, status: :internal_server_error
13
+ end
14
+
3
15
  rescue_from ActiveRecord::RecordNotFound do |exception|
4
- respond_to do |type|
5
- type.json { render json: { errors: Stitches::Errors.new([ Stitches::Error.new(code: "not_found", message: exception.message) ]) }, status: 404 }
6
- type.all { render :nothing => true, :status => 404 }
7
- end
16
+ render json: { errors: Stitches::Errors.from_exception(exception) }, status: :not_found
8
17
  end
9
18
 
10
19
  def current_user
@@ -1,3 +1,3 @@
1
1
  module Stitches
2
- VERSION = '3.7.0'
2
+ VERSION = '3.7.2'
3
3
  end
@@ -32,7 +32,7 @@ describe Stitches::Deprecation do
32
32
  end
33
33
  it "logs about the request and current API key id" do
34
34
  fake_controller.deprecated(gone_on: "2018-01-01") {}
35
- expect(logger).to have_received(:info).with(/deprecated.*#{Regexp.escape(request.method)}.*#{Regexp.escape(request.fullpath)}.*#{Regexp.escape(api_client.id.to_s)}/i)
35
+ expect(logger).to have_received(:info).with(/DEPRECATED.*#{Regexp.escape(request.method)}.*#{Regexp.escape(request.fullpath)}.*#{Regexp.escape(api_client.id.to_s)}/i)
36
36
  end
37
37
  it "executes and returns the block" do
38
38
  block_executed = false
@@ -94,6 +94,13 @@ describe Stitches::Errors do
94
94
  expect(errors_hash[1]["code"]).to eq("person_invalid")
95
95
  expect(errors_hash[1]["message"]).to eq("Age is not a number, First name can't be blank, Last name starts with z.")
96
96
  end
97
+
98
+ it "works with nested attributes" do
99
+ object.errors.add("something.nested", "is required")
100
+ errors = Stitches::Errors.from_active_record_object(object)
101
+ errors_hash = JSON.parse(errors.to_json).sort_by {|_| _["code"] }
102
+ expect(errors_hash[0]["code"]).to eq("something-nested_invalid")
103
+ expect(errors_hash[0]["message"]).to eq("Something nested is required")
104
+ end
97
105
  end
98
106
  end
99
-
@@ -75,6 +75,8 @@ RSpec.describe "Adding Stitches to a New Rails App", :integration do
75
75
  expect(File.read(rails_root / "spec" / "rails_helper.rb")).to include("require 'rspec_api_documentation'")
76
76
  expect(File.read(rails_root / "config" / "initializers" / "apitome.rb")).to include("config.mount_at = nil")
77
77
  expect(File.read(rails_root / "config" / "initializers" / "apitome.rb")).to include("config.title = 'Service Documentation'")
78
+ expect(File.read(rails_root / "app" / "controllers" / "api" / "api_controller.rb")).to include("rescue_from StandardError")
79
+ expect(File.read(rails_root / "app" / "controllers" / "api" / "api_controller.rb")).to include("rescue_from ActiveRecord::RecordNotFound")
78
80
  end
79
81
  end
80
82
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stitches
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stitch Fix Engineering
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-08-26 00:00:00.000000000 Z
14
+ date: 2019-02-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -210,8 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
212
  requirements: []
213
- rubyforge_project:
214
- rubygems_version: 2.7.6
213
+ rubygems_version: 3.0.1
215
214
  signing_key:
216
215
  specification_version: 4
217
216
  summary: You'll be in stitches at how easy it is to create a service at Stitch Fix