cubism 0.2.0 → 0.2.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +6 -11
  3. data/Gemfile.lock +332 -155
  4. data/README.md +9 -0
  5. data/README.md~ +32 -12
  6. data/Rakefile +0 -2
  7. data/app/channels/cubism/presence_channel.rb +4 -0
  8. data/app/helpers/cubism_helper.rb +11 -0
  9. data/cubism.gemspec +5 -5
  10. data/lib/cubism/broadcaster.rb +6 -0
  11. data/lib/cubism/cubicle_store.rb +9 -2
  12. data/lib/cubism/preprocessor.rb +4 -1
  13. data/lib/cubism/version.rb +1 -1
  14. data/lib/cubism.rb +6 -0
  15. data/package.json +1 -1
  16. metadata +25 -102
  17. data/test/block_container_test.rb +0 -105
  18. data/test/block_source_test.rb +0 -102
  19. data/test/broadcaster_test.rb +0 -66
  20. data/test/channels/cubism/presence_channel_test.rb +0 -72
  21. data/test/cubicle_store_test.rb +0 -34
  22. data/test/cubism_test.rb +0 -7
  23. data/test/dummy/app/channels/application_cable/channel.rb +0 -4
  24. data/test/dummy/app/channels/application_cable/connection.rb +0 -4
  25. data/test/dummy/app/controllers/application_controller.rb +0 -2
  26. data/test/dummy/app/helpers/application_helper.rb +0 -2
  27. data/test/dummy/app/jobs/application_job.rb +0 -7
  28. data/test/dummy/app/mailers/application_mailer.rb +0 -4
  29. data/test/dummy/app/models/application_record.rb +0 -3
  30. data/test/dummy/app/models/post.rb +0 -3
  31. data/test/dummy/app/models/user.rb +0 -3
  32. data/test/dummy/config/application.rb +0 -22
  33. data/test/dummy/config/boot.rb +0 -5
  34. data/test/dummy/config/environment.rb +0 -5
  35. data/test/dummy/config/environments/development.rb +0 -76
  36. data/test/dummy/config/environments/production.rb +0 -120
  37. data/test/dummy/config/environments/test.rb +0 -59
  38. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
  39. data/test/dummy/config/initializers/assets.rb +0 -12
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
  41. data/test/dummy/config/initializers/content_security_policy.rb +0 -28
  42. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  43. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -6
  44. data/test/dummy/config/initializers/inflections.rb +0 -16
  45. data/test/dummy/config/initializers/mime_types.rb +0 -4
  46. data/test/dummy/config/initializers/permissions_policy.rb +0 -11
  47. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  48. data/test/dummy/config/puma.rb +0 -43
  49. data/test/dummy/config/routes.rb +0 -3
  50. data/test/dummy/db/migrate/20220102072929_create_posts.rb +0 -10
  51. data/test/dummy/db/migrate/20220102073003_create_users.rb +0 -9
  52. data/test/dummy/db/schema.rb +0 -26
  53. data/test/dummy/test/models/post_test.rb +0 -7
  54. data/test/dummy/test/models/user_test.rb +0 -7
  55. data/test/helpers/cubism_helper_test.rb +0 -39
  56. data/test/integration/navigation_test.rb +0 -7
  57. data/test/models/concerns/presence_test.rb +0 -25
  58. data/test/models/concerns/user_test.rb +0 -9
  59. data/test/rendering/preprocessor_test.rb +0 -61
  60. data/test/test_helper.rb +0 -16
data/README.md~ CHANGED
@@ -71,10 +71,27 @@ And then execute:
71
71
  $ bundle
72
72
  ```
73
73
 
74
- After `bundle`, install the Javascript library:
74
+ There are a few ways to install the Cubism JavaScript client, depending on your application setup.
75
75
 
76
- ```bash
77
- $ bin/yarn add @minthesize/cubism
76
+ #### ESBuild / Webpacker
77
+
78
+ ```sh
79
+ yarn add @minthesize/cubism
80
+ ```
81
+
82
+ #### Import maps:
83
+
84
+ ```ruby
85
+ # config/importmap.rb
86
+ # ...
87
+ pin '@minthesize/cubism', to: 'cubism.min.js', preload: true
88
+ ```
89
+
90
+ #### Rails Asset pipeline (Sprockets):
91
+
92
+ ```html+erb
93
+ <!-- app/views/layouts/application.html.erb -->
94
+ <%= javascript_include_tag "cubism.umd.min.js", "data-turbo-track": "reload" %>
78
95
  ```
79
96
 
80
97
  ### Kredis
@@ -146,7 +163,7 @@ yarn link # set the local machine's cubism npm package's lookup to this local pa
146
163
 
147
164
  # Setup a sample project and edit Gemfile to point to local gem
148
165
  # (e.g. `gem "cubism", path: "../cubism"`)
149
- # yarn link @stimulus_reflex/cubism
166
+ # yarn link @minthesize/cubism
150
167
 
151
168
 
152
169
  # Do your work, Submit PR, Profit!
@@ -163,14 +180,17 @@ cd path/to/project
163
180
  yarn install --force
164
181
  ```
165
182
 
166
- ### Release
167
-
168
- 1. Update the version numbers in `javascript/package.json` and `lib/cubism/version.rb`
169
- 2. `git commit -m "Bump version to x.x.x"`
170
- 3. Run `bundle exec rake build`
171
- 4. Run `bundle exec rake release`
172
- 5. Run `npm publish --access public`
173
-
183
+ ### 📦 Releasing
184
+
185
+ 1. Make sure that you run `yarn` and `bundle` to pick up the latest.
186
+ 2. Bump version number at `lib/cubism/version.rb`. Pre-release versions use `.preN`
187
+ 3. Run `rake build` and `yarn build`
188
+ 4. Commit and push changes to github `git commit -m "Bump version to x.x.x"`
189
+ 5. Run `rake release`
190
+ 6. Run `yarn publish --no-git-tag-version`
191
+ 7. Yarn will prompt you for the new version. Pre-release versions use `-preN`
192
+ 8. Commit and push changes to GitHub
193
+ 9. Create a new release on GitHub ([here](https://github.com/julianrubisch/cubism/releases)) and generate the changelog for the stable release for it
174
194
  ## License
175
195
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
176
196
 
data/Rakefile CHANGED
@@ -3,8 +3,6 @@ require "bundler/setup"
3
3
  APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
4
  load "rails/tasks/engine.rake"
5
5
 
6
- load "rails/tasks/statistics.rake"
7
-
8
6
  require "bundler/gem_tasks"
9
7
 
10
8
  require "rake/testtask"
@@ -2,6 +2,8 @@ class Cubism::PresenceChannel < ActionCable::Channel::Base
2
2
  include CableReady::StreamIdentifier
3
3
 
4
4
  def subscribed
5
+ return if Cubism.skip_in_test? && Rails.env.test?
6
+
5
7
  if resource.present?
6
8
  stream_from element_id
7
9
  resource.cubicle_element_ids << element_id
@@ -12,6 +14,8 @@ class Cubism::PresenceChannel < ActionCable::Channel::Base
12
14
  end
13
15
 
14
16
  def unsubscribed
17
+ return if Cubism.skip_in_test? && Rails.env.test?
18
+
15
19
  return unless resource.present?
16
20
 
17
21
  resource.cubicle_element_ids.remove(element_id)
@@ -2,11 +2,22 @@ module CubismHelper
2
2
  include CableReady::StreamIdentifier
3
3
 
4
4
  def cubicle_for(resource, user, scope: "", html_options: {}, appear_trigger: :connect, disappear_trigger: nil, trigger_root: nil, exclude_current_user: true, &block)
5
+ return if Cubism.skip_in_test? && Rails.env.test?
6
+
5
7
  block_location = block.source_location.join(":")
6
8
  block_source = Cubism::BlockSource.find_or_create(
7
9
  location: block_location,
8
10
  view_context: self
9
11
  )
12
+ if block_source.variable_name.blank?
13
+ block_variable_name = block.parameters.find { |type, _| [:req, :opt, :rest].include?(type) }&.last
14
+ if block_variable_name.present?
15
+ block_source.variable_name = block_variable_name.to_s
16
+ # Never write back a sourceless block source: it would replace a good
17
+ # store entry with one the broadcaster cannot render.
18
+ Cubism.source_store[block_source.digest] = block_source if block_source.source.present?
19
+ end
20
+ end
10
21
 
11
22
  resource_gid = resource.to_gid.to_s
12
23
 
data/cubism.gemspec CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.summary = "Lightweight Resource-Based Presence Solution with CableReady"
10
10
  spec.description = "Lightweight Resource-Based Presence Solution with CableReady"
11
11
  spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 3.2"
12
13
 
13
14
  spec.metadata["homepage_uri"] = spec.homepage
14
15
  spec.metadata["source_code_uri"] = "https://github.com/julianrubisch/cubism.git"
@@ -22,15 +23,14 @@ Gem::Specification.new do |spec|
22
23
  "[A-Z]*"
23
24
  ]
24
25
 
25
- spec.test_files = Dir["test/**/*.rb"]
26
-
27
- spec.add_dependency "rails", ">= 6.0"
26
+ spec.add_dependency "rails", ">= 7.2"
28
27
  spec.add_dependency "kredis", ">= 0.4"
29
28
  spec.add_dependency "cable_ready", ">= 5.0.0"
29
+ spec.add_dependency "observer"
30
30
 
31
- spec.add_development_dependency "standard"
31
+ spec.add_development_dependency "standard", ">= 1.35.1"
32
32
  spec.add_development_dependency "nokogiri"
33
33
  spec.add_development_dependency "mocha"
34
34
  spec.add_development_dependency "appraisal"
35
- spec.add_development_dependency "sqlite3"
35
+ spec.add_development_dependency "sqlite3", ">= 2.1"
36
36
  end
@@ -21,6 +21,12 @@ module Cubism
21
21
 
22
22
  block_source = block_container.block_source
23
23
 
24
+ # Blocks declared inside an inline template are never parsed, and the
25
+ # source store can be evicted independently of the block store. Without
26
+ # a source there is nothing to render, and `inline: nil` would raise
27
+ # deep inside ActionView (`nil.to_s` is frozen).
28
+ next if block_source.nil? || block_source.source.blank?
29
+
24
30
  html = ApplicationController.render(inline: block_source.source, locals: {"#{block_source.variable_name}": present_users})
25
31
 
26
32
  selector = "cubicle-element#cubicle-#{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']"
@@ -99,9 +99,16 @@ module Cubism
99
99
  ) do
100
100
  def self.find_or_create(location:, view_context:)
101
101
  instance = new(location: location, view_context: view_context)
102
-
103
- Cubism.source_store.fetch(instance.digest, instance) do |instance|
102
+ stored = Cubism.source_store[instance.digest]
103
+
104
+ # A stored entry without a source is unusable downstream (the broadcaster
105
+ # would hand `inline: nil` to ActionView), so treat it as a miss and reparse.
106
+ if stored&.source.present?
107
+ instance.source = stored.source
108
+ instance.variable_name = stored.variable_name
109
+ else
104
110
  instance.parse!
111
+ Cubism.source_store[instance.digest] = instance
105
112
  end
106
113
 
107
114
  instance
@@ -36,7 +36,10 @@ module Cubism
36
36
  def evaluate_view(erubi, view_context)
37
37
  view = Class.new(ActionView::Base) {
38
38
  include view_context._routes.url_helpers
39
- class_eval("define_method(:_template) { |local_assigns, output_buffer| #{erubi.src} }", erubi.filename.nil? ? "(erubi)" : erubi.filename, 0)
39
+
40
+ # Deliberately not __FILE__/__LINE__: the eval'd source is the user's
41
+ # template, so backtraces have to point there and not at this file.
42
+ class_eval("define_method(:_template) { |local_assigns, output_buffer| #{erubi.src} }", erubi.filename.nil? ? "(erubi)" : erubi.filename, 0) # standard:disable Style/EvalWithLocation
40
43
  }.empty
41
44
  view._run(:_template, nil, {}, ActionView::OutputBuffer.new)
42
45
  end
@@ -1,3 +1,3 @@
1
1
  module Cubism
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/cubism.rb CHANGED
@@ -16,4 +16,10 @@ module Cubism
16
16
 
17
17
  mattr_accessor :block_store, instance_reader: false
18
18
  mattr_accessor :source_store, instance_reader: false
19
+
20
+ mattr_accessor :skip_in_test, default: false
21
+
22
+ def self.skip_in_test?
23
+ skip_in_test.present?
24
+ end
19
25
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minthesize/cubism",
3
- "version": "0.1.1",
3
+ "version": "0.2.2",
4
4
  "description": "Lightweight Resource-Based Presence Solution with CableReady.",
5
5
  "main": "./dist/cubism.umd.min.js",
6
6
  "module": "./dist/cubism.min.js",
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cubism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Rubisch
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-03-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '6.0'
18
+ version: '7.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '6.0'
25
+ version: '7.2'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: kredis
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +52,33 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: 5.0.0
55
54
  - !ruby/object:Gem::Dependency
56
- name: standard
55
+ name: observer
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
- type: :development
61
+ type: :runtime
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: standard
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.35.1
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.35.1
69
82
  - !ruby/object:Gem::Dependency
70
83
  name: nokogiri
71
84
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +127,14 @@ dependencies:
114
127
  requirements:
115
128
  - - ">="
116
129
  - !ruby/object:Gem::Version
117
- version: '0'
130
+ version: '2.1'
118
131
  type: :development
119
132
  prerelease: false
120
133
  version_requirements: !ruby/object:Gem::Requirement
121
134
  requirements:
122
135
  - - ">="
123
136
  - !ruby/object:Gem::Version
124
- version: '0'
137
+ version: '2.1'
125
138
  description: Lightweight Resource-Based Presence Solution with CableReady
126
139
  email:
127
140
  - julian@julianrubisch.at
@@ -166,50 +179,6 @@ files:
166
179
  - package.json~
167
180
  - rollup.config.js
168
181
  - rollup.config.js~
169
- - test/block_container_test.rb
170
- - test/block_source_test.rb
171
- - test/broadcaster_test.rb
172
- - test/channels/cubism/presence_channel_test.rb
173
- - test/cubicle_store_test.rb
174
- - test/cubism_test.rb
175
- - test/dummy/app/channels/application_cable/channel.rb
176
- - test/dummy/app/channels/application_cable/connection.rb
177
- - test/dummy/app/controllers/application_controller.rb
178
- - test/dummy/app/helpers/application_helper.rb
179
- - test/dummy/app/jobs/application_job.rb
180
- - test/dummy/app/mailers/application_mailer.rb
181
- - test/dummy/app/models/application_record.rb
182
- - test/dummy/app/models/post.rb
183
- - test/dummy/app/models/user.rb
184
- - test/dummy/config/application.rb
185
- - test/dummy/config/boot.rb
186
- - test/dummy/config/environment.rb
187
- - test/dummy/config/environments/development.rb
188
- - test/dummy/config/environments/production.rb
189
- - test/dummy/config/environments/test.rb
190
- - test/dummy/config/initializers/application_controller_renderer.rb
191
- - test/dummy/config/initializers/assets.rb
192
- - test/dummy/config/initializers/backtrace_silencers.rb
193
- - test/dummy/config/initializers/content_security_policy.rb
194
- - test/dummy/config/initializers/cookies_serializer.rb
195
- - test/dummy/config/initializers/filter_parameter_logging.rb
196
- - test/dummy/config/initializers/inflections.rb
197
- - test/dummy/config/initializers/mime_types.rb
198
- - test/dummy/config/initializers/permissions_policy.rb
199
- - test/dummy/config/initializers/wrap_parameters.rb
200
- - test/dummy/config/puma.rb
201
- - test/dummy/config/routes.rb
202
- - test/dummy/db/migrate/20220102072929_create_posts.rb
203
- - test/dummy/db/migrate/20220102073003_create_users.rb
204
- - test/dummy/db/schema.rb
205
- - test/dummy/test/models/post_test.rb
206
- - test/dummy/test/models/user_test.rb
207
- - test/helpers/cubism_helper_test.rb
208
- - test/integration/navigation_test.rb
209
- - test/models/concerns/presence_test.rb
210
- - test/models/concerns/user_test.rb
211
- - test/rendering/preprocessor_test.rb
212
- - test/test_helper.rb
213
182
  - yarn.lock
214
183
  homepage: https://github.com/julianrubisch/cubism
215
184
  licenses:
@@ -217,7 +186,6 @@ licenses:
217
186
  metadata:
218
187
  homepage_uri: https://github.com/julianrubisch/cubism
219
188
  source_code_uri: https://github.com/julianrubisch/cubism.git
220
- post_install_message:
221
189
  rdoc_options: []
222
190
  require_paths:
223
191
  - lib
@@ -225,59 +193,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
193
  requirements:
226
194
  - - ">="
227
195
  - !ruby/object:Gem::Version
228
- version: '0'
196
+ version: '3.2'
229
197
  required_rubygems_version: !ruby/object:Gem::Requirement
230
198
  requirements:
231
199
  - - ">="
232
200
  - !ruby/object:Gem::Version
233
201
  version: '0'
234
202
  requirements: []
235
- rubygems_version: 3.1.4
236
- signing_key:
203
+ rubygems_version: 3.6.7
237
204
  specification_version: 4
238
205
  summary: Lightweight Resource-Based Presence Solution with CableReady
239
- test_files:
240
- - test/dummy/app/mailers/application_mailer.rb
241
- - test/dummy/app/models/application_record.rb
242
- - test/dummy/app/models/post.rb
243
- - test/dummy/app/models/user.rb
244
- - test/dummy/app/jobs/application_job.rb
245
- - test/dummy/app/controllers/application_controller.rb
246
- - test/dummy/app/helpers/application_helper.rb
247
- - test/dummy/app/channels/application_cable/connection.rb
248
- - test/dummy/app/channels/application_cable/channel.rb
249
- - test/dummy/test/models/post_test.rb
250
- - test/dummy/test/models/user_test.rb
251
- - test/dummy/config/routes.rb
252
- - test/dummy/config/environments/production.rb
253
- - test/dummy/config/environments/development.rb
254
- - test/dummy/config/environments/test.rb
255
- - test/dummy/config/environment.rb
256
- - test/dummy/config/application.rb
257
- - test/dummy/config/puma.rb
258
- - test/dummy/config/boot.rb
259
- - test/dummy/config/initializers/application_controller_renderer.rb
260
- - test/dummy/config/initializers/backtrace_silencers.rb
261
- - test/dummy/config/initializers/mime_types.rb
262
- - test/dummy/config/initializers/filter_parameter_logging.rb
263
- - test/dummy/config/initializers/wrap_parameters.rb
264
- - test/dummy/config/initializers/assets.rb
265
- - test/dummy/config/initializers/cookies_serializer.rb
266
- - test/dummy/config/initializers/permissions_policy.rb
267
- - test/dummy/config/initializers/content_security_policy.rb
268
- - test/dummy/config/initializers/inflections.rb
269
- - test/dummy/db/schema.rb
270
- - test/dummy/db/migrate/20220102072929_create_posts.rb
271
- - test/dummy/db/migrate/20220102073003_create_users.rb
272
- - test/integration/navigation_test.rb
273
- - test/broadcaster_test.rb
274
- - test/cubicle_store_test.rb
275
- - test/models/concerns/presence_test.rb
276
- - test/models/concerns/user_test.rb
277
- - test/block_container_test.rb
278
- - test/cubism_test.rb
279
- - test/rendering/preprocessor_test.rb
280
- - test/test_helper.rb
281
- - test/helpers/cubism_helper_test.rb
282
- - test/block_source_test.rb
283
- - test/channels/cubism/presence_channel_test.rb
206
+ test_files: []
@@ -1,105 +0,0 @@
1
- require "test_helper"
2
-
3
- class BlockContainerTest < ActiveSupport::TestCase
4
- FIXTURES_DIR = File.expand_path("./fixtures", __dir__)
5
-
6
- setup do
7
- @cwd = Dir.pwd
8
- @tmp_dir = Dir.mktmpdir
9
-
10
- FileUtils.cp_r FIXTURES_DIR, @tmp_dir
11
- Dir.chdir @tmp_dir
12
-
13
- @post = posts(:one)
14
- @user = users(:one)
15
- end
16
-
17
- teardown do
18
- Dir.chdir @cwd
19
- FileUtils.rm_r @tmp_dir
20
- end
21
-
22
- test "block container digest changes when file contents change" do
23
- template = "fixtures/_cubicle_partial"
24
-
25
- digest1 = Cubism::BlockContainer.new(
26
- block_location: "#{template_tmp_path(template)}.html.erb:1",
27
- resource_gid: @post.to_gid.to_s,
28
- user_gid: @user.to_gid.to_s
29
- ).digest
30
-
31
- change_template(template)
32
-
33
- digest2 = Cubism::BlockContainer.new(
34
- block_location: "#{template_tmp_path(template)}.html.erb:1",
35
- resource_gid: @post.to_gid.to_s,
36
- user_gid: @user.to_gid.to_s
37
- ).digest
38
-
39
- refute_equal digest1, digest2
40
- end
41
-
42
- test "block container digest changes when user changes" do
43
- template = "fixtures/_cubicle_partial"
44
-
45
- digest1 = Cubism::BlockContainer.new(
46
- block_location: "#{template_tmp_path(template)}.html.erb:1",
47
- resource_gid: @post.to_gid.to_s,
48
- user_gid: @user.to_gid.to_s
49
- ).digest
50
-
51
- digest2 = Cubism::BlockContainer.new(
52
- block_location: "#{template_tmp_path(template)}.html.erb:1",
53
- resource_gid: @post.to_gid.to_s,
54
- user_gid: users(:two).to_gid.to_s
55
- ).digest
56
-
57
- refute_equal digest1, digest2
58
- end
59
-
60
- test "block container digest changes when resource changes" do
61
- template = "fixtures/_cubicle_partial"
62
-
63
- digest1 = Cubism::BlockContainer.new(
64
- block_location: "#{template_tmp_path(template)}.html.erb:1",
65
- resource_gid: @post.to_gid.to_s,
66
- user_gid: @user.to_gid.to_s
67
- ).digest
68
-
69
- digest2 = Cubism::BlockContainer.new(
70
- block_location: "#{template_tmp_path(template)}.html.erb:1",
71
- resource_gid: posts(:two).to_gid.to_s,
72
- user_gid: @user.to_gid.to_s
73
- ).digest
74
-
75
- refute_equal digest1, digest2
76
- end
77
-
78
- test "block container digest changes when block_location changes" do
79
- template = "fixtures/_cubicle_partial"
80
-
81
- digest1 = Cubism::BlockContainer.new(
82
- block_location: "#{template_tmp_path(template)}.html.erb:1",
83
- resource_gid: @post.to_gid.to_s,
84
- user_gid: @user.to_gid.to_s
85
- ).digest
86
-
87
- digest2 = Cubism::BlockContainer.new(
88
- block_location: "#{template_tmp_path(template)}.html.erb:2",
89
- resource_gid: @post.to_gid.to_s,
90
- user_gid: @user.to_gid.to_s
91
- ).digest
92
-
93
- refute_equal digest1, digest2
94
- end
95
-
96
- private
97
-
98
- def template_tmp_path(template)
99
- Pathname.new(@tmp_dir).join(template).to_path
100
- end
101
-
102
- def change_template(template)
103
- File.write("#{template}.html.erb", "\nTHIS WAS CHANGED!")
104
- end
105
- end
@@ -1,102 +0,0 @@
1
- require "test_helper"
2
-
3
- class BlockSourceTest < ActionView::TestCase
4
- FIXTURES_DIR = File.expand_path("./fixtures", __dir__)
5
-
6
- setup do
7
- @cwd = Dir.pwd
8
- @tmp_dir = Dir.mktmpdir
9
-
10
- FileUtils.cp_r FIXTURES_DIR, @tmp_dir
11
- Dir.chdir @tmp_dir
12
-
13
- @post = posts(:one)
14
- @user = users(:one)
15
- end
16
-
17
- teardown do
18
- Dir.chdir @cwd
19
- FileUtils.rm_r @tmp_dir
20
- end
21
-
22
- test "block source digest changes when file contents change" do
23
- template = "fixtures/_cubicle_partial"
24
-
25
- digest1 = Cubism::BlockSource.new(
26
- location: "#{template_tmp_path(template)}.html.erb:1",
27
- view_context: self
28
- ).digest
29
-
30
- change_template(template)
31
-
32
- digest2 = Cubism::BlockSource.new(
33
- location: "#{template_tmp_path(template)}.html.erb:1",
34
- view_context: self
35
- ).digest
36
-
37
- refute_equal digest1, digest2
38
- end
39
-
40
- test "block source digest changes when block_location changes" do
41
- template = "fixtures/_cubicle_partial"
42
-
43
- digest1 = Cubism::BlockSource.new(
44
- location: "#{template_tmp_path(template)}.html.erb:1",
45
- view_context: self
46
- ).digest
47
-
48
- digest2 = Cubism::BlockSource.new(
49
- location: "#{template_tmp_path(template)}.html.erb:2",
50
- view_context: self
51
- ).digest
52
-
53
- refute_equal digest1, digest2
54
- end
55
-
56
- test "can be created in the store by source location" do
57
- template = "fixtures/_cubicle_partial"
58
-
59
- assert_equal 0, Cubism.source_store.size
60
-
61
- Cubism::BlockSource.any_instance.expects(:parse!).once
62
-
63
- Cubism::BlockSource.find_or_create(
64
- location: "#{template_tmp_path(template)}.html.erb:1",
65
- view_context: self
66
- )
67
-
68
- assert_equal 1, Cubism.source_store.size
69
- end
70
-
71
- test "existing block source is returned and not parsed" do
72
- template = "fixtures/_cubicle_partial"
73
-
74
- instance = Cubism::BlockSource.new(
75
- location: "#{template_tmp_path(template)}.html.erb:1",
76
- view_context: self
77
- )
78
-
79
- Cubism.source_store[instance.digest] = instance
80
-
81
- assert_equal 1, Cubism.source_store.size
82
-
83
- Cubism::BlockSource.any_instance.expects(:parse!).never
84
-
85
- Cubism::BlockSource.find_or_create(
86
- location: "#{template_tmp_path(template)}.html.erb:1",
87
- view_context: self
88
- )
89
-
90
- assert_equal 1, Cubism.source_store.size
91
- end
92
-
93
- private
94
-
95
- def template_tmp_path(template)
96
- Pathname.new(@tmp_dir).join(template).to_path
97
- end
98
-
99
- def change_template(template)
100
- File.write("#{template}.html.erb", "\nTHIS WAS CHANGED!")
101
- end
102
- end