cable_ready 5.0.0.pre6 → 5.0.0.pre9

Sign up to get free protection for your applications and to get access to all the features.
data/rollup.config.js ADDED
@@ -0,0 +1,75 @@
1
+ import resolve from '@rollup/plugin-node-resolve'
2
+ import commonjs from '@rollup/plugin-commonjs'
3
+ import json from '@rollup/plugin-json'
4
+ import { terser } from 'rollup-plugin-terser'
5
+
6
+ const pretty = () => {
7
+ return terser({
8
+ mangle: false,
9
+ compress: false,
10
+ format: {
11
+ beautify: true,
12
+ indent_level: 2
13
+ }
14
+ })
15
+ }
16
+
17
+ const minify = () => {
18
+ return terser({
19
+ mangle: true,
20
+ compress: true
21
+ })
22
+ }
23
+
24
+ const esConfig = {
25
+ format: 'es',
26
+ inlineDynamicImports: true
27
+ }
28
+
29
+ const umdConfig = {
30
+ name: 'CableReady',
31
+ format: 'umd',
32
+ exports: 'named',
33
+ globals: { morphdom: 'morphdom' }
34
+ }
35
+
36
+ const distFolders = ['dist/', 'app/assets/javascripts/']
37
+
38
+ const output = distFolders
39
+ .map(distFolder => [
40
+ {
41
+ ...esConfig,
42
+ file: `${distFolder}/cable_ready.js`,
43
+ plugins: [pretty()]
44
+ },
45
+ {
46
+ ...esConfig,
47
+ file: `${distFolder}/cable_ready.min.js`,
48
+ sourcemap: true,
49
+ plugins: [minify()]
50
+ },
51
+ {
52
+ ...umdConfig,
53
+ file: `${distFolder}/cable_ready.umd.js`,
54
+ plugins: [pretty()]
55
+ },
56
+ {
57
+ ...umdConfig,
58
+ file: `${distFolder}/cable_ready.umd.min.js`,
59
+ sourcemap: true,
60
+ plugins: [minify()]
61
+ }
62
+ ])
63
+ .flat()
64
+
65
+ export default [
66
+ {
67
+ external: ['morphdom'],
68
+ input: 'javascript/index.js',
69
+ output,
70
+ plugins: [commonjs(), resolve(), json()],
71
+ watch: {
72
+ include: 'javascript/**'
73
+ }
74
+ }
75
+ ]
@@ -0,0 +1,4 @@
1
+ class Dugong < ApplicationRecord
2
+ include CableReady::Updatable
3
+ has_many_attached :images, enable_updates: true
4
+ end
@@ -0,0 +1,8 @@
1
+ class CreateDugongs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :dugongs do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ # This migration comes from active_storage (originally 20170806125915)
2
+ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
3
+ def change
4
+ create_table :active_storage_blobs do |t|
5
+ t.string :key, null: false
6
+ t.string :filename, null: false
7
+ t.string :content_type
8
+ t.text :metadata
9
+ t.string :service_name, null: false
10
+ t.bigint :byte_size, null: false
11
+ t.string :checksum, null: false
12
+ t.datetime :created_at, null: false
13
+
14
+ t.index [ :key ], unique: true
15
+ end
16
+
17
+ create_table :active_storage_attachments do |t|
18
+ t.string :name, null: false
19
+ t.references :record, null: false, polymorphic: true, index: false
20
+ t.references :blob, null: false
21
+
22
+ t.datetime :created_at, null: false
23
+
24
+ t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
25
+ t.foreign_key :active_storage_blobs, column: :blob_id
26
+ end
27
+
28
+ create_table :active_storage_variant_records do |t|
29
+ t.belongs_to :blob, null: false, index: false
30
+ t.string :variation_digest, null: false
31
+
32
+ t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
33
+ t.foreign_key :active_storage_blobs, column: :blob_id
34
+ end
35
+ end
36
+ end
@@ -10,7 +10,40 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2021_09_13_191759) do
13
+ ActiveRecord::Schema.define(version: 2022_03_29_230221) do
14
+
15
+ create_table "active_storage_attachments", force: :cascade do |t|
16
+ t.string "name", null: false
17
+ t.string "record_type", null: false
18
+ t.integer "record_id", null: false
19
+ t.integer "blob_id", null: false
20
+ t.datetime "created_at", null: false
21
+ t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
22
+ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
23
+ end
24
+
25
+ create_table "active_storage_blobs", force: :cascade do |t|
26
+ t.string "key", null: false
27
+ t.string "filename", null: false
28
+ t.string "content_type"
29
+ t.text "metadata"
30
+ t.string "service_name", null: false
31
+ t.bigint "byte_size", null: false
32
+ t.string "checksum", null: false
33
+ t.datetime "created_at", null: false
34
+ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
35
+ end
36
+
37
+ create_table "active_storage_variant_records", force: :cascade do |t|
38
+ t.integer "blob_id", null: false
39
+ t.string "variation_digest", null: false
40
+ t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
41
+ end
42
+
43
+ create_table "dugongs", force: :cascade do |t|
44
+ t.datetime "created_at", precision: 6, null: false
45
+ t.datetime "updated_at", precision: 6, null: false
46
+ end
14
47
 
15
48
  create_table "posts", force: :cascade do |t|
16
49
  t.string "title"
@@ -45,5 +78,7 @@ ActiveRecord::Schema.define(version: 2021_09_13_191759) do
45
78
  t.index ["team_id"], name: "index_users_on_team_id"
46
79
  end
47
80
 
81
+ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
82
+ add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
48
83
  add_foreign_key "posts", "users"
49
84
  end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class DugongTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -13,7 +13,7 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
13
13
  test "updates the collection when an item is added" do
14
14
  mock_server = mock("server")
15
15
  mock_server.expects(:broadcast).with(User, {}).once
16
- mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
16
+ mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {changed: ["id", "title", "user_id", "created_at", "updated_at"]}).once
17
17
 
18
18
  ActionCable.stubs(:server).returns(mock_server)
19
19
  user = User.create(name: "John Doe")
@@ -26,7 +26,7 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
26
26
  post = user.posts.create(title: "Lorem")
27
27
 
28
28
  mock_server = mock("server")
29
- mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
29
+ mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {changed: ["id", "title", "user_id", "created_at", "updated_at"]}).once
30
30
 
31
31
  ActionCable.stubs(:server).returns(mock_server)
32
32
 
@@ -38,7 +38,7 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
38
38
  post = user.posts.create(title: "Lorem")
39
39
 
40
40
  mock_server = mock("server")
41
- mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
41
+ mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {changed: ["title", "updated_at"]}).once
42
42
 
43
43
  ActionCable.stubs(:server).returns(mock_server)
44
44
 
@@ -50,7 +50,7 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
50
50
 
51
51
  mock_server = mock("server")
52
52
  mock_server.expects(:broadcast).with(User, {}).once
53
- mock_server.expects(:broadcast).with(user.to_global_id, {}).once
53
+ mock_server.expects(:broadcast).with(user.to_global_id, {changed: ["name", "updated_at"]}).once
54
54
 
55
55
  ActionCable.stubs(:server).returns(mock_server)
56
56
 
@@ -63,10 +63,10 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
63
63
 
64
64
  mock_server = mock("server")
65
65
  mock_server.expects(:broadcast).with(User, {}).once
66
- mock_server.expects(:broadcast).with(user.to_global_id, {}).once
67
- mock_server.expects(:broadcast).with("gid://dummy/Team/1:users", {}).once
66
+ mock_server.expects(:broadcast).with(user.to_global_id, {changed: ["name", "updated_at"]}).once
67
+ mock_server.expects(:broadcast).with("gid://dummy/Team/1:users", {changed: ["name", "updated_at"]}).once
68
68
  mock_server.expects(:broadcast).with(Team, {}).once
69
- mock_server.expects(:broadcast).with(team.to_global_id, {}).once
69
+ mock_server.expects(:broadcast).with(team.to_global_id, {changed: ["id", "created_at", "updated_at"]}).once
70
70
 
71
71
  ActionCable.stubs(:server).returns(mock_server)
72
72
 
@@ -94,7 +94,7 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
94
94
  section.updates_enabled = true
95
95
 
96
96
  mock_server.expects(:broadcast).with(Section, {}).once
97
- mock_server.expects(:broadcast).with(section.to_global_id, {}).once
97
+ mock_server.expects(:broadcast).with(section.to_global_id, {changed: ["title", "updated_at", "updates_enabled"]}).once
98
98
  section.update(title: "First Section")
99
99
  end
100
100
 
@@ -109,4 +109,27 @@ class CableReady::UpdatableTest < ActiveSupport::TestCase
109
109
 
110
110
  entity.fake_update
111
111
  end
112
+
113
+ test "updates the collection when a file is attached" do
114
+ mock_server = mock("server")
115
+ image = File.open(Rails.root.join("test", "fixtures", "files", "dugong.jpg"))
116
+ dugong = Dugong.create
117
+
118
+ mock_server.expects(:broadcast).with("gid://dummy/Dugong/1:images", {changed: ["id", "name", "record_type", "record_id", "blob_id", "created_at"]}).once
119
+ ActionCable.stubs(:server).returns(mock_server)
120
+
121
+ dugong.images.attach(io: image, filename: "dugong.jpg")
122
+ end
123
+
124
+ test "updates the collection when a file is destroyed" do
125
+ mock_server = mock("server")
126
+ image = File.open(Rails.root.join("test", "fixtures", "files", "dugong.jpg"))
127
+ dugong = Dugong.create
128
+ dugong.images.attach(io: image, filename: "dugong.jpg")
129
+
130
+ mock_server.expects(:broadcast).with("gid://dummy/Dugong/1:images", {changed: ["id", "name", "record_type", "record_id", "blob_id", "created_at"]}).once
131
+ ActionCable.stubs(:server).returns(mock_server)
132
+
133
+ dugong.images.first.destroy
134
+ end
112
135
  end