render_turbo_stream 0.1.34 → 0.1.36

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95e94563d2f1c54311f3755286e2ace6f4f258c63f443b305043cf2c7611cd4f
4
- data.tar.gz: e7deed853515642b52503f1f870e436ad4870359320b7fc88d179e10b9d60943
3
+ metadata.gz: 2c7532451ee9d808af49593c554e304f1f4de4f82f561378bf449ae7e9933722
4
+ data.tar.gz: c967685bd9bb8476536af267ad2e9fe24b66ef5ca63ba48b6aef6501621c6cf4
5
5
  SHA512:
6
- metadata.gz: a34007581d53530c7f96f1aff79af28594303c856dea1913708d913794a4020f8203c98ffd8a6538446e1a85295436a7d466ff1e09f3171615af7eac6afff781
7
- data.tar.gz: f7fa39fbd0932a58112168abe638f323f1f3a3ae98d1ddd9fc700e504d741dfbc04dfb666ecd34cff42ff6b6ca0ab236ad94fbd05e48f55c8b75b5da19593c10
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.34"
2
+ VERSION = "0.1.36"
3
3
  end
@@ -97,6 +97,7 @@ module RenderTurboStream
97
97
  flash_partial = Rails.configuration.x.render_turbo_stream.flash_partial
98
98
  flash_action = Rails.configuration.x.render_turbo_stream.flash_action
99
99
  flash_notices.each do |notice|
100
+ next unless notice.present?
100
101
  # inside the flash partial has to be a loop that handles all theese flashes
101
102
  flash_stream = {
102
103
  id: flash_id,
@@ -107,6 +108,7 @@ module RenderTurboStream
107
108
  streams.push(flash_stream)
108
109
  end
109
110
  flash_alerts.each do |alert|
111
+ next unless alert.present?
110
112
  # inside the flash partial has to be a loop that handles all theese flashes
111
113
  flash_stream = {
112
114
  id: flash_id,
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.34
4
+ version: 0.1.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian