Skip to content

Commit 28f7559

Browse files
authored
Merge branch 'main' into add-missing-status-to-scaffolded-destroy-method
2 parents c72e211 + 8dbc23f commit 28f7559

21 files changed

+140
-250
lines changed

.github/workflows/ruby.yml

+7-93
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
test:
77
name: Ruby ${{ matrix.ruby }} (${{ matrix.gemfile }})
88
runs-on: ubuntu-20.04
9-
continue-on-error: ${{ matrix.experimental }}
9+
continue-on-error: ${{ matrix.gemfile == 'rails_head' }}
1010
env:
1111
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
1212
BUNDLE_JOBS: 4
@@ -15,116 +15,30 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
ruby:
18-
- "2.2"
19-
- "2.3"
20-
- "2.4"
21-
- "2.5"
22-
- "2.6"
23-
- "2.7"
2418
- "3.0"
2519
- "3.1"
20+
- "3.2"
21+
- "3.3"
2622

2723
gemfile:
28-
- "rails_5_0"
29-
- "rails_5_1"
30-
- "rails_5_2"
31-
- "rails_6_0"
32-
- "rails_6_1"
3324
- "rails_7_0"
25+
- "rails_7_1"
3426
- "rails_head"
3527

36-
experimental: [false]
3728
exclude:
38-
- ruby: 2.7
39-
gemfile: rails_5_0
4029
- ruby: '3.0'
41-
gemfile: rails_5_0
42-
- ruby: '3.1'
43-
gemfile: rails_5_0
44-
- ruby: head
45-
gemfile: rails_5_0
46-
- ruby: 2.7
47-
gemfile: rails_5_1
48-
- ruby: '3.0'
49-
gemfile: rails_5_1
50-
- ruby: '3.1'
51-
gemfile: rails_5_1
52-
- ruby: head
53-
gemfile: rails_5_1
54-
- ruby: 2.2
55-
gemfile: rails_5_2
56-
- ruby: 2.7
57-
gemfile: rails_5_2
58-
- ruby: '3.0'
59-
gemfile: rails_5_2
60-
- ruby: '3.1'
61-
gemfile: rails_5_2
62-
- ruby: head
63-
gemfile: rails_5_2
64-
- ruby: 2.2
65-
gemfile: rails_6_0
66-
- ruby: 2.3
67-
gemfile: rails_6_0
68-
- ruby: 2.4
69-
gemfile: rails_6_0
70-
- ruby: '3.0'
71-
gemfile: rails_6_0
72-
- ruby: '3.1'
73-
gemfile: rails_6_0
74-
- ruby: head
75-
gemfile: rails_6_0
76-
- ruby: 2.2
77-
gemfile: rails_6_1
78-
- ruby: 2.3
79-
gemfile: rails_6_1
80-
- ruby: 2.4
81-
gemfile: rails_6_1
82-
- ruby: 2.2
83-
gemfile: rails_7_0
84-
- ruby: 2.3
85-
gemfile: rails_7_0
86-
- ruby: 2.4
87-
gemfile: rails_7_0
88-
- ruby: 2.5
89-
gemfile: rails_7_0
90-
- ruby: 2.6
91-
gemfile: rails_7_0
92-
- ruby: 2.2
93-
gemfile: rails_head
94-
- ruby: 2.3
9530
gemfile: rails_head
96-
- ruby: 2.4
97-
gemfile: rails_head
98-
- ruby: 2.5
99-
gemfile: rails_head
100-
- ruby: 2.6
101-
gemfile: rails_head
102-
- ruby: 2.7
103-
gemfile: rails_head
104-
experimental: false
105-
- ruby: '3.0'
106-
gemfile: rails_head
107-
experimental: false
108-
- ruby: '3.1'
109-
gemfile: rails_head
110-
experimental: false
11131

11232
include:
113-
- ruby: 2.7
114-
gemfile: rails_head
115-
experimental: true
116-
- ruby: '3.0'
117-
gemfile: rails_head
118-
experimental: true
11933
- ruby: '3.1'
12034
gemfile: rails_head
121-
experimental: true
35+
- ruby: '3.2'
36+
gemfile: rails_head
12237
- ruby: head
12338
gemfile: rails_head
124-
experimental: true
12539

12640
steps:
127-
- uses: actions/checkout@v2
41+
- uses: actions/checkout@v4
12842

12943
- uses: ruby/setup-ruby@v1
13044
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tmp
2+
/log
23
gemfiles/.bundle
34
gemfiles/*.lock
45
Gemfile.lock

Appraisals

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
appraise "rails-5-0" do
2-
gem "rails", "~> 5.0.0"
3-
end
4-
5-
appraise "rails-5-1" do
6-
gem "rails", "~> 5.1.0"
7-
end
8-
9-
appraise "rails-5-2" do
10-
gem "rails", "~> 5.2.0"
11-
end
12-
13-
if RUBY_VERSION >= "2.5.0"
14-
appraise "rails-6-0" do
15-
gem "rails", "~> 6.0.0"
16-
end
17-
18-
appraise "rails-6-1" do
19-
gem "rails", "~> 6.1.0"
20-
end
21-
end
22-
231
if RUBY_VERSION >= "2.7.0"
242
appraise "rails-7-0" do
253
gem "rails", "~> 7.0.0"
264
end
275

6+
appraise "rails-7-1" do
7+
gem "rails", "~> 7.1.0"
8+
end
9+
2810
appraise "rails-head" do
2911
gem "rails", github: "rails/rails", branch: "main"
3012
end

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ environment.rb for example):
338338
Jbuilder.deep_format_keys true
339339
```
340340

341+
## Testing JBuilder Response body with RSpec
342+
343+
To test the response body of your controller spec, enable `render_views` in your RSpec context. This [configuration](https://rspec.info/features/6-0/rspec-rails/controller-specs/render-views) renders the views in a controller test.
344+
341345
## Contributing to Jbuilder
342346

343347
Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose

gemfiles/rails_5_1.gemfile

-10
This file was deleted.

gemfiles/rails_5_2.gemfile

-10
This file was deleted.

gemfiles/rails_6_0.gemfile

-10
This file was deleted.

gemfiles/rails_6_1.gemfile

-10
This file was deleted.

gemfiles/rails_5_0.gemfile gemfiles/rails_7_1.gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ source "https://rubygems.org"
55
gem "rake"
66
gem "mocha", require: false
77
gem "appraisal"
8-
gem "rails", "~> 5.0.0"
8+
gem "rails", "~> 7.1.0"
99

1010
gemspec path: "../"

jbuilder.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'jbuilder'
3-
s.version = '2.11.5'
3+
s.version = '2.12.0'
44
s.authors = 'David Heinemeier Hansson'
55
s.email = '[email protected]'
66
s.summary = 'Create JSON structures via a Builder-style DSL'

lib/generators/rails/templates/controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create
3030

3131
respond_to do |format|
3232
if @<%= orm_instance.save %>
33-
format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully created.") %> }
33+
format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %> }
3434
format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> }
3535
else
3636
format.html { render :new, status: :unprocessable_entity }
@@ -43,7 +43,7 @@ def create
4343
def update
4444
respond_to do |format|
4545
if @<%= orm_instance.update("#{singular_table_name}_params") %>
46-
format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully updated.") %> }
46+
format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %> }
4747
format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
4848
else
4949
format.html { render :edit, status: :unprocessable_entity }
@@ -57,7 +57,7 @@ def destroy
5757
@<%= orm_instance.destroy %>
5858
5959
respond_to do |format|
60-
format.html { redirect_to <%= index_helper %>_url, status: :see_other, notice: <%= %("#{human_name} was successfully destroyed.") %> }
60+
format.html { redirect_to <%= index_helper %>_path, status: :see_other, notice: <%= %("#{human_name} was successfully destroyed.") %> }
6161
format.json { head :no_content }
6262
end
6363
end

lib/jbuilder.rb

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
require 'jbuilder/key_formatter'
55
require 'jbuilder/errors'
66
require 'json'
7-
require 'ostruct'
87
require 'active_support/core_ext/hash/deep_merge'
8+
begin
9+
require 'ostruct'
10+
rescue LoadError
11+
end
912

1013
class Jbuilder
1114
@@key_formatter = nil
@@ -28,7 +31,7 @@ def self.encode(*args, &block)
2831
end
2932

3033
BLANK = Blank.new
31-
NON_ENUMERABLES = [ ::Struct, ::OpenStruct ].to_set
34+
NON_ENUMERABLES = defined?(::OpenStruct) ? [::Struct, ::OpenStruct].to_set : [::Struct].to_set
3235

3336
def set!(key, value = BLANK, *args, &block)
3437
result = if ::Kernel.block_given?
@@ -292,7 +295,7 @@ def _extract_method_values(object, attributes)
292295

293296
def _merge_block(key)
294297
current_value = _blank? ? BLANK : @attributes.fetch(_key(key), BLANK)
295-
raise NullError.build(key) if current_value.nil?
298+
::Kernel.raise NullError.build(key) if current_value.nil?
296299
new_value = _scope{ yield self }
297300
_merge_values(current_value, new_value)
298301
end
@@ -307,7 +310,7 @@ def _merge_values(current_value, updates)
307310
elsif ::Hash === current_value && ::Hash === updates
308311
current_value.deep_merge(updates)
309312
else
310-
raise MergeError.build(current_value, updates)
313+
::Kernel.raise MergeError.build(current_value, updates)
311314
end
312315
end
313316

@@ -328,8 +331,8 @@ def _format_keys(hash_or_array)
328331
end
329332

330333
def _set_value(key, value)
331-
raise NullError.build(key) if @attributes.nil?
332-
raise ArrayError.build(key) if ::Array === @attributes
334+
::Kernel.raise NullError.build(key) if @attributes.nil?
335+
::Kernel.raise ArrayError.build(key) if ::Array === @attributes
333336
return if @ignore_nil && value.nil? or _blank?(value)
334337
@attributes = {} if _blank?
335338
@attributes[_key(key)] = value

lib/jbuilder/dependency_tracker.rb

-61
This file was deleted.

lib/jbuilder/jbuilder.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
Jbuilder = Class.new(begin
2-
require 'active_support/proxy_object'
3-
ActiveSupport::ProxyObject
4-
rescue LoadError
5-
require 'active_support/basic_object'
6-
ActiveSupport::BasicObject
7-
end)
1+
Jbuilder = Class.new(BasicObject)

0 commit comments

Comments
 (0)