jpie 0.4.4 → 0.4.5
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 +4 -4
- data/.cursor/rules/publish_gem.mdc +73 -0
- data/.cursor/rules/style.mdc +1 -1
- data/PUBLISHING.md +111 -0
- data/examples/rspec_testing.md +130 -0
- data/lib/jpie/version.rb +1 -1
- data/lib/jpie.rb +0 -4
- metadata +5 -3
- data/lib/jpie/rspec.rb +0 -71
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47016b3f031cd5322fecf012737f1aaace980414f3ed27dd18f54e21e5c5b76b
|
4
|
+
data.tar.gz: 7f8164b1e49018f93838740dcf64d79c331608095e1aa6c58e6c3fbf756ce1b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81b14fd2264f3a2b930deec1f9328fea96c6b89e8fd0a2ef60379ec245789503304f013c442ff6e23b1eee304a8e3d34c064b8535a51edcbcf505b108f63acff
|
7
|
+
data.tar.gz: aad90976a22a42d6dcc038edfb0a28ef5f2a4923cf7a8d5083ad6d9c55198c93c59aab7b94cce408057597219f50f4f8ecad18651f7a774821d5906601be55e9
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Publish JPie Gem
|
2
|
+
|
3
|
+
This rule helps publish a new version of the JPie gem.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
# Publish JPie Gem
|
7
|
+
|
8
|
+
This rule helps publish a new version of the JPie gem.
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
1. You must have publishing rights on RubyGems.org
|
13
|
+
2. You must have 2FA enabled on RubyGems.org
|
14
|
+
3. The version must be updated in `lib/jpie/version.rb`
|
15
|
+
4. The changelog must be updated in `CHANGELOG.md`
|
16
|
+
|
17
|
+
## Steps
|
18
|
+
|
19
|
+
1. First, ensure the version and changelog are updated and committed
|
20
|
+
2. Build the gem
|
21
|
+
3. Get OTP code from user
|
22
|
+
4. Push to RubyGems with OTP
|
23
|
+
5. Update bundle
|
24
|
+
6. Tag the release
|
25
|
+
7. Push tags
|
26
|
+
|
27
|
+
## Example Chat
|
28
|
+
|
29
|
+
Human: Publish new version of JPie gem
|
30
|
+
|
31
|
+
Assistant: I will help you publish the gem. First, let me check if the version and changelog are updated.
|
32
|
+
[Checks version and changelog]
|
33
|
+
|
34
|
+
Now I will build the gem:
|
35
|
+
> gem build jpie.gemspec
|
36
|
+
|
37
|
+
The gem has been built. To publish it, I will need your OTP code from RubyGems.org.
|
38
|
+
What is your OTP code?
|
39
|
+
|
40
|
+
Human: 123456
|
41
|
+
|
42
|
+
Assistant: Thanks! I will now push the gem with your OTP:
|
43
|
+
> gem push jpie-x.y.z.gem --otp 123456
|
44
|
+
|
45
|
+
Great! The gem has been published. Now I will:
|
46
|
+
1. Update the bundle
|
47
|
+
> bundle update jpie
|
48
|
+
|
49
|
+
2. Tag the release
|
50
|
+
> git tag -a vx.y.z -m "Version x.y.z"
|
51
|
+
|
52
|
+
3. Push the tags
|
53
|
+
> git push origin --tags
|
54
|
+
|
55
|
+
The gem has been successfully published and all post-publish steps are complete!
|
56
|
+
|
57
|
+
## Automation
|
58
|
+
|
59
|
+
```bash
|
60
|
+
# Build the gem
|
61
|
+
gem build jpie.gemspec
|
62
|
+
|
63
|
+
# Push to RubyGems (OTP will be requested via chat)
|
64
|
+
gem push jpie-*.gem --otp ${OTP_CODE}
|
65
|
+
|
66
|
+
# Update bundle
|
67
|
+
bundle update jpie
|
68
|
+
|
69
|
+
# Tag and push
|
70
|
+
VERSION=$(ruby -r ./lib/jpie/version.rb -e "puts JPie::VERSION")
|
71
|
+
git tag -a v${VERSION} -m "Version ${VERSION}"
|
72
|
+
git push origin --tags
|
73
|
+
```
|
data/.cursor/rules/style.mdc
CHANGED
@@ -7,7 +7,7 @@ alwaysApply: false
|
|
7
7
|
|
8
8
|
## Ruby Style
|
9
9
|
- Follow Ruby style guide and RuboCop rules defined in .rubocop.yml
|
10
|
-
- Prefer rubocop autocorrect
|
10
|
+
- Prefer rubocop autocorrect
|
11
11
|
- Always pass rubocop before committing to git
|
12
12
|
- Use `{data:}` rather than `{data: data}`
|
13
13
|
- Only use code comments when absolutely necessary
|
data/PUBLISHING.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Publishing JPie
|
2
|
+
|
3
|
+
This guide explains how to publish new versions of the JPie gem to RubyGems.org.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
1. Ensure you have a RubyGems.org account
|
8
|
+
2. Ensure you have ownership/publishing rights to the gem
|
9
|
+
3. Configure your local credentials:
|
10
|
+
```bash
|
11
|
+
gem signin
|
12
|
+
```
|
13
|
+
|
14
|
+
## Publishing Process
|
15
|
+
|
16
|
+
### 1. Update Version
|
17
|
+
|
18
|
+
Update the version number in `lib/jpie/version.rb`:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
module JPie
|
22
|
+
VERSION = "x.y.z" # Use semantic versioning
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
### 2. Update Changelog
|
27
|
+
|
28
|
+
Update `CHANGELOG.md` with the changes in the new version:
|
29
|
+
|
30
|
+
```markdown
|
31
|
+
## [x.y.z] - YYYY-MM-DD
|
32
|
+
|
33
|
+
### Added
|
34
|
+
- New features
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
- Changes in existing functionality
|
38
|
+
|
39
|
+
### Deprecated
|
40
|
+
- Soon-to-be removed features
|
41
|
+
|
42
|
+
### Removed
|
43
|
+
- Removed features
|
44
|
+
|
45
|
+
### Fixed
|
46
|
+
- Bug fixes
|
47
|
+
|
48
|
+
### Security
|
49
|
+
- Security fixes
|
50
|
+
```
|
51
|
+
|
52
|
+
### 3. Build the Gem
|
53
|
+
|
54
|
+
```bash
|
55
|
+
gem build jpie.gemspec
|
56
|
+
```
|
57
|
+
|
58
|
+
This will create a file named `jpie-x.y.z.gem`.
|
59
|
+
|
60
|
+
### 4. Test the Gem Locally (Optional)
|
61
|
+
|
62
|
+
```bash
|
63
|
+
# In a test project
|
64
|
+
gem install ../path/to/jpie-x.y.z.gem
|
65
|
+
```
|
66
|
+
|
67
|
+
### 5. Push to RubyGems
|
68
|
+
|
69
|
+
```bash
|
70
|
+
gem push jpie-x.y.z.gem
|
71
|
+
```
|
72
|
+
|
73
|
+
### 6. Tag the Release
|
74
|
+
|
75
|
+
```bash
|
76
|
+
git add lib/jpie/version.rb CHANGELOG.md
|
77
|
+
git commit -m "Release version x.y.z"
|
78
|
+
git tag -a vx.y.z -m "Version x.y.z"
|
79
|
+
git push origin main --tags
|
80
|
+
```
|
81
|
+
|
82
|
+
## Versioning Guidelines
|
83
|
+
|
84
|
+
Follow [Semantic Versioning](https://semver.org/):
|
85
|
+
|
86
|
+
- MAJOR version (x) - incompatible API changes
|
87
|
+
- MINOR version (y) - add functionality in a backward compatible manner
|
88
|
+
- PATCH version (z) - backward compatible bug fixes
|
89
|
+
|
90
|
+
## Troubleshooting
|
91
|
+
|
92
|
+
### Common Issues
|
93
|
+
|
94
|
+
1. **Authentication Failed**
|
95
|
+
```bash
|
96
|
+
gem signin # Re-authenticate with RubyGems
|
97
|
+
```
|
98
|
+
|
99
|
+
2. **Gem Name Conflict**
|
100
|
+
- Ensure the version number is unique
|
101
|
+
- Check if the gem name is available on RubyGems.org
|
102
|
+
|
103
|
+
3. **Build Errors**
|
104
|
+
- Ensure all dependencies are correctly specified in the gemspec
|
105
|
+
- Verify the gem builds locally before pushing
|
106
|
+
|
107
|
+
### Getting Help
|
108
|
+
|
109
|
+
- [RubyGems Guides](https://guides.rubygems.org/)
|
110
|
+
- [Semantic Versioning](https://semver.org/)
|
111
|
+
- Open an issue in the JPie repository
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# Testing JPie Resources with RSpec
|
2
|
+
|
3
|
+
This guide demonstrates how to use JPie's RSpec matchers and helpers to test your JSON:API resources.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Add to your `spec/rails_helper.rb` or `spec/spec_helper.rb`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'jpie/rspec'
|
11
|
+
JPie::RSpec.configure!
|
12
|
+
```
|
13
|
+
|
14
|
+
## Example Usage
|
15
|
+
|
16
|
+
Given a basic resource setup:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# app/models/book.rb
|
20
|
+
class Book < ApplicationRecord
|
21
|
+
belongs_to :author
|
22
|
+
has_many :reviews
|
23
|
+
|
24
|
+
def reading_time_minutes
|
25
|
+
(content.split.length / 200.0).ceil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# app/resources/book_resource.rb
|
30
|
+
class BookResource < JPie::Resource
|
31
|
+
type :books
|
32
|
+
|
33
|
+
attribute :title
|
34
|
+
meta_attribute :reading_time
|
35
|
+
relationship :author
|
36
|
+
relationship :reviews
|
37
|
+
|
38
|
+
def reading_time
|
39
|
+
{ minutes: object.reading_time_minutes }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Here's how to test it:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# spec/resources/book_resource_spec.rb
|
48
|
+
RSpec.describe BookResource, type: :resource do
|
49
|
+
let(:author) { create(:author) }
|
50
|
+
let(:book) { create(:book, author: author) }
|
51
|
+
let(:resource) { described_class.new(model: book) }
|
52
|
+
|
53
|
+
# Test resource structure
|
54
|
+
it { is_expected.to have_type(:books) }
|
55
|
+
it { is_expected.to have_attribute(:title) }
|
56
|
+
it { is_expected.to have_meta_attribute(:reading_time) }
|
57
|
+
it { is_expected.to have_relationship(:author) }
|
58
|
+
it { is_expected.to have_relationship(:reviews) }
|
59
|
+
|
60
|
+
# Test meta values
|
61
|
+
it 'has correct reading time' do
|
62
|
+
expect(resource).to have_meta_value(:reading_time).including(
|
63
|
+
minutes: book.reading_time_minutes
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Test relationship linkage
|
68
|
+
it 'has correct author linkage' do
|
69
|
+
expect(resource).to have_relationship_linkage(:author).with_id(author.id.to_s)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# spec/requests/books_controller_spec.rb
|
74
|
+
RSpec.describe BooksController, type: :request do
|
75
|
+
let!(:books) { create_list(:book, 10) }
|
76
|
+
|
77
|
+
describe 'GET /books' do
|
78
|
+
it 'handles pagination and includes' do
|
79
|
+
get '/books', params: {
|
80
|
+
page: 1,
|
81
|
+
per_page: 5,
|
82
|
+
include: 'author,reviews'
|
83
|
+
}
|
84
|
+
|
85
|
+
# Test pagination
|
86
|
+
expect(response).to be_paginated
|
87
|
+
expect(response).to have_page_size(5)
|
88
|
+
expect(response).to have_pagination_links.including(:first, :last, :next)
|
89
|
+
|
90
|
+
# Test includes
|
91
|
+
expect(response).to include_related(:author)
|
92
|
+
expect(response).to include_related(:reviews)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
## Helper Methods
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# Build without saving
|
102
|
+
book = build_jpie_resource(:books, { title: 'Test Book' })
|
103
|
+
|
104
|
+
# Create with relationships
|
105
|
+
author = create_jpie_resource(:authors, { name: 'Author' })
|
106
|
+
book = create_jpie_resource(:books, { title: 'Test Book' }, { author: author })
|
107
|
+
|
108
|
+
# Clean up
|
109
|
+
cleanup_jpie_resources([book, author])
|
110
|
+
```
|
111
|
+
|
112
|
+
## Best Practices
|
113
|
+
|
114
|
+
1. Always clean up your test resources using `cleanup_jpie_resources`
|
115
|
+
2. Test both the presence of attributes/relationships and their values
|
116
|
+
3. Group your tests logically by resource features (attributes, relationships, meta)
|
117
|
+
4. Test pagination with different page sizes and page numbers
|
118
|
+
5. Test relationship includes with various combinations
|
119
|
+
6. Test meta fields with both simple and complex values
|
120
|
+
7. Use factories (like FactoryBot) to create test data
|
121
|
+
8. Test edge cases and validations specific to your resource configuration
|
122
|
+
|
123
|
+
## Common Gotchas
|
124
|
+
|
125
|
+
- Remember that `have_attribute` and `have_relationship` check both the presence of the method and the attribute/relationship in the resource's configuration
|
126
|
+
- The cleanup helper will only destroy persisted resources
|
127
|
+
- When testing relationships, make sure to test both the relationship configuration and the actual related resources
|
128
|
+
- Meta field values should match exactly, including nested structures
|
129
|
+
- Pagination tests should verify both the metadata and the actual number of records returned
|
130
|
+
- When testing includes, verify both the presence of the included data and its structure
|
data/lib/jpie/version.rb
CHANGED
data/lib/jpie.rb
CHANGED
@@ -4,12 +4,8 @@ require 'active_support'
|
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
require 'jpie/version'
|
6
6
|
require_relative 'jpie/resource'
|
7
|
-
require_relative 'jpie/client'
|
8
7
|
require_relative 'jpie/errors'
|
9
8
|
|
10
|
-
# Load RSpec support if RSpec is defined
|
11
|
-
require_relative 'jpie/rspec' if defined?(RSpec)
|
12
|
-
|
13
9
|
module JPie
|
14
10
|
autoload :Serializer, 'jpie/serializer'
|
15
11
|
autoload :Deserializer, 'jpie/deserializer'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jpie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Kampp
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-05-
|
10
|
+
date: 2025-05-28 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- ".cursor/rules/examples.mdc"
|
174
174
|
- ".cursor/rules/git.mdc"
|
175
175
|
- ".cursor/rules/project_structure.mdc"
|
176
|
+
- ".cursor/rules/publish_gem.mdc"
|
176
177
|
- ".cursor/rules/security.mdc"
|
177
178
|
- ".cursor/rules/style.mdc"
|
178
179
|
- ".cursor/rules/testing.mdc"
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- ".rubocop.yml"
|
181
182
|
- CHANGELOG.md
|
182
183
|
- LICENSE.txt
|
184
|
+
- PUBLISHING.md
|
183
185
|
- README.md
|
184
186
|
- Rakefile
|
185
187
|
- examples/basic_example.md
|
@@ -188,6 +190,7 @@ files:
|
|
188
190
|
- examples/relationships.md
|
189
191
|
- examples/resource_attribute_configuration.md
|
190
192
|
- examples/resource_meta_configuration.md
|
193
|
+
- examples/rspec_testing.md
|
191
194
|
- examples/single_table_inheritance.md
|
192
195
|
- jpie.gemspec
|
193
196
|
- lib/jpie.rb
|
@@ -213,7 +216,6 @@ files:
|
|
213
216
|
- lib/jpie/resource/inferrable.rb
|
214
217
|
- lib/jpie/resource/sortable.rb
|
215
218
|
- lib/jpie/routing.rb
|
216
|
-
- lib/jpie/rspec.rb
|
217
219
|
- lib/jpie/serializer.rb
|
218
220
|
- lib/jpie/version.rb
|
219
221
|
homepage: https://github.com/emk-klaay/jpie
|
data/lib/jpie/rspec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rspec/expectations'
|
4
|
-
|
5
|
-
module JPie
|
6
|
-
# RSpec matchers and helpers for testing JPie resources
|
7
|
-
module RSpec
|
8
|
-
# Configure RSpec with JPie helpers and matchers
|
9
|
-
def self.configure!
|
10
|
-
::RSpec.configure do |config|
|
11
|
-
config.include JPie::RSpec::Matchers
|
12
|
-
config.include JPie::RSpec::Helpers
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Custom matchers for JPie resources
|
17
|
-
module Matchers
|
18
|
-
extend ::RSpec::Matchers::DSL
|
19
|
-
|
20
|
-
matcher :have_attribute do |attribute_name|
|
21
|
-
match do |actual|
|
22
|
-
actual.respond_to?(attribute_name) &&
|
23
|
-
actual.attributes.key?(attribute_name.to_s)
|
24
|
-
end
|
25
|
-
|
26
|
-
failure_message do |actual|
|
27
|
-
"expected #{actual.inspect} to have attribute '#{attribute_name}'"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
matcher :have_relationship do |relationship_name|
|
32
|
-
match do |actual|
|
33
|
-
actual.respond_to?(relationship_name) &&
|
34
|
-
actual.relationships.key?(relationship_name.to_s)
|
35
|
-
end
|
36
|
-
|
37
|
-
failure_message do |actual|
|
38
|
-
"expected #{actual.inspect} to have relationship '#{relationship_name}'"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Helper methods for testing JPie resources
|
44
|
-
module Helpers
|
45
|
-
# Build a JPie resource without saving it
|
46
|
-
def build_jpie_resource(type, attributes = {}, relationships = {})
|
47
|
-
JPie::Resource.new(
|
48
|
-
type: type,
|
49
|
-
attributes: attributes,
|
50
|
-
relationships: relationships
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Create a JPie resource and save it
|
55
|
-
def create_jpie_resource(type, attributes = {}, relationships = {})
|
56
|
-
resource = build_jpie_resource(type, attributes, relationships)
|
57
|
-
resource.save
|
58
|
-
resource
|
59
|
-
end
|
60
|
-
|
61
|
-
# Clean up test data after specs
|
62
|
-
def cleanup_jpie_resources(resources)
|
63
|
-
Array(resources).each do |resource|
|
64
|
-
resource.destroy if resource.persisted?
|
65
|
-
rescue StandardError => e
|
66
|
-
warn "Failed to cleanup resource #{resource.inspect}: #{e.message}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|