fie 0.1.11 → 0.1.12

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
  SHA1:
3
- metadata.gz: a738ba65dca90aa1244891e027b009a844f57c12
4
- data.tar.gz: cc3ce83b850b2511f0b3d6bc2577d2adf2f61a75
3
+ metadata.gz: d9fa60a840aea7f3c1a20c4d9cf697a435eded6e
4
+ data.tar.gz: 905bbd23714728292dd2695fe751ba8adc6d14a5
5
5
  SHA512:
6
- metadata.gz: c6f600905946799d535a638d77321f6291793f3fc901c848ccb83f6b350b7b05800358aa18a81def2f68f7d895385ffb3b1d2e473583e353525089e594b16695
7
- data.tar.gz: aa87a41952290b08012b7151ab07ec649925194a35c756fec4beed3593c85b70eb9319d53ac4ff3afd7c53ce860825c2d75fb6858cc3eed25b5c08d60cbe367d
6
+ metadata.gz: 8f68682ec79d4717894098c6657d18eb1db5be2b5c40320ac431373f1847f44a35dc13bdcbc31ac17b0f81c9b3fd5c0a3235b19ca6308e1880c58d8344952a81
7
+ data.tar.gz: 4edd883ba3fc1fdf442cd89a834f9a053b18312415d4e69ba1fefc4fd3b861d07faef1fb1ab95ee42a16e8346cdea647b3ac221a1c3dbbfb7c95cb7fd1ff0458
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # <a href="https://fie.eranpeer.co/" target="_blank"><img src="https://image.ibb.co/c0JaA8/github_fie.jpg" height="200" /></a>
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/fie.svg)](https://badge.fury.io/rb/fie)
4
+ [![Build Status](https://travis-ci.org/raen79/fie.svg?branch=master)](https://travis-ci.org/raen79/fie)
4
5
  [![CodeFactor](https://www.codefactor.io/repository/github/raen79/fie/badge)](https://www.codefactor.io/repository/github/raen79/fie)
5
6
  [![Join the chat at https://gitter.im/rails-fie/Lobby](https://badges.gitter.im/rails-fie/Lobby.svg)](https://gitter.im/rails-fie/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
- [![GitHub license](https://img.shields.io/github/license/raen79/fie.svg)](https://github.com/raen79/fie/blob/master/LICENSE)
7
7
  [![Beerpay](https://beerpay.io/raen79/fie/badge.svg?style=beer-square)](https://beerpay.io/raen79/fie)
8
8
 
9
9
  ### Fie is a Rails-centric frontend framework running over a permanent WebSocket connection.
@@ -104,7 +104,7 @@ The project does not use javascript, but opal. To build the opal project (in `li
104
104
 
105
105
  To transfer gems and node packages to opal, add `Opal.use_gem(gem_name)` or `Opal.append_path('./node_modules/module_name/dist')` in the Rakefile within the `build_opal` task.
106
106
 
107
- The ruby files can be found within `lib\opal` and their development is the same as in any other gem.
107
+ The ruby files can be found within `lib/fie` and their development is the same as in any other gem.
108
108
 
109
109
  Please add tests if you add new features or resolve bugs.
110
110
 
@@ -20,13 +20,6 @@ module Fie
20
20
  uuid: self.params[:identifier]
21
21
  end
22
22
 
23
- def handle_pool_callbacks(params)
24
- subject = params['subject']
25
- object = Marshal.load(params['object'])
26
-
27
- run_hook :"#{subject}_pool", object
28
- end
29
-
30
23
  def unsubscribed
31
24
  redis.del Fie::Commander.commander_name(params[:identifier])
32
25
  end
@@ -72,7 +65,7 @@ module Fie
72
65
  @@pools_subjects.add(subject)
73
66
 
74
67
  pool_name = Fie::Pools.pool_name(subject)
75
- define_method("#{pool_name}_callback") do |object:|
68
+ define_method("#{ pool_name }_callback") do |object:|
76
69
  @published_object = Marshal.load(object)
77
70
  instance_eval(&block)
78
71
  end
@@ -83,7 +76,15 @@ module Fie
83
76
  end
84
77
 
85
78
  def method_added(name)
86
- super_commander_method_names = [:subscribed, :refresh_view, :identifier, :state, :unsubscribed, :modify_state_using_changelog]
79
+ super_commander_method_names = [
80
+ :subscribed,
81
+ :refresh_view,
82
+ :identifier,
83
+ :state,
84
+ :unsubscribed,
85
+ :modify_state_using_changelog,
86
+ :execute_js_function
87
+ ]
87
88
 
88
89
  unless @@disable_override || super_commander_method_names.include?(name)
89
90
  @@disable_override = true
@@ -99,7 +100,7 @@ module Fie
99
100
  alias_method("sub_#{name}", name)
100
101
  remove_method(name)
101
102
  define_method(name) do |params|
102
- @caller = params['caller'].symbolize_keys
103
+ @caller = params['caller'].symbolize_keys if params['caller']
103
104
  @controller_name = params['controller_name']
104
105
  @action_name = params['action_name']
105
106
  @connection_uuid = self.params['identifier']
@@ -58,7 +58,7 @@ module Fie
58
58
  redis.set Fie::Commander.commander_name(@uuid), Marshal.dump(self)
59
59
 
60
60
  rendered_view = ApplicationController.render \
61
- "#{@controller_name}/#{@action_name}",
61
+ "#{ @controller_name }/#{ @action_name }",
62
62
  assigns: attributes.merge(fie_controller_name: @controller_name, fie_action_name: @action_name),
63
63
  layout: 'fie'
64
64
 
@@ -1,3 +1,3 @@
1
1
  module Fie
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
@@ -28,7 +28,7 @@ module Fie
28
28
  parameters['subjects'].each do |subject|
29
29
  @cable.subscribe_to_pool(subject)
30
30
  end
31
- when 'publish_to_pools'
31
+ when 'publish_to_pool'
32
32
  subject = parameters['subject']
33
33
  object = parameters['object']
34
34
 
@@ -36,7 +36,7 @@ module Fie
36
36
  when 'execute_function'
37
37
  Util.exec_js(parameters['name'], parameters['arguments'])
38
38
  else
39
- console.log("Command: #{ command }, Parameters: #{ parameters }")
39
+ puts "Command: #{ command }, Parameters: #{ parameters }"
40
40
  end
41
41
  end
42
42
  end
@@ -0,0 +1,3 @@
1
+ RSpec.describe Fie::Commander do
2
+
3
+ end
@@ -0,0 +1,173 @@
1
+ RSpec.describe Fie::State do
2
+ before do
3
+ credentials = {
4
+ secret_key_base: 'c2c3f440e947a5592acaad052e756d87dd8db717275ef14ac794a3c2a07cbdaec8aa0df7a090c1bc83833736ee3f5209affe55639845871081d48598d57de3f7'
5
+ }
6
+
7
+ allow(Rails.application).to receive(:credentials) { credentials }
8
+
9
+ @unencrypted_variables = {
10
+ users: [
11
+ { name: 'eran', age: '20' },
12
+ User.new(name: 'eran', age: '20'),
13
+ '120'
14
+ ],
15
+ primitive: '120',
16
+ hash: {
17
+ array: [1, 2, 3],
18
+ primitive: '120'
19
+ }
20
+ }
21
+ end
22
+
23
+ let(:view_variables) do
24
+ @unencrypted_variables.map do |key, value|
25
+ [key, encrypt(value)]
26
+ end.to_h
27
+ end
28
+
29
+ let(:controller_name) { 'home_controller' }
30
+ let(:action_name) { 'index' }
31
+ let(:uuid) { SecureRandom.uuid }
32
+ let(:attributes) { nil }
33
+
34
+ let(:state) do
35
+ Fie::State.new \
36
+ view_variables: view_variables,
37
+ controller_name: controller_name,
38
+ action_name: action_name,
39
+ uuid: uuid,
40
+ attributes: attributes
41
+ end
42
+
43
+ subject { state }
44
+
45
+ context "when view_variables == #{ @unencrypted_variables.to_json }" do
46
+ [:users, :primitive, :hash].each do |variable_name|
47
+ it { is_expected.to respond_to(variable_name) }
48
+ it { is_expected.to respond_to("#{ variable_name }=") }
49
+ end
50
+
51
+ describe 'marshalling' do
52
+ let(:marshalled) { Marshal.dump state }
53
+ let(:unmarshalled) { Marshal.load marshalled }
54
+
55
+ subject { unmarshalled.attributes.to_json }
56
+
57
+ it { is_expected.to eq(state.attributes.to_json) }
58
+ end
59
+
60
+ describe 'permeate' do
61
+ it 'should render an html template which is then sent over action cable' do
62
+ expect(ApplicationController).to receive(:render).with(
63
+ "#{ controller_name }/#{ action_name }",
64
+ assigns: state.attributes.merge(fie_controller_name: controller_name, fie_action_name: action_name),
65
+ layout: 'fie'
66
+ ).and_return('long HTML string')
67
+
68
+ expect(ActionCable.server).to receive(:broadcast).with \
69
+ "commander_#{ uuid }",
70
+ command: 'refresh_view',
71
+ parameters: {
72
+ html: 'long HTML string'
73
+ }
74
+
75
+ state.permeate
76
+ end
77
+ end
78
+
79
+ describe '`hash`' do
80
+ before { expect(state).to receive(:permeate) }
81
+
82
+ context 'when setting value' do
83
+ subject { state.hash }
84
+ let!(:change_value) { state.hash = 'value' }
85
+
86
+ it { is_expected.to eq('value') }
87
+ end
88
+
89
+ context 'when deleting value' do
90
+ let(:delete_value) { state.hash.delete :primitive }
91
+ it { expect { delete_value }.to change { state.hash.count }.by(-1) }
92
+ end
93
+
94
+ describe 'primitive' do
95
+ context 'when setting value' do
96
+ subject { state.hash[:primitive] }
97
+ let!(:change_hash_value) { state.hash[:primitive] = 'value' }
98
+
99
+ it { is_expected.to eq('value') }
100
+ end
101
+ end
102
+ end
103
+
104
+ describe '`users`' do
105
+ before { expect(state).to receive(:permeate) }
106
+
107
+ context 'when setting value' do
108
+ subject { state.users }
109
+ let!(:change_value) { state.users = 'value' }
110
+
111
+ it { is_expected.to eq('value') }
112
+ end
113
+
114
+ describe 'first index' do
115
+ context 'when setting value' do
116
+ subject { state.users[0] }
117
+ let!(:change_array_value) { state.users[0] = 'value' }
118
+
119
+ it { is_expected.to eq('value') }
120
+ end
121
+
122
+ describe 'name attribute' do
123
+ context 'when setting value' do
124
+ subject { state.users[0][:name] }
125
+ let!(:change_hash_value) { state.users[0][:name] = 'value' }
126
+
127
+ it { expect(state.users[0][:name]).to eq('value') }
128
+ end
129
+ end
130
+
131
+ context 'when appending' do
132
+ let(:append1) { state.users << 'value' }
133
+ let(:append2) { state.users.push('value') }
134
+
135
+ it { expect { append1 }.to change { state.users.count }.by(1) }
136
+ it { expect { append2 }.to change { state.users.count }.by(1) }
137
+ end
138
+
139
+ context 'when deleting a value' do
140
+ let(:delete_value) { state.users.delete '120' }
141
+ it { expect { delete_value }.to change { state.users.count }.by(-1) }
142
+ end
143
+
144
+ context 'when deleting an index' do
145
+ let(:delete_value) { state.users.delete_at 1 }
146
+ it { expect { delete_value }.to change { state.users.count }.by(-1) }
147
+ end
148
+ end
149
+ end
150
+
151
+ describe 'attributes' do
152
+ describe 'users' do
153
+ subject { state.attributes['users'] }
154
+
155
+ it { is_expected.to include a_hash_including(name: 'eran', age: '20') }
156
+ it { is_expected.to include an_object_having_attributes(name: 'eran', age: '20') }
157
+ it { is_expected.to include '120' }
158
+ end
159
+
160
+ describe 'primitive' do
161
+ subject { state.attributes['primitive'] }
162
+ it { is_expected.to eq('120') }
163
+ end
164
+
165
+ describe 'hash' do
166
+ subject { state.attributes['hash'] }
167
+
168
+ it { is_expected.to include(array: [1, 2, 3]) }
169
+ it { is_expected.to include(primitive: '120') }
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,37 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+ require File.expand_path('../../config/environment', __FILE__)
6
+ # Prevent database truncation if the environment is production
7
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
8
+ require 'rspec/rails'
9
+
10
+ Dir['./spec/fie/*_spec.rb'].each {|file| require file }
11
+ Dir['./spec/support/*.rb'].each {|file| require file }
12
+ Dir['./spec/test_controllers/*.rb'].each {|file| require file }
13
+ Dir['./spec/test_models/*.rb'].each {|file| require file }
14
+
15
+ RSpec.configure do |config|
16
+ config.include HelperMethods
17
+
18
+ # RSpec Rails can automatically mix in different behaviours to your tests
19
+ # based on their file location, for example enabling you to call `get` and
20
+ # `post` in specs under `spec/controllers`.
21
+ #
22
+ # You can disable this behaviour by removing the line below, and instead
23
+ # explicitly tag your specs with their type, e.g.:
24
+ #
25
+ # RSpec.describe UsersController, :type => :controller do
26
+ # # ...
27
+ # end
28
+ #
29
+ # The different available types are documented in the features, such as in
30
+ # https://relishapp.com/rspec/rspec-rails/docs
31
+ config.infer_spec_type_from_file_location!
32
+
33
+ # Filter lines from Rails gems in backtraces.
34
+ config.filter_rails_from_backtrace!
35
+ # arbitrary gems may also be filtered via:
36
+ # config.filter_gems_from_backtrace("gem name")
37
+ end
@@ -0,0 +1,97 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
42
+ # have no way to turn it off -- the option exists only for backwards
43
+ # compatibility in RSpec 3). It causes shared context metadata to be
44
+ # inherited by the metadata hash of host groups and examples, rather than
45
+ # triggering implicit auto-inclusion in groups with matching metadata.
46
+ config.shared_context_metadata_behavior = :apply_to_host_groups
47
+
48
+ # The settings below are suggested to provide a good initial experience
49
+ # with RSpec, but feel free to customize to your heart's content.
50
+ =begin
51
+ # This allows you to limit a spec run to individual examples or groups
52
+ # you care about by tagging them with `:focus` metadata. When nothing
53
+ # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ config.filter_run_when_matching :focus
57
+
58
+ # Allows RSpec to persist some state between runs in order to support
59
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # you configure your source control system to ignore this file.
61
+ config.example_status_persistence_file_path = "spec/examples.txt"
62
+
63
+ # Limits the available syntax to the non-monkey patched syntax that is
64
+ # recommended. For more details, see:
65
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ config.disable_monkey_patching!
69
+
70
+ # Many RSpec users commonly either run the entire suite or an individual
71
+ # file, and it's useful to allow more verbose output when running an
72
+ # individual spec file.
73
+ if config.files_to_run.one?
74
+ # Use the documentation formatter for detailed output,
75
+ # unless a formatter has already been configured
76
+ # (e.g. via a command-line flag).
77
+ config.default_formatter = "doc"
78
+ end
79
+
80
+ # Print the 10 slowest examples and example groups at the
81
+ # end of the spec run, to help surface which specs are running
82
+ # particularly slow.
83
+ config.profile_examples = 10
84
+
85
+ # Run specs in random order to surface order dependencies. If you find an
86
+ # order dependency and want to debug it, you can fix the order by providing
87
+ # the seed, which is printed after each run.
88
+ # --seed 1234
89
+ config.order = :random
90
+
91
+ # Seed global randomization in this process using the `--seed` CLI option.
92
+ # Setting this allows you to use `--seed` to deterministically reproduce
93
+ # test failures related to randomization by passing the same `--seed` value
94
+ # as the one that triggered the failure.
95
+ Kernel.srand config.seed
96
+ =end
97
+ end
@@ -0,0 +1,13 @@
1
+ module HelperMethods
2
+ def encryptor
3
+ ActiveSupport::MessageEncryptor.new Rails.application.credentials[:secret_key_base]
4
+ end
5
+
6
+ def encrypt(value)
7
+ encryptor.encrypt_and_sign Marshal.dump(value)
8
+ end
9
+
10
+ def decrypt(value)
11
+ Marshal.load encryptor.decrypt_and_verify(value)
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationController
2
+ def self.render(action, assigns:, layout:)
3
+ end
4
+ end