fie 0.2.0pa → 0.2.0

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
  SHA1:
3
- metadata.gz: 525be6f875d908a5fa3aea8f38ec53b0e0a9d830
4
- data.tar.gz: eedbc74097abd96cb5d0613df91884a557967b35
3
+ metadata.gz: 7c87d695d7cd5206d5dee85232552bf7f624b5db
4
+ data.tar.gz: 97648f74d8dca1744483ecdb16fe552af3ebcdf8
5
5
  SHA512:
6
- metadata.gz: e9d7e196dae681efca4141c6fa362ade681bcdb8327371f36a7e057a2a06284f7238ff88321f737fee47678c2e2a8c705d4faefd24a6fee83482d15167047ef1
7
- data.tar.gz: 58b5470a2d2cc762e28847633b8492c61b4f6caa197404d61ebc8008571e5bd6756bb6e92704c2bbc048a734ef5681a6cfaf1a00d8356c03bde93b636ace6bf0
6
+ metadata.gz: 6dc2b0185bcd909e5776be527fa076388c92d8cea891d91c4bb26d8c9c18aa2f105f2bb00053b64b770d191b37a1ccd082c6a0caaa7792062efa38841bb85a4f
7
+ data.tar.gz: 38030add9ee2db0cda45bdecf529aa3935d1dc9969d09a762d002600b110ec019d1ac1bf4ebc663116c87cdfe968efdc2206fe330f9bea449266841673ebb9d1
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/fie.svg)](https://badge.fury.io/rb/fie)
4
4
  [![Build Status](https://travis-ci.org/raen79/fie.svg?branch=master)](https://travis-ci.org/raen79/fie)
5
- [![CodeFactor](https://www.codefactor.io/repository/github/raen79/fie/badge)](https://www.codefactor.io/repository/github/raen79/fie)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/68db9a94db4b3f028cec/maintainability)](https://codeclimate.com/github/raen79/fie/maintainability)
6
+ [![Coverage Status](https://coveralls.io/repos/github/raen79/fie/badge.svg?branch=master)](https://coveralls.io/github/raen79/fie?branch=master)
6
7
  [![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)
7
8
  [![Beerpay](https://beerpay.io/raen79/fie/badge.svg?style=beer-square)](https://beerpay.io/raen79/fie)
8
9
 
@@ -20,7 +21,7 @@ fie therefore replaces traditional Javascript frontend frameworks while requirin
20
21
 
21
22
  1. Add the gem to your gemfile like so:
22
23
  ```ruby
23
- gem 'fie', '~> 0.1.14'
24
+ gem 'fie', '~> 0.2.0'
24
25
  ```
25
26
  2. Run the bundler
26
27
  ```bash
data/lib/fie.rb CHANGED
@@ -2,4 +2,5 @@ module Fie
2
2
  require 'fie/railtie'
3
3
  require 'fie/commander'
4
4
  require 'fie/manipulator'
5
+ require 'fie/pools'
5
6
  end
data/lib/fie/commander.rb CHANGED
@@ -33,7 +33,7 @@ module Fie
33
33
  end
34
34
 
35
35
  def publish(subject, object)
36
- Fie::Pools.publish_lazy(subject, object, @connection_uuid)
36
+ Fie::Pools.publish_lazy(subject, object, params[:identifier])
37
37
  end
38
38
 
39
39
  def state
@@ -63,12 +63,20 @@ module Fie
63
63
  $redis ||= Redis.new
64
64
  end
65
65
 
66
+ def method_keywords_hash(method_name, params)
67
+ method(method_name).parameters.map do |_, parameter_name|
68
+ [parameter_name, params[parameter_name.to_s]]
69
+ end.to_h
70
+ end
71
+
66
72
  class << self
67
73
  def pool(subject, &block)
68
74
  @@pools_subjects.add(subject)
69
75
 
70
76
  pool_name = Fie::Pools.pool_name(subject)
71
- define_method("#{ pool_name }_callback") do |object:, sender_uuid:, lazy: false|
77
+ define_method("#{ pool_name }_callback") do |object:, sender_uuid: nil, lazy: false|
78
+ @connection_uuid = self.params['identifier']
79
+
72
80
  unless @connection_uuid == sender_uuid
73
81
  @published_object = Marshal.load(object)
74
82
  instance_eval(&block)
@@ -81,7 +89,7 @@ module Fie
81
89
  end
82
90
 
83
91
  def commander_name(connection_uuid)
84
- "commander_#{connection_uuid}"
92
+ "commander_#{ connection_uuid }"
85
93
  end
86
94
 
87
95
  def method_added(name)
@@ -107,11 +115,14 @@ module Fie
107
115
  end
108
116
 
109
117
  private
110
- def restructure_subclass_method_parameters(name)
111
- alias_method("sub_#{name}", name)
112
- remove_method(name)
113
- define_method(name) do |params|
114
- @caller = params['caller'].symbolize_keys if params['caller']
118
+ def restructure_subclass_method_parameters(method_name)
119
+ alias_method("sub_#{ method_name }", method_name)
120
+ remove_method(method_name)
121
+ define_method(method_name) do |params|
122
+ if caller = params['caller']
123
+ @caller = { value: caller['value'], id: caller['id'], class: caller['class'] }
124
+ end
125
+
115
126
  @controller_name = params['controller_name']
116
127
  @action_name = params['action_name']
117
128
  @connection_uuid = self.params['identifier']
@@ -119,9 +130,10 @@ module Fie
119
130
  ['caller', 'action', 'controller_name', 'action_name'].each { |param| params.delete param }
120
131
 
121
132
  if params.blank?
122
- self.send(:"sub_#{name}")
133
+ self.send(:"sub_#{ method_name }")
123
134
  else
124
- self.send(:"sub_#{name}", params.symbolize_keys)
135
+ method_keywords_hash = method_keywords_hash(:"sub_#{ method_name }", params)
136
+ self.send(:"sub_#{ method_name }", method_keywords_hash)
125
137
  end
126
138
  end
127
139
  end
data/lib/fie/pools.rb CHANGED
@@ -6,7 +6,7 @@ module Fie
6
6
 
7
7
  class << self
8
8
  def pool_name(subject)
9
- "pool_#{subject}"
9
+ "pool_#{ subject }"
10
10
  end
11
11
 
12
12
  def publish_lazy(subject, object, sender_uuid)
@@ -15,8 +15,7 @@ module Fie
15
15
  command: 'publish_to_pool_lazy',
16
16
  parameters: {
17
17
  subject: subject,
18
- object: Marshal.dump(object),
19
- sender_uuid: nil
18
+ object: Marshal.dump(object)
20
19
  }
21
20
  end
22
21
 
data/lib/fie/state.rb CHANGED
@@ -37,16 +37,16 @@ module Fie
37
37
 
38
38
  def inspect
39
39
  object_reference = self.to_s
40
- pretty_print = "\e[0;33m#{object_reference[0..-2]}\e[0m "
40
+ pretty_print = "\e[0;33m#{ object_reference[0..-2] }\e[0m "
41
41
 
42
42
  attributes.each do |name, value|
43
43
  if value.is_a? String
44
- value = "\e[0;31m#{value.inspect}\e[0m"
44
+ value = "\e[0;31m#{ value.inspect }\e[0m"
45
45
  else
46
- value = "\e[1;34m#{value.inspect}\e[0m"
46
+ value = "\e[1;34m#{ value.inspect }\e[0m"
47
47
  end
48
48
 
49
- pretty_print += "\n #{name}: #{value}"
49
+ pretty_print += "\n #{ name }: #{ value }"
50
50
  end
51
51
 
52
52
  pretty_print += '>'
@@ -15,7 +15,7 @@ module Fie
15
15
  else
16
16
  update_object_value \
17
17
  object: object,
18
- node_name:node_name,
18
+ node_name: node_name,
19
19
  value: changelog_node
20
20
  end
21
21
  end
@@ -35,7 +35,7 @@ module Fie
35
35
  object_node = object[node_name]
36
36
  elsif symbol_in_hash
37
37
  object_node = object[node_name.to_sym]
38
- end
38
+ end
39
39
  else
40
40
  object_node = object.send(node_name)
41
41
  end
@@ -45,7 +45,7 @@ module Fie
45
45
 
46
46
  def update_object_value(object:, node_name:, value:)
47
47
  if object.is_a?(Array)
48
- node_name = node_name.to_i if object.is_a?(Array)
48
+ node_name = node_name.to_i
49
49
  object[node_name] = value
50
50
  elsif object.is_a?(Hash)
51
51
  string_in_hash = object.keys.include? node_name
data/lib/fie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fie
2
- VERSION = '0.2.0pa'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,8 +1,8 @@
1
1
  <span fie-body='true'>
2
2
  <%= yield %>
3
3
 
4
- <% assigns.symbolize_keys.map do |assigns_name, assigns_value| %>
5
- <% unless assigns_value.blank? || assigns_name == :marked_for_same_origin_verification %>
4
+ <% assigns.map do |assigns_name, assigns_value| %>
5
+ <% unless assigns_value.nil? || assigns_name == :marked_for_same_origin_verification %>
6
6
  <% encryptor = ActiveSupport::MessageEncryptor.new Rails.application.credentials[:secret_key_base] %>
7
7
  <span fie-variable='<%= assigns_name %>' fie-value='<%= encryptor.encrypt_and_sign Marshal.dump(assigns_value) %>'></span>
8
8
  <% end %>
@@ -0,0 +1,76 @@
1
+ RSpec.describe Fie::Changelog 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
+ context "when view_variables == #{ @unencrypted_variables.to_json }" do
44
+ describe '#update_object_using_changelog' do
45
+ subject { state.update_object_using_changelog(changelog) }
46
+
47
+ context 'when changelog == { "users" => { 0 => { "name" => "New Name" } } }' do
48
+ let(:changelog) do
49
+ {
50
+ 'users' => {
51
+ 0 => {
52
+ 'name' => 'New Name'
53
+ }
54
+ }
55
+ }
56
+ end
57
+
58
+ it { expect { subject }.to change { state.users[0][:name] }.from('eran').to('New Name') }
59
+ end
60
+
61
+ context 'when changelog == { "hash" => { "array" => { 1 => 5 } }' do
62
+ let(:changelog) do
63
+ {
64
+ 'hash' => {
65
+ 'array' => {
66
+ 1 => 5
67
+ }
68
+ }
69
+ }
70
+ end
71
+
72
+ it { expect { subject }.to change { state.hash[:array][1] }.from(2).to(5) }
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,3 +1,199 @@
1
- RSpec.describe Fie::Commander do
1
+ require 'securerandom'
2
+
3
+ RSpec.describe Fie::Commander, type: :channel do
4
+ before do
5
+ credentials = {
6
+ secret_key_base: 'c2c3f440e947a5592acaad052e756d87dd8db717275ef14ac794a3c2a07cbdaec8aa0df7a090c1bc83833736ee3f5209affe55639845871081d48598d57de3f7'
7
+ }
8
+
9
+ allow(Rails.application).to receive(:credentials) { credentials }
10
+ end
11
+
12
+ let(:controller_name) { 'home_controller' }
13
+ let(:action_name) { 'index' }
14
+ let(:state_params) { { 'view_variables' => view_variables, 'controller_name' => controller_name, 'action_name' => action_name } }
15
+ let(:view_variables) do
16
+ {
17
+ users: encrypt([
18
+ { name: 'eran', age: '20' },
19
+ '120'
20
+ ]),
21
+ primitive: encrypt('120'),
22
+ hash: encrypt({
23
+ array: [1, 2, 3],
24
+ primitive: '120'
25
+ })
26
+ }
27
+ end
28
+
29
+ let!(:connection) { stub_connection }
30
+ let!(:connection_uuid) { '92dbabc7-60af-4658-9cc5-277846d1f813' }
31
+ let!(:subscription) { subscribe identifier: connection_uuid }
32
+
33
+ before { subscription.singleton_class.class_variable_set(:@@pools_subjects, Set.new) }
34
+
35
+ describe '#params' do
36
+ describe ':identifier' do
37
+ context 'when connection_uuid == 92dbabc7-60af-4658-9cc5-277846d1f813' do
38
+ subject { subscription.params[:identifier] }
39
+ it { is_expected.to eq(connection_uuid) }
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'streams' do
45
+ context 'when connection_uuid == 92dbabc7-60af-4658-9cc5-277846d1f813' do
46
+ subject { streams }
47
+ it { is_expected.to include("commander_#{ connection_uuid }") }
48
+ end
49
+ end
50
+
51
+ describe '#initialize_state' do
52
+ let!(:initialize_state) { subscription.initialize_state(state_params) }
53
+ let(:redis_state) { redis.get("commander_#{ connection_uuid }") }
54
+
55
+ subject { subscription.state }
56
+
57
+ it { is_expected.to be_a(Fie::State) }
58
+ it { expect(redis_state).to_not be_blank }
59
+ end
60
+
61
+ describe '#unsubscribed' do
62
+ before { subscription.unsubscribed }
63
+ subject { redis.get("commander_#{ connection_uuid }") }
64
+
65
+ it('deletes state') { is_expected.to be_blank }
66
+ end
2
67
 
3
- end
68
+ describe '#initialize_pools' do
69
+ subject { subscription.initialize_pools }
70
+
71
+ context 'when subjects are :chat and :notifications' do
72
+ before { subscription.singleton_class.class_variable_set :@@pools_subjects, Set.new([:chat, :notifications]) }
73
+
74
+ it do
75
+ expect { subject }
76
+ .to have_broadcasted_to("commander_#{ connection_uuid }")
77
+ .with command: 'subscribe_to_pools', parameters: { subjects: ['chat', 'notifications']}
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#publish' do
83
+ let(:pool_subject) { :chat }
84
+ let(:object) { Object.new }
85
+
86
+ before { expect(Fie::Pools).to receive(:publish_lazy).with(pool_subject, object, connection_uuid) }
87
+
88
+ it { subscription.publish(pool_subject, object) }
89
+ end
90
+
91
+ describe '#state' do
92
+ before { subscription.initialize_state state_params }
93
+
94
+ let(:redis_state) { Marshal.load redis.get("commander_#{ connection_uuid }") }
95
+ subject { subscription.state.attributes }
96
+
97
+ it { is_expected.to eq(redis_state.attributes) }
98
+ end
99
+
100
+ describe '#state=' do
101
+ let(:state_object) do
102
+ Fie::State.new \
103
+ view_variables: view_variables,
104
+ controller_name: controller_name,
105
+ action_name: action_name,
106
+ uuid: connection_uuid
107
+ end
108
+
109
+ before { subscription.state = state_object }
110
+
111
+ it 'is expected to modify the state to the state object provided' do
112
+ expect(subscription.state.attributes).to eq(state_object.attributes)
113
+ end
114
+ end
115
+
116
+ describe '#modify_state_using_changelog' do
117
+ let(:objects_changelog) { { key: 'value' } }
118
+ let(:params) { { 'objects_changelog' => objects_changelog } }
119
+
120
+ before { expect_any_instance_of(Fie::State).to receive(:update_object_using_changelog).with(objects_changelog) }
121
+
122
+ it { subscription.modify_state_using_changelog(params) }
123
+ end
124
+
125
+ describe '#execute_js_function' do
126
+ let(:function_name) { 'console.log' }
127
+ let(:arguments) { ['print this in console.'] }
128
+
129
+ subject { subscription.execute_js_function(function_name, *arguments) }
130
+
131
+ it do
132
+ expect { subject }
133
+ .to have_broadcasted_to("commander_#{ connection_uuid }")
134
+ .with command: 'execute_function', parameters: { name: function_name, arguments: arguments }
135
+ end
136
+ end
137
+
138
+ describe '.commander_name' do
139
+ subject { Fie::Commander.commander_name(connection_uuid) }
140
+ it { is_expected.to eq("commander_#{ connection_uuid }") }
141
+ end
142
+
143
+ describe '.pool' do
144
+ before do
145
+ subscription.singleton_class.pool :chat do
146
+ puts @connection_uuid
147
+ puts @published_object
148
+ end
149
+ end
150
+
151
+ describe 'created callback' do
152
+ let(:object) { 123 }
153
+ let(:dumped_object) { Marshal.dump object }
154
+ subject { subscription.pool_chat_callback(object: dumped_object) }
155
+
156
+ it 'is expected to output @connection_uuid and @published_object' do
157
+ expect(STDOUT).to receive(:puts).with(connection_uuid)
158
+ expect(STDOUT).to receive(:puts).with(object)
159
+ subject
160
+ end
161
+ end
162
+ end
163
+
164
+ describe 'new method' do
165
+ let(:caller) { { 'value' => '15', 'id' => 'id', 'class' => 'class' } }
166
+
167
+ before do
168
+ subscription.define_singleton_method(:new_method) do |arg1:, arg2:|
169
+ puts @caller
170
+ puts @controller_name
171
+ puts @action_name
172
+ puts @connection_uuid
173
+ puts state.attributes
174
+ end
175
+
176
+ subscription.singleton_class.method_added(:new_method)
177
+ end
178
+
179
+ let(:new_method_parameters) do
180
+ {
181
+ 'caller' => caller,
182
+ 'controller_name' => controller_name,
183
+ 'action_name' => action_name,
184
+ 'arg1' => 123,
185
+ 'arg2' => 123
186
+ }
187
+ end
188
+
189
+ it 'should contain @caller, @controller_name, @action_name, and @connection_uuid instance variables and state method when called' do
190
+ expect(STDOUT).to receive(:puts).with(caller.symbolize_keys)
191
+ expect(STDOUT).to receive(:puts).with(controller_name)
192
+ expect(STDOUT).to receive(:puts).with(action_name)
193
+ expect(STDOUT).to receive(:puts).with(connection_uuid)
194
+ expect(STDOUT).to receive(:puts).with(subscription.state.attributes)
195
+
196
+ subscription.new_method(new_method_parameters)
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,62 @@
1
+ RSpec.describe Fie::Pools, type: :channel do
2
+ context 'when subject == "chat"' do
3
+ let(:pool_subject) { 'chat' }
4
+
5
+ describe 'subscription' do
6
+ subject { subscribe identifier: pool_subject }
7
+ it { is_expected.to_not be_blank }
8
+ it { is_expected.to be_a(Fie::Pools) }
9
+ end
10
+
11
+ describe '.pool_name' do
12
+ subject { Fie::Pools.pool_name(pool_subject) }
13
+ it { is_expected.to eq("pool_#{ pool_subject }") }
14
+ end
15
+
16
+ describe '.publish_lazy' do
17
+ context 'when sender_uuid is "92dbabc7-60af-4658-9cc5-277846d1f813" && object is 123' do
18
+ let(:sender_uuid) { '92dbabc7-60af-4658-9cc5-277846d1f813' }
19
+ let(:object) { 123 }
20
+
21
+ subject { Fie::Pools.publish_lazy(pool_subject, object, sender_uuid) }
22
+
23
+ it do
24
+ expect { subject }
25
+ .to have_broadcasted_to("commander_#{ sender_uuid }")
26
+ .with command: 'publish_to_pool_lazy', parameters: { subject: pool_subject, object: Marshal.dump(object) }
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '.publish' do
32
+ context 'when object == 123' do
33
+ let(:object) { 123 }
34
+
35
+ context 'when sender is not specified' do
36
+ let(:sender_uuid) { nil }
37
+
38
+ subject { Fie::Pools.publish(pool_subject, object, sender_uuid: sender_uuid) }
39
+
40
+ it do
41
+ expect { subject }
42
+ .to have_broadcasted_to("pool_#{ pool_subject }")
43
+ .with command: 'publish_to_pool', parameters: { subject: pool_subject, object: Marshal.dump(object), sender_uuid: sender_uuid }
44
+ end
45
+ end
46
+
47
+ context 'when sender is specified' do
48
+ let(:sender_uuid) { '92dbabc7-60af-4658-9cc5-277846d1f813' }
49
+
50
+ subject { Fie::Pools.publish(pool_subject, object, sender_uuid: sender_uuid) }
51
+
52
+ it do
53
+ expect { subject }
54
+ .to have_broadcasted_to("pool_#{ pool_subject }")
55
+ .with command: 'publish_to_pool', parameters: { subject: pool_subject, object: Marshal.dump(object), sender_uuid: sender_uuid }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -57,7 +57,7 @@ RSpec.describe Fie::State do
57
57
  it { is_expected.to eq(state.attributes.to_json) }
58
58
  end
59
59
 
60
- describe 'permeate' do
60
+ describe '#permeate' do
61
61
  it 'should render an html template which is then sent over action cable' do
62
62
  expect(ApplicationController).to receive(:render).with(
63
63
  "#{ controller_name }/#{ action_name }",
@@ -76,7 +76,7 @@ RSpec.describe Fie::State do
76
76
  end
77
77
  end
78
78
 
79
- describe '`hash`' do
79
+ describe '#hash' do
80
80
  before { expect(state).to receive(:permeate) }
81
81
 
82
82
  context 'when setting value' do
@@ -91,7 +91,7 @@ RSpec.describe Fie::State do
91
91
  it { expect { delete_value }.to change { state.hash.count }.by(-1) }
92
92
  end
93
93
 
94
- describe 'primitive' do
94
+ describe '#primitive' do
95
95
  context 'when setting value' do
96
96
  subject { state.hash[:primitive] }
97
97
  let!(:change_hash_value) { state.hash[:primitive] = 'value' }
@@ -101,7 +101,7 @@ RSpec.describe Fie::State do
101
101
  end
102
102
  end
103
103
 
104
- describe '`users`' do
104
+ describe '#users' do
105
105
  before { expect(state).to receive(:permeate) }
106
106
 
107
107
  context 'when setting value' do
@@ -119,7 +119,7 @@ RSpec.describe Fie::State do
119
119
  it { is_expected.to eq('value') }
120
120
  end
121
121
 
122
- describe 'name attribute' do
122
+ describe '#name' do
123
123
  context 'when setting value' do
124
124
  subject { state.users[0][:name] }
125
125
  let!(:change_hash_value) { state.users[0][:name] = 'value' }
@@ -148,8 +148,8 @@ RSpec.describe Fie::State do
148
148
  end
149
149
  end
150
150
 
151
- describe 'attributes' do
152
- describe 'users' do
151
+ describe '#attributes' do
152
+ describe '#users' do
153
153
  subject { state.attributes['users'] }
154
154
 
155
155
  it { is_expected.to include a_hash_including(name: 'eran', age: '20') }
@@ -157,17 +157,31 @@ RSpec.describe Fie::State do
157
157
  it { is_expected.to include '120' }
158
158
  end
159
159
 
160
- describe 'primitive' do
160
+ describe '#primitive' do
161
161
  subject { state.attributes['primitive'] }
162
162
  it { is_expected.to eq('120') }
163
163
  end
164
164
 
165
- describe 'hash' do
165
+ describe '#hash' do
166
166
  subject { state.attributes['hash'] }
167
167
 
168
168
  it { is_expected.to include(array: [1, 2, 3]) }
169
169
  it { is_expected.to include(primitive: '120') }
170
170
  end
171
171
  end
172
+
173
+
174
+ describe '#inspect' do
175
+ subject { state.inspect }
176
+
177
+ it { is_expected.to include(state.to_s[0..-2]) }
178
+ it { is_expected.to include("users:") }
179
+ it { is_expected.to include(state.users.inspect) }
180
+ it { is_expected.to include("primitive:") }
181
+ it { is_expected.to include(state.primitive.inspect) }
182
+ it { is_expected.to include("hash:") }
183
+ it { is_expected.to include(state.hash.inspect) }
184
+ it { is_expected.to include('>') }
185
+ end
172
186
  end
173
187
  end
data/spec/rails_helper.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  require 'spec_helper'
3
3
 
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
4
7
  ENV['RAILS_ENV'] ||= 'test'
5
8
  require File.expand_path('../../config/environment', __FILE__)
9
+ require 'action_cable/testing/rspec'
10
+ require 'pry-rails'
6
11
  # Prevent database truncation if the environment is production
7
12
  abort("The Rails environment is running in production mode!") if Rails.env.production?
8
13
  require 'rspec/rails'
@@ -6,8 +6,8 @@ module HelperMethods
6
6
  def encrypt(value)
7
7
  encryptor.encrypt_and_sign Marshal.dump(value)
8
8
  end
9
-
10
- def decrypt(value)
11
- Marshal.load encryptor.decrypt_and_verify(value)
9
+
10
+ def redis
11
+ $redis ||= Redis.new
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0pa
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eran Peer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-08 00:00:00.000000000 Z
11
+ date: 2018-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,6 +130,66 @@ dependencies:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: 1.0.0
133
+ - !ruby/object:Gem::Dependency
134
+ name: action-cable-testing
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 0.3.1
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.3.1
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: 0.3.1
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.3.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.8.21
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 0.8.21
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: 0.8.21
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 0.8.21
173
+ - !ruby/object:Gem::Dependency
174
+ name: pry-rails
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: 0.3.6
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 0.3.6
183
+ type: :development
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: 0.3.6
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 0.3.6
133
193
  - !ruby/object:Gem::Dependency
134
194
  name: redis
135
195
  requirement: !ruby/object:Gem::Requirement
@@ -223,7 +283,9 @@ files:
223
283
  - lib/opal/fie/native/timeout.rb
224
284
  - lib/opal/fie/pool.rb
225
285
  - lib/opal/fie/util.rb
286
+ - spec/fie/changelog_spec.rb
226
287
  - spec/fie/commander_spec.rb
288
+ - spec/fie/pools_spec.rb
227
289
  - spec/fie/state_spec.rb
228
290
  - spec/rails_helper.rb
229
291
  - spec/spec_helper.rb
@@ -248,9 +310,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
310
  version: '0'
249
311
  required_rubygems_version: !ruby/object:Gem::Requirement
250
312
  requirements:
251
- - - ">"
313
+ - - ">="
252
314
  - !ruby/object:Gem::Version
253
- version: 1.3.1
315
+ version: '0'
254
316
  requirements: []
255
317
  rubyforge_project:
256
318
  rubygems_version: 2.5.2.1
@@ -259,7 +321,9 @@ specification_version: 4
259
321
  summary: Fie is a Rails-centric frontend framework running over a permanent WebSocket
260
322
  connection.
261
323
  test_files:
324
+ - spec/fie/changelog_spec.rb
262
325
  - spec/fie/commander_spec.rb
326
+ - spec/fie/pools_spec.rb
263
327
  - spec/fie/state_spec.rb
264
328
  - spec/rails_helper.rb
265
329
  - spec/spec_helper.rb