respondo 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb5118a5648863ec54d68805d897485f40da5b81b9b628b9b9a08d6ee2f735d7
4
- data.tar.gz: 4282b491b0bd587ba668e7accaf19f6dfb879cc61261d64d744de69c803ae8a0
3
+ metadata.gz: c72fa46b09dc6370fd885748d78c0a4cc878738fb994d43609edab1af1bee637
4
+ data.tar.gz: 47a068b005b488305b4bf30a096a38446015643a6650a5c71e7042fe5d49927d
5
5
  SHA512:
6
- metadata.gz: 4ae4daae47ef9c2c66388fc6d8f3a915b66439208fafa25b7046234813229704de0e53863921f2b4e2100817218b2a315ef40a564c5f672a9848194e55814906
7
- data.tar.gz: 86a9ecb6864c1bba75dc4d47941bd0f80c837f4dbc72ed424526e1dad3f05ead92b738a417a239f3fb160e7043fc465418fe6670948be147399ea90ee3ce85d8
6
+ metadata.gz: ed33945bff899f32f5f599bfeac0ed90906acafe2ddaa0ef8f19f8a1c24699839b9df78bcb033174e79bea720161bd3aa1a5841353193463ab69bbf329b2a9f0
7
+ data.tar.gz: ff5b519754b9ec2145feaf1611cd7ad29cfc2291f369781e131e175029025d507ad62fef92b4a6057ea2abf92cf77f3bacf6ae778b0f460f94fc6a810af76ce6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,173 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.1.2] — Code Quality & Test Coverage
4
+
5
+ ### Fixed
6
+
7
+ #### `controller_helpers.rb` — `render_success` and `render_error` made private
8
+ Previously `render_success` and `render_error` were public methods, meaning any
9
+ controller could call them directly — bypassing the semantic named helpers
10
+ (`render_ok`, `render_created`, `render_forbidden`, etc.) and undermining the
11
+ gem's design intent.
12
+
13
+ **Before (public — bypassable):**
14
+ ```ruby
15
+ # Any controller could do this, skipping semantic intent entirely
16
+ render_success(data: @user, status: :created)
17
+ render_error(message: "bad", status: :not_found)
18
+ ```
19
+
20
+ **After (private — enforced through named helpers only):**
21
+ ```ruby
22
+ # Correct usage — callers must use the named helpers
23
+ render_created(data: @user)
24
+ render_not_found(message: "User not found")
25
+ ```
26
+
27
+ **Why:** The named helpers encode the correct HTTP status code, default
28
+ message, and meta code for each scenario. Allowing direct calls to
29
+ `render_success` / `render_error` lets callers set arbitrary status/code
30
+ combinations that break the consistency guarantee.
31
+
32
+ **Migration:** Replace any direct `render_success` / `render_error` calls in
33
+ your controllers with the appropriate named helper. All named helpers remain
34
+ public and their signatures are unchanged.
35
+
36
+ ---
37
+
38
+ #### `response_builder.rb` — replaced `defined?(Time.current)` with `Time.respond_to?(:current)`
39
+ The original guard used Ruby's `defined?` keyword to check for Rails'
40
+ `Time.current`. However, `defined?(Time.current)` always returns `"method"`
41
+ as long as the `Time` constant exists — making the `else` branch permanently
42
+ unreachable even in non-Rails environments.
43
+
44
+ **Before (broken guard — else branch unreachable):**
45
+ ```ruby
46
+ def current_timestamp
47
+ if defined?(Time.current) # always truthy — else never runs
48
+ Time.current.iso8601
49
+ else
50
+ Time.now.utc.iso8601 # dead code
51
+ end
52
+ end
53
+ ```
54
+
55
+ **After (correct guard — both branches reachable):**
56
+ ```ruby
57
+ def current_timestamp
58
+ if Time.respond_to?(:current) # false outside Rails
59
+ Time.current.iso8601
60
+ else
61
+ Time.now.utc.iso8601 # correctly used in plain Ruby
62
+ end
63
+ end
64
+ ```
65
+
66
+ **Why:** `respond_to?` correctly returns `false` in plain Ruby environments
67
+ where ActiveSupport is not loaded, allowing the `Time.now.utc` fallback to
68
+ actually execute. Behaviour in Rails is identical since `Time.respond_to?(:current)`
69
+ returns `true` when ActiveSupport is present.
70
+
71
+ ---
72
+
73
+ #### `install_generator.rb` — blank `api_version` no longer writes empty key to initializer
74
+ Previously, if a user entered a blank api_version at the prompt, the generator
75
+ would write `api_version: ""` into the initializer's `default_meta` block —
76
+ a meaningless empty string that would be sent in every API response.
77
+
78
+ **Before (wrote empty key):**
79
+ ```ruby
80
+ meta = { "api_version" => @cfg[:api_version] }.merge(@cfg[:default_meta])
81
+ # If api_version is "" → writes: api_version: ""
82
+ ```
83
+
84
+ **After (omits blank api_version):**
85
+ ```ruby
86
+ meta = @cfg[:default_meta].dup
87
+ meta["api_version"] = @cfg[:api_version] unless @cfg[:api_version].to_s.empty?
88
+ # If api_version is "" → key is cleanly omitted
89
+ # If no extra meta either → writes: config.default_meta = {}
90
+ ```
91
+
92
+ **Why:** An empty `api_version` key adds noise to every response's meta block
93
+ with no value. The generator now omits it cleanly, and the previously
94
+ unreachable `config.default_meta = {}` branch is now correctly written when
95
+ both `api_version` is blank and no extra meta fields were added.
96
+
97
+ ---
98
+
99
+ ### Changed
100
+
101
+ #### Test coverage improved from 97.92% → 100%
102
+ All previously uncovered branches are now exercised:
103
+
104
+ | File | Branch previously missed | Fix |
105
+ |------|--------------------------|-----|
106
+ | `controller_helpers.rb` | `extract_errors` — `ActiveModel::Errors`, `Array`, `String`, and unknown-type paths | Added `send(:extract_errors, ...)` specs |
107
+ | `response_builder.rb` | `else` branch of `current_timestamp` (non-Rails fallback) | Fixed guard + added branch specs |
108
+ | `install_generator.rb` | `if meta.empty?` branch in `build_content` | Fixed generator logic + added spec |
109
+ | `serializer.rb` | `serialize_record` — `elsif respond_to?(:to_h)` and `else` (bare record) | Added `serialize_record` branch specs |
110
+
111
+ ---
112
+
113
+ ## [2.1.1] — Bug Fix
114
+
115
+ ### Fixed
116
+
117
+ #### `render_no_content` — status mismatch corrected
118
+ Previously `render_no_content` was sending `status: :ok` (200) while setting
119
+ `code: 204` in the meta block. This meant the HTTP response status was 200
120
+ but the meta claimed 204 — inconsistent and misleading to clients.
121
+
122
+ **Before (buggy):**
123
+ ```ruby
124
+ def render_no_content(message: "Deleted successfully", meta: {}, pagination: nil)
125
+ render_success(data: nil, message: message, meta: meta, pagination: pagination, code: 204, status: :ok)
126
+ # ^^^^^^^^^^
127
+ # wrong — sends 200
128
+ end
129
+ ```
130
+
131
+ **After (fixed):**
132
+ ```ruby
133
+ def render_no_content(message: "Deleted successfully", meta: {}, pagination: nil)
134
+ render_success(data: nil, message: message, meta: meta, pagination: pagination, code: 204, status: :no_content)
135
+ # ^^^^^^^^^^^^^^^^^^
136
+ # correct — sends 204
137
+ end
138
+ ```
139
+
140
+ **Why body is kept:** HTTP spec discourages a body on 204 but does not
141
+ strictly forbid it. Respondo keeps the JSON body so FE clients can display
142
+ the `message` field on delete confirmations. Rails and all major HTTP clients
143
+ (Axios, Fetch, OkHttp) handle this correctly.
144
+
145
+ **Migration:** No changes needed — method signature is identical. If you were
146
+ relying on the incorrect 200 status in tests, update your assertions to
147
+ expect 204.
148
+
149
+ ### Changed
150
+
151
+ #### `respondo.gemspec` — corrected `bug_tracker_uri`
152
+ A stray `auditron/` path segment was present in the `bug_tracker_uri` metadata
153
+ field, producing a broken link on RubyGems.
154
+
155
+ **Before:**
156
+ ```ruby
157
+ "bug_tracker_uri" => "#{spec.homepage}/auditron/issues"
158
+ ```
159
+
160
+ **After:**
161
+ ```ruby
162
+ "bug_tracker_uri" => "#{spec.homepage}/issues"
163
+ ```
164
+
165
+ #### `response_builder.rb` — removed stale commented-out code
166
+ A dead `build_meta` implementation was left commented out from a previous
167
+ refactor. Removed to keep the file clean and readable.
168
+
169
+ ---
170
+
3
171
  ## [2.1.0] — Interactive Install Generator
4
172
 
5
173
  ### Added