graphiti-rails 0.2.0 → 0.3.0

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: 0546b042d2d512c700094de8be871f95f65488ae003c508ce522bb881dfccb2e
4
- data.tar.gz: 75dc08fb8add0c1a1eb6ef63c927ff83fdba84eb8cfa9d3b08197db4ee3dbae8
3
+ metadata.gz: bce137505cdca25b658def15e2bfde137b6cf16b7a80aaae9c21218c8ada8f59
4
+ data.tar.gz: f48bbbb85727bffa2367ca8f409574787fc2809c18115027c0c228208c8549a5
5
5
  SHA512:
6
- metadata.gz: e5d4a756cc7bd379e962830b1ff7171fdabae707799a2961e3df8d96746643a6061fe7b6cb1151aea0228fc1a34f42197e11c188a40976cbc0a6982ae09769c5
7
- data.tar.gz: cce0b7aff8cc4301068c6c1e367abb094cc1bed28d7a5203736b4f9cf747082a73fd54438ec15d1e45cdc8e79b7a3a1f1ca9b42a933706e1612ba0c12120f701
6
+ metadata.gz: 28d90e3f09621739f7e743000114c478ee75520dc484baa36e28fe450f6a1f2ac85d084e2e25961d7347cc21c56f8a77019efb5146638591a6b760a218f42868
7
+ data.tar.gz: 9da0d55120df21ec87e99d5746c827f999d2c1efe92f568e03930f06edb5cf4b010ffb01a5b41ec19c15f6b86eb71dbd40837e7d6b9a58427b7a82f0d00c9a6f
data/CHANGELOG.md CHANGED
@@ -7,4 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
- No releases means no changes...
10
+ ## [0.3.0] - 2021-05-11
11
+ ### Changed
12
+ - `rescue_registry` has been updated to 0.3.0. This causes some changes to error payloads.
13
+ [CHANGELOG](https://github.com/wagenet/rescue_registry/blob/master/CHANGELOG.md#030---2021-05-11)
14
+
15
+ ## [0.2.4] - 2020-08-10
16
+ ### Changed
17
+ - The `rails` dependency has been replaced with `railties`. - #60
18
+
19
+ ## [0.2.3] - 2019-10-31
20
+ ### Added
21
+ - Add option to use rawid in generated tests
22
+
23
+ ## [0.2.2] - 2019-10-26
24
+ ### Fixed
25
+ - Let user disable the logger
26
+
27
+ ## [0.2.1] - 2019-06-13
28
+ ### Added
29
+ - Include `__raw_errors__` in detailed error payloads for use by Vandal and Request Responses
30
+
31
+ ### Fixed
32
+ - Do not depend on ActiveRecord for route generators
33
+
34
+ ## [0.2.0] - 2019-05-27
35
+
36
+ Initial release
@@ -13,6 +13,12 @@ module Graphiti
13
13
  aliases: ["--actions", "-a"],
14
14
  desc: 'Array of controller actions, e.g. "index show destroy"'
15
15
 
16
+ class_option :'rawid',
17
+ type: :boolean,
18
+ default: false,
19
+ aliases: ["--rawid", "-r"],
20
+ desc: "Generate tests using rawid"
21
+
16
22
  desc "Generates rspec request specs at spec/api"
17
23
  def generate
18
24
  generate_api_specs
@@ -41,5 +41,19 @@ module Graphiti
41
41
  config = graphiti_config.merge(attrs)
42
42
  File.open(".graphiticfg.yml", "w") { |f| f.write(config.to_yaml) }
43
43
  end
44
+
45
+ def id_or_rawid
46
+ @options["rawid"] ? "rawid" : "id"
47
+ end
48
+
49
+ def sort_raw_ids
50
+ return unless @options["rawid"]
51
+ ".sort"
52
+ end
53
+
54
+ def sort_raw_ids_descending
55
+ return unless @options["rawid"]
56
+ ".sort.reverse"
57
+ end
44
58
  end
45
59
  end
@@ -14,6 +14,12 @@ module Graphiti
14
14
  aliases: ["--omit-comments", "-c"],
15
15
  desc: "Generate without documentation comments"
16
16
 
17
+ class_option :'rawid',
18
+ type: :boolean,
19
+ default: false,
20
+ aliases: ["--rawid", "-r"],
21
+ desc: "Generate tests using rawid"
22
+
17
23
  class_option :actions,
18
24
  type: :array,
19
25
  default: nil,
@@ -132,10 +138,7 @@ module Graphiti
132
138
  end
133
139
 
134
140
  def generate_route
135
- # Rails 5.2 adds `plural_route_name`, fallback to `plural_table_name`
136
- plural_name = try(:plural_route_name) || plural_table_name
137
-
138
- code = "resources :#{plural_name}"
141
+ code = "resources :#{file_name.pluralize}"
139
142
  code << %(, only: [#{actions.map { |a| ":#{a}" }.join(", ")}]) if actions.length < 5
140
143
  code << "\n"
141
144
  inject_into_file "config/routes.rb", after: /ApplicationResource.*$\n/ do
@@ -146,12 +149,14 @@ module Graphiti
146
149
  def generate_resource_specs
147
150
  opts = {}
148
151
  opts[:actions] = @options[:actions] if @options[:actions]
152
+ opts[:rawid] = @options[:rawid] if @options[:rawid]
149
153
  invoke "graphiti:resource_test", [resource_klass], opts
150
154
  end
151
155
 
152
156
  def generate_api_specs
153
157
  opts = {}
154
158
  opts[:actions] = @options[:actions] if @options[:actions]
159
+ opts[:rawid] = @options[:rawid] if @options[:rawid]
155
160
  invoke "graphiti:api_test", [resource_klass], opts
156
161
  end
157
162
 
@@ -16,7 +16,7 @@ RSpec.describe "<%= type %>#index", type: :request do
16
16
  make_request
17
17
  expect(response.status).to eq(200), response.body
18
18
  expect(d.map(&:jsonapi_type).uniq).to match_array(['<%= type %>'])
19
- expect(d.map(&:id)).to match_array([<%= var %>1.id, <%= var %>2.id])
19
+ expect(d.map(&:<%= id_or_rawid %>)).to match_array([<%= var %>1.id, <%= var %>2.id])
20
20
  end
21
21
  end
22
22
  end
@@ -7,7 +7,7 @@ RSpec.describe <%= resource_class %>, type: :resource do
7
7
  it 'works' do
8
8
  render
9
9
  data = jsonapi_data[0]
10
- expect(data.id).to eq(<%= var %>.id)
10
+ expect(data.<%= id_or_rawid %>).to eq(<%= var %>.id)
11
11
  expect(data.jsonapi_type).to eq('<%= type %>')
12
12
  <%- attributes.each do |a| -%>
13
13
  <%- if [:created_at, :updated_at].include?(a.name.to_sym) -%>
@@ -31,7 +31,7 @@ RSpec.describe <%= resource_class %>, type: :resource do
31
31
 
32
32
  it 'works' do
33
33
  render
34
- expect(d.map(&:id)).to eq([<%= var %>2.id])
34
+ expect(d.map(&:<%= id_or_rawid %>)).to eq([<%= var %>2.id])
35
35
  end
36
36
  end
37
37
  end
@@ -48,10 +48,10 @@ RSpec.describe <%= resource_class %>, type: :resource do
48
48
 
49
49
  it 'works' do
50
50
  render
51
- expect(d.map(&:id)).to eq([
51
+ expect(d.map(&:<%= id_or_rawid %>)).to eq([
52
52
  <%= var %>1.id,
53
53
  <%= var %>2.id
54
- ])
54
+ ]<%= sort_raw_ids %>)
55
55
  end
56
56
  end
57
57
 
@@ -62,10 +62,10 @@ RSpec.describe <%= resource_class %>, type: :resource do
62
62
 
63
63
  it 'works' do
64
64
  render
65
- expect(d.map(&:id)).to eq([
65
+ expect(d.map(&:<%= id_or_rawid %>)).to eq([
66
66
  <%= var %>2.id,
67
67
  <%= var %>1.id
68
- ])
68
+ ]<%= sort_raw_ids_descending %>)
69
69
  end
70
70
  end
71
71
  end
@@ -15,7 +15,7 @@ RSpec.describe "<%= type %>#show", type: :request do
15
15
  make_request
16
16
  expect(response.status).to eq(200)
17
17
  expect(d.jsonapi_type).to eq('<%= type %>')
18
- expect(d.id).to eq(<%= var %>.id)
18
+ expect(d.<%= id_or_rawid %>).to eq(<%= var %>.id)
19
19
  end
20
20
  end
21
21
  end
@@ -5,7 +5,16 @@ module Graphiti
5
5
  def build_payload(show_details: false, traces: nil, style: :rails)
6
6
  case style
7
7
  when :standard
8
- super(show_details: show_details, traces: traces)
8
+ super(show_details: show_details, traces: traces).tap do |payload|
9
+ if show_details
10
+ # For Vandal and Request Responses
11
+ payload[:__raw_error__] = {
12
+ message: exception.message,
13
+ debug: exception.instance_variable_get(:@__graphiti_debug),
14
+ backtrace: exception.backtrace
15
+ }
16
+ end
17
+ end
9
18
  when :rails
10
19
  # TODO: Find way to not duplicate RailsExceptionHandler
11
20
  body = {
@@ -37,7 +37,7 @@ module Graphiti
37
37
 
38
38
  initializer "graphti-rails.logger" do
39
39
  config.after_initialize do
40
- Graphiti.config.debug = ::Rails.logger.level.zero?
40
+ Graphiti.config.debug = ::Rails.logger.debug? && Graphiti.config.debug
41
41
  Graphiti.logger = ::Rails.logger
42
42
  end
43
43
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Graphiti
4
4
  module Rails
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Wagenet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-27 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphiti
@@ -30,16 +30,16 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.1
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.1
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: rails
42
+ name: railties
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec-rails
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +192,7 @@ dependencies:
178
192
  - - ">="
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0'
181
- description:
195
+ description:
182
196
  email:
183
197
  - peter.wagenet@gmail.com
184
198
  executables: []
@@ -222,7 +236,7 @@ metadata:
222
236
  bug_tracker_uri: https://github.com/graphiti-api/graphiti-rails/issues
223
237
  changelog_uri: https://github.com/graphiti-api/graphiti-rails/CHANGELOG.md
224
238
  source_code_uri: https://github.com/graphiti-api/graphiti-rails
225
- post_install_message:
239
+ post_install_message:
226
240
  rdoc_options: []
227
241
  require_paths:
228
242
  - lib
@@ -237,9 +251,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
251
  - !ruby/object:Gem::Version
238
252
  version: '0'
239
253
  requirements: []
240
- rubyforge_project:
241
- rubygems_version: 2.7.6
242
- signing_key:
254
+ rubygems_version: 3.2.15
255
+ signing_key:
243
256
  specification_version: 4
244
257
  summary: Rails integration for Graphiti
245
258
  test_files: []