live_record 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -5
  3. data/.travis.yml +12 -0
  4. data/Gemfile +5 -1
  5. data/Gemfile.lock +199 -1
  6. data/README.md +38 -9
  7. data/app/assets/javascripts/live_record/plugins/live_dom.coffee +2 -3
  8. data/lib/live_record.rb +3 -0
  9. data/lib/live_record/.rspec +3 -0
  10. data/lib/live_record/{channel.rb → channel/implement.rb} +1 -4
  11. data/lib/live_record/config.ru +10 -0
  12. data/lib/live_record/generators/install_generator.rb +0 -6
  13. data/lib/live_record/generators/templates/live_record_channel.rb +1 -1
  14. data/lib/live_record/generators/templates/model.rb.rb +3 -0
  15. data/lib/live_record/model/callbacks.rb +36 -0
  16. data/lib/live_record/spec/factories/posts.rb +6 -0
  17. data/lib/live_record/spec/features/live_record_syncing_spec.rb +60 -0
  18. data/lib/live_record/spec/internal/app/assets/config/manifest.js +2 -0
  19. data/lib/live_record/spec/internal/app/assets/javascripts/application.js +17 -0
  20. data/lib/live_record/spec/internal/app/assets/javascripts/cable.js +12 -0
  21. data/lib/live_record/spec/internal/app/assets/javascripts/posts.coffee +14 -0
  22. data/lib/live_record/spec/internal/app/channels/application_cable/channel.rb +4 -0
  23. data/lib/live_record/spec/internal/app/channels/application_cable/connection.rb +8 -0
  24. data/lib/live_record/spec/internal/app/channels/live_record_channel.rb +4 -0
  25. data/lib/live_record/spec/internal/app/controllers/application_controller.rb +3 -0
  26. data/lib/live_record/spec/internal/app/controllers/posts_controller.rb +74 -0
  27. data/lib/live_record/spec/internal/app/models/application_record.rb +3 -0
  28. data/lib/live_record/spec/internal/app/models/live_record_update.rb +3 -0
  29. data/lib/live_record/spec/internal/app/models/post.rb +11 -0
  30. data/lib/live_record/spec/internal/app/views/layouts/application.html.erb +13 -0
  31. data/lib/live_record/spec/internal/app/views/posts/_form.html.erb +27 -0
  32. data/lib/live_record/spec/internal/app/views/posts/_post.json.jbuilder +2 -0
  33. data/lib/live_record/spec/internal/app/views/posts/edit.html.erb +6 -0
  34. data/lib/live_record/spec/internal/app/views/posts/index.html.erb +32 -0
  35. data/lib/live_record/spec/internal/app/views/posts/index.json.jbuilder +1 -0
  36. data/lib/live_record/spec/internal/app/views/posts/new.html.erb +5 -0
  37. data/lib/live_record/spec/internal/app/views/posts/show.html.erb +21 -0
  38. data/lib/live_record/spec/internal/app/views/posts/show.json.jbuilder +1 -0
  39. data/lib/live_record/spec/internal/config/cable.yml +8 -0
  40. data/lib/live_record/spec/internal/config/database.yml +3 -0
  41. data/lib/live_record/spec/internal/config/routes.rb +3 -0
  42. data/lib/live_record/spec/internal/db/schema.rb +16 -0
  43. data/lib/live_record/spec/internal/public/favicon.ico +0 -0
  44. data/lib/live_record/spec/rails_helper.rb +34 -0
  45. data/lib/live_record/spec/spec_helper.rb +12 -0
  46. data/lib/live_record/version.rb +1 -1
  47. data/live_record.gemspec +19 -3
  48. metadata +251 -8
  49. data/lib/live_record/model.rb +0 -36
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :posts
3
+ end
@@ -0,0 +1,16 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table "live_record_updates", force: :cascade do |t|
3
+ t.string "recordable_type"
4
+ t.integer "recordable_id"
5
+ t.datetime "created_at", null: false
6
+ t.index ["created_at"], name: "index_live_record_updates_on_created_at"
7
+ t.index ["recordable_type", "recordable_id"], name: "index_live_record_updates_on_recordable_type_and_recordable_id"
8
+ end
9
+
10
+ create_table "posts", force: :cascade do |t|
11
+ t.string "title"
12
+ t.text "content"
13
+ t.datetime "created_at", null: false
14
+ t.datetime "updated_at", null: false
15
+ end
16
+ end
File without changes
@@ -0,0 +1,34 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require 'spec_helper'
3
+
4
+ ActiveRecord::Migration.maintain_test_schema!
5
+
6
+ Capybara.javascript_driver = :selenium_chrome_headless
7
+ Capybara.server = :puma
8
+
9
+ RSpec.configure do |config|
10
+ config.include FactoryGirl::Syntax::Methods
11
+ config.include Capybara::DSL
12
+
13
+ config.use_transactional_fixtures = true
14
+ config.infer_spec_type_from_file_location!
15
+
16
+ config.filter_run focus: true
17
+ config.run_all_when_everything_filtered = true
18
+
19
+ config.before(:suite) do
20
+ DatabaseCleaner.strategy = :truncation
21
+ DatabaseCleaner.clean
22
+ DatabaseCleaner.strategy = :deletion
23
+ end
24
+
25
+ config.before(:each) do
26
+ DatabaseCleaner.start
27
+ DatabaseCleaner.clean
28
+ end
29
+
30
+ config.after(:suite) do
31
+ DatabaseCleaner.strategy = :truncation
32
+ DatabaseCleaner.clean
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+
3
+ Bundler.require :default, :development
4
+
5
+ require 'live_record'
6
+ require 'action_cable/engine'
7
+
8
+ Combustion.initialize! :all
9
+
10
+ require 'rspec/rails'
11
+ require 'capybara/rails'
12
+ require 'factory_girl_rails'
@@ -1,3 +1,3 @@
1
1
  module LiveRecord
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
data/live_record.gemspec CHANGED
@@ -13,8 +13,24 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.homepage = 'https://github.com/jrpolidario/live_record'
15
15
  s.license = 'MIT'
16
- s.required_ruby_version = '~> 2.0'
16
+ s.required_ruby_version = '~> 2.2'
17
17
 
18
- s.add_dependency 'rails', '~> 5.0', '< 5.2'
18
+ s.add_dependency 'rails', '>= 5.0.0', '< 5.2'
19
+
20
+ s.add_development_dependency 'bundler', '~> 1.3'
21
+ s.add_development_dependency 'rspec-rails', '~> 3.6'
22
+ s.add_development_dependency 'combustion', '~> 0.7'
19
23
  s.add_development_dependency 'byebug', '~> 9.0'
20
- end
24
+ s.add_development_dependency 'sqlite3', '~> 1.3'
25
+ s.add_development_dependency 'redis', '~> 3.3'
26
+ s.add_development_dependency 'puma', '~> 3.10'
27
+ s.add_development_dependency 'jquery-rails', '~> 4.3'
28
+ s.add_development_dependency 'sprockets-rails', '~> 3.2'
29
+ s.add_development_dependency 'coffee-rails', '~> 4.2'
30
+ s.add_development_dependency 'jbuilder', '~> 2.7'
31
+ s.add_development_dependency 'capybara', '~> 2.15'
32
+ s.add_development_dependency 'chromedriver-helper', '~> 1.1'
33
+ s.add_development_dependency 'selenium-webdriver', '~> 3.5'
34
+ s.add_development_dependency 'faker', '~> 1.8'
35
+ s.add_development_dependency 'database_cleaner', '~> 1.6'
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: live_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jules Roman B. Polidario
@@ -14,9 +14,9 @@ dependencies:
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: 5.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5.2'
@@ -24,12 +24,54 @@ dependencies:
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.0'
29
+ version: 5.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: combustion
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.7'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.7'
33
75
  - !ruby/object:Gem::Dependency
34
76
  name: byebug
35
77
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +86,174 @@ dependencies:
44
86
  - - "~>"
45
87
  - !ruby/object:Gem::Version
46
88
  version: '9.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: sqlite3
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.3'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.3'
103
+ - !ruby/object:Gem::Dependency
104
+ name: redis
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.3'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.3'
117
+ - !ruby/object:Gem::Dependency
118
+ name: puma
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.10'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.10'
131
+ - !ruby/object:Gem::Dependency
132
+ name: jquery-rails
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '4.3'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '4.3'
145
+ - !ruby/object:Gem::Dependency
146
+ name: sprockets-rails
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '3.2'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '3.2'
159
+ - !ruby/object:Gem::Dependency
160
+ name: coffee-rails
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '4.2'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '4.2'
173
+ - !ruby/object:Gem::Dependency
174
+ name: jbuilder
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '2.7'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '2.7'
187
+ - !ruby/object:Gem::Dependency
188
+ name: capybara
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '2.15'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '2.15'
201
+ - !ruby/object:Gem::Dependency
202
+ name: chromedriver-helper
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '1.1'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '1.1'
215
+ - !ruby/object:Gem::Dependency
216
+ name: selenium-webdriver
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '3.5'
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '3.5'
229
+ - !ruby/object:Gem::Dependency
230
+ name: faker
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: '1.8'
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: '1.8'
243
+ - !ruby/object:Gem::Dependency
244
+ name: database_cleaner
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '1.6'
250
+ type: :development
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - "~>"
255
+ - !ruby/object:Gem::Version
256
+ version: '1.6'
47
257
  description: |-
48
258
  Auto-syncs records in client-side JS (through a Model DSL) from changes in the backend Rails server through ActionCable.
49
259
  Auto-updates DOM elements mapped to a record attribute, from changes.
@@ -54,6 +264,7 @@ extensions: []
54
264
  extra_rdoc_files: []
55
265
  files:
56
266
  - ".gitignore"
267
+ - ".travis.yml"
57
268
  - Gemfile
58
269
  - Gemfile.lock
59
270
  - README.md
@@ -66,7 +277,9 @@ files:
66
277
  - app/assets/javascripts/live_record/plugins.js
67
278
  - app/assets/javascripts/live_record/plugins/live_dom.coffee
68
279
  - lib/live_record.rb
69
- - lib/live_record/channel.rb
280
+ - lib/live_record/.rspec
281
+ - lib/live_record/channel/implement.rb
282
+ - lib/live_record/config.ru
70
283
  - lib/live_record/engine.rb
71
284
  - lib/live_record/generators/install_generator.rb
72
285
  - lib/live_record/generators/templates/create_live_record_updates.rb
@@ -77,7 +290,37 @@ files:
77
290
  - lib/live_record/generators/templates/live_record_update.rb
78
291
  - lib/live_record/generators/templates/model.rb.rb
79
292
  - lib/live_record/generators/templates/show.html.erb
80
- - lib/live_record/model.rb
293
+ - lib/live_record/model/callbacks.rb
294
+ - lib/live_record/spec/factories/posts.rb
295
+ - lib/live_record/spec/features/live_record_syncing_spec.rb
296
+ - lib/live_record/spec/internal/app/assets/config/manifest.js
297
+ - lib/live_record/spec/internal/app/assets/javascripts/application.js
298
+ - lib/live_record/spec/internal/app/assets/javascripts/cable.js
299
+ - lib/live_record/spec/internal/app/assets/javascripts/posts.coffee
300
+ - lib/live_record/spec/internal/app/channels/application_cable/channel.rb
301
+ - lib/live_record/spec/internal/app/channels/application_cable/connection.rb
302
+ - lib/live_record/spec/internal/app/channels/live_record_channel.rb
303
+ - lib/live_record/spec/internal/app/controllers/application_controller.rb
304
+ - lib/live_record/spec/internal/app/controllers/posts_controller.rb
305
+ - lib/live_record/spec/internal/app/models/application_record.rb
306
+ - lib/live_record/spec/internal/app/models/live_record_update.rb
307
+ - lib/live_record/spec/internal/app/models/post.rb
308
+ - lib/live_record/spec/internal/app/views/layouts/application.html.erb
309
+ - lib/live_record/spec/internal/app/views/posts/_form.html.erb
310
+ - lib/live_record/spec/internal/app/views/posts/_post.json.jbuilder
311
+ - lib/live_record/spec/internal/app/views/posts/edit.html.erb
312
+ - lib/live_record/spec/internal/app/views/posts/index.html.erb
313
+ - lib/live_record/spec/internal/app/views/posts/index.json.jbuilder
314
+ - lib/live_record/spec/internal/app/views/posts/new.html.erb
315
+ - lib/live_record/spec/internal/app/views/posts/show.html.erb
316
+ - lib/live_record/spec/internal/app/views/posts/show.json.jbuilder
317
+ - lib/live_record/spec/internal/config/cable.yml
318
+ - lib/live_record/spec/internal/config/database.yml
319
+ - lib/live_record/spec/internal/config/routes.rb
320
+ - lib/live_record/spec/internal/db/schema.rb
321
+ - lib/live_record/spec/internal/public/favicon.ico
322
+ - lib/live_record/spec/rails_helper.rb
323
+ - lib/live_record/spec/spec_helper.rb
81
324
  - lib/live_record/version.rb
82
325
  - live_record.gemspec
83
326
  homepage: https://github.com/jrpolidario/live_record
@@ -92,7 +335,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
335
  requirements:
93
336
  - - "~>"
94
337
  - !ruby/object:Gem::Version
95
- version: '2.0'
338
+ version: '2.2'
96
339
  required_rubygems_version: !ruby/object:Gem::Requirement
97
340
  requirements:
98
341
  - - ">="
@@ -1,36 +0,0 @@
1
- module LiveRecord
2
- module Model
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- has_many :live_record_updates, as: :recordable
7
-
8
- after_update :__live_record_reference_changed_attributes__
9
- after_update_commit :__live_record_broadcast_record_update__
10
- after_destroy_commit :__live_record_broadcast_record_destroy__
11
-
12
- def self.live_record_whitelisted_attributes(record, current_user)
13
- []
14
- end
15
-
16
- private
17
-
18
- def __live_record_reference_changed_attributes__
19
- @_live_record_changed_attributes = changed
20
- end
21
-
22
- def __live_record_broadcast_record_update__
23
- included_attributes = attributes.slice(*@_live_record_changed_attributes)
24
- @_live_record_changed_attributes = nil
25
- message_data = { 'action' => 'update', 'attributes' => included_attributes }
26
- LiveRecordChannel.broadcast_to(self, message_data)
27
- LiveRecordUpdate.create!(recordable: self)
28
- end
29
-
30
- def __live_record_broadcast_record_destroy__
31
- message_data = { 'action' => 'destroy' }
32
- LiveRecordChannel.broadcast_to(self, message_data)
33
- end
34
- end
35
- end
36
- end