render_turbo_stream 0.1.35 → 0.1.36

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: 7009da829a23424793f7a032d3de9600465af5837204c63da84f28818a292aa2
4
- data.tar.gz: 417b01b78e4939cd175e80a71bd80c593d91ca5c1578479afbe0a62554c0713a
3
+ metadata.gz: 2c7532451ee9d808af49593c554e304f1f4de4f82f561378bf449ae7e9933722
4
+ data.tar.gz: c967685bd9bb8476536af267ad2e9fe24b66ef5ca63ba48b6aef6501621c6cf4
5
5
  SHA512:
6
- metadata.gz: bac76150d7cdff0b7f2dcd895f798041e18381fcc0862a4afddbd8c7442a09cdb10dac85b80004d54e4c9c8e87cf99c2a5a20d86ea1f5399026033dd14b5b9ff
7
- data.tar.gz: e9b03231a29046f79049d53e3c1c1eb2fea122661ce0e5ca28e2988afb507a4f13538b71ccb879f6c7d0ee1ab34727a0d2c9b0b845f307528f26500d35391a3b
6
+ metadata.gz: 293fdcc0dff25264324482dd433a31507756b73526edc0ab31786e9b08a9e4a86e18cc82b932065b0ff329cded36439cdee2944dbc99440c77359714615f8f73
7
+ data.tar.gz: edde20365f6a575f4dafde9166100b4e3ff4d54cd72ac0f4e767d9b67fb798e7923fe0b906b0f8d3976227f035bcc70cf9d51d1cc408581048083cdaa2219366
data/README.md CHANGED
@@ -2,11 +2,15 @@
2
2
 
3
3
  Defining templates like `(create|update).turbo_stream.haml` annoyed me.
4
4
 
5
- Working consistently with turbo_stream means shooting lots of partials from the backend to the frontend, which always needs the same attributes: ID, partial, and maybe some locals. This gem serializes that: Partials can be controlled directly from the controller.
5
+ Working consistently with turbo_stream means shooting lots of partials from the backend to the frontend, which always
6
+ needs the same attributes: ID, partial, and maybe some locals. This gem serializes that: Partials can be controlled
7
+ directly from the controller.
6
8
 
7
- It sets the status, generates a flash message, handles redirection, pushes it all to the front and comes with predefined helpers for enabling request-specs.
9
+ It sets the status, generates a flash message, handles redirection, pushes it all to the front and comes with predefined
10
+ helpers for enabling request-specs.
8
11
 
9
- An overview of how we design a rails-7 application with turbo is [published on dev.to](https://dev.to/chmich/rails-7-vite-wrapping-up-1pia).
12
+ An overview of how we design a rails-7 application with turbo
13
+ is [published on dev.to](https://dev.to/chmich/rails-7-vite-wrapping-up-1pia).
10
14
 
11
15
  ## Installation
12
16
 
@@ -34,35 +38,39 @@ end
34
38
 
35
39
  Redirection
36
40
 
37
- For redirection to work, you must follow the installation steps from [turbo_power](https://github.com/marcoroth/turbo_power).
41
+ For redirection to work, you must follow the installation steps
42
+ from [turbo_power](https://github.com/marcoroth/turbo_power).
38
43
 
39
44
  Required Configurations for Flash Partial
40
45
 
41
46
  ```ruby
42
47
  config.x.render_turbo_stream.flash_partial = 'layouts/flash'
43
- config.x.render_turbo_stream.flash_id = 'flash-box'
44
- config.x.render_turbo_stream.flash_action = 'prepend'
48
+ config.x.render_turbo_stream.flash_id = 'flash-box'
49
+ config.x.render_turbo_stream.flash_action = 'prepend'
45
50
  ```
46
51
 
47
52
  The corresponding partials for flashes could look [like this](https://gitlab.com/sedl/renderturbostream/-/wikis/flashes)
48
53
 
49
54
  ## Usage
50
55
 
51
- `turbo_stream_save` is a special method for streamlining `update` or `create` functions for `turbo_stream`, which might look like this:
56
+ `turbo_stream_save` is a special method for streamlining `update` or `create` functions for `turbo_stream`, which might
57
+ look like this:
52
58
 
53
59
  ```ruby
54
- def create
55
- @customer = Customer.new(customer_params)
56
60
 
57
- turbo_stream_save(
58
- @customer.save,
59
- redirect_on_success_to: edit_customer_path(@customer)
60
- )
61
+ def create
62
+ @customer = Customer.new(customer_params)
61
63
 
62
- end
64
+ turbo_stream_save(
65
+ @customer.save,
66
+ redirect_on_success_to: edit_customer_path(@customer)
67
+ )
68
+
69
+ end
63
70
  ```
64
71
 
65
- This will set a status, generate a flash message and perform `stream_partials`, which could result in something like this:
72
+ This will set a status, generate a flash message and perform `stream_partials`, which could result in something like
73
+ this:
66
74
 
67
75
  ```ruby
68
76
  stream_partials(
@@ -93,35 +101,40 @@ stream_partial(
93
101
 
94
102
  ## Testing
95
103
 
96
- For system testing we have Capybara. This works great and is necessary for javascript and backend combined apps, but it is good practice to break tests into smaller pieces.
104
+ For system testing we have Capybara. This works great and is necessary for javascript and backend combined apps, but it
105
+ is good practice to break tests into smaller pieces.
97
106
 
98
107
  For the much faster request-level tests, there are some helpers:
99
108
 
100
- If the request format is not `turbo_stream`, which is the case on request specs, the method responds in a special html that contains the medadata that is interesting for our tests and is parsed by included test helpers. So tests could look like this:
109
+ If the request format is not `turbo_stream`, which is the case on request specs, the method responds in a special html
110
+ that contains the medadata that is interesting for our tests and is parsed by included test helpers. So tests could look
111
+ like this:
101
112
 
102
113
  ```ruby
103
114
  require 'rails_helper'
104
115
  include RenderTurboStream::TestHelpers
105
116
 
106
117
  RSpec.describe "Articles", type: :request do
107
-
118
+
108
119
  let(:invalid_params) { { article: { title: '', desciption: 'abc' } } }
109
120
 
110
121
  it 'create failed' do
111
-
122
+
112
123
  post articles_path(params: invalid_params)
113
124
 
114
- # --- BASIC TEST ---
115
-
116
- # Count of rendered partials
117
- expect(partials_count).to eq(2)
118
- # Make sure that each of these partials is rendered exactly once.
119
- expect(partials_once).to include('layouts/flash', 'articles/form')
120
-
121
-
122
-
123
-
124
- # --- MORE OPTIONS ---
125
+ # ----- BASIC -----
126
+
127
+ # Which partials were rendered
128
+ expect(partials).to include('layouts/flash', 'articles/form')
129
+
130
+ # Exactly Which partials were rendered to which ids
131
+ expect(
132
+ partials_once(
133
+ { partial: 'layouts/flash', id: 'flash-box' },
134
+ { partial: 'articles/form', id: 'form' })
135
+ ).to be_truthy
136
+
137
+ # ----- MORE OPTIONS -----
125
138
 
126
139
  # to which html-ids turbo-stream would point
127
140
  expect(partials_ids).to include('flash-box', 'form')
@@ -143,7 +156,7 @@ RSpec.describe "Articles", type: :request do
143
156
  expect(partials_responses(id: 'flash-box').length).to eq(1)
144
157
 
145
158
  # Same with partials
146
-
159
+
147
160
  expect(partials_responses(partial: 'layouts/flash').length).to eq(1)
148
161
  end
149
162
  end
@@ -161,7 +174,8 @@ end
161
174
 
162
175
  P.S.:
163
176
 
164
- Testing the plugin itself: There is a [quick-and-dirty app](https://gitlab.com/sedl/renderturbostream_railsapp) which includes the plugin and has tests done by rspec/request and capybara.
177
+ Testing the plugin itself: There is a [quick-and-dirty app](https://gitlab.com/sedl/renderturbostream_railsapp) which
178
+ includes the plugin and has tests done by rspec/request and capybara.
165
179
 
166
180
  ## Parameters for turbo_stream_save
167
181
 
@@ -212,4 +226,5 @@ example value: `"%<model_name>s successfully created"`
212
226
  Contribution welcome.
213
227
 
214
228
  ## License
229
+
215
230
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.35"
2
+ VERSION = "0.1.36"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_turbo_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.35
4
+ version: 0.1.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian