respondo 2.1.1 → 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: fbe7751852587a50eb66e9d18128db0f0b98295f6e309ea1db812d2c6802827e
4
- data.tar.gz: d59797929ccbf67f507eba232a36c04f5642318b1f3992aa0251f3949b4ed284
3
+ metadata.gz: c72fa46b09dc6370fd885748d78c0a4cc878738fb994d43609edab1af1bee637
4
+ data.tar.gz: 47a068b005b488305b4bf30a096a38446015643a6650a5c71e7042fe5d49927d
5
5
  SHA512:
6
- metadata.gz: d3d210ee9413164b2d0b80b4c84e8f238ffac624145704dbabfb4a09242d655460e18ecd0591cd010a43a5a9c37d1b0a1ad6086ac0ab8f0a7e36536f0d6b16c3
7
- data.tar.gz: 8683372f8e107d696b62d6f5e69e9f693638ce3dc50f21775d54820781c987fae14e924bce00c126b83747ce8ef14857652582a7a1e0d1c881c1536c7c4bbfe5
6
+ metadata.gz: ed33945bff899f32f5f599bfeac0ed90906acafe2ddaa0ef8f19f8a1c24699839b9df78bcb033174e79bea720161bd3aa1a5841353193463ab69bbf329b2a9f0
7
+ data.tar.gz: ff5b519754b9ec2145feaf1611cd7ad29cfc2291f369781e131e175029025d507ad62fef92b4a6057ea2abf92cf77f3bacf6ae778b0f460f94fc6a810af76ce6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,115 @@
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
+
3
113
  ## [2.1.1] — Bug Fix
4
114
 
5
115
  ### Fixed