volt 0.8.22.beta2 → 0.8.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/app/volt/views/notices/index.html +1 -1
- data/lib/volt.rb +0 -51
- data/lib/volt/controllers/model_controller.rb +1 -1
- data/lib/volt/models/buffer.rb +75 -0
- data/lib/volt/models/model.rb +3 -87
- data/lib/volt/models/model_hash_behaviour.rb +6 -0
- data/lib/volt/page/bindings/each_binding.rb +2 -2
- data/lib/volt/page/bindings/template_binding.rb +4 -1
- data/lib/volt/page/channel.rb +25 -12
- data/lib/volt/spec/capybara.rb +45 -0
- data/lib/volt/spec/sauce_labs.rb +33 -0
- data/lib/volt/spec/setup.rb +10 -79
- data/lib/volt/volt/users.rb +72 -10
- data/volt.gemspec +3 -3
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6ab3bfaaaef61c6d01c04750b95167dcd80515c
|
4
|
+
data.tar.gz: 8ade7dbaa63ee162ee463880a559736e004ddeed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 937470848e406afe613e695d35f07b6c9a46bd4ddbd3e946c5b11327a1ea2a0d823bc111e4a40413db7c41681c1b31d61a235ff1e0862436386fe573a13aa206
|
7
|
+
data.tar.gz: f462b993fdc5a4f1a301131aaeae7767bd175e19478081417682542547d55c4109984f14b0426601fb21f03508fa578b3743bd15d845751c6a7e4e757d6ebae9
|
data/.travis.yml
CHANGED
@@ -10,7 +10,7 @@ env:
|
|
10
10
|
- secure: X95q9DUVJRLIoxd116xEbi/3xL85XiGbWdz0p5z/UawShQalMHxLfPNdU9u5gyw99LrgxTdPsJOTps8hB3vhzp8qIegrM8i2AICcicXC1QDOWi7McXSH9SBmE1AjhlyE/PLLHwLDeqfvwNMPAOrDH1GOisQp505D7SSXUZ9m0GI=
|
11
11
|
matrix:
|
12
12
|
- NO_BROWSER=true
|
13
|
-
- BROWSER=sauce OS="Windows 8" USE_BROWSER="Firefox" VERSION="33"
|
13
|
+
# - BROWSER=sauce OS="Windows 8" USE_BROWSER="Firefox" VERSION="33"
|
14
14
|
script: bundle exec rake
|
15
15
|
notifications:
|
16
16
|
webhooks:
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.22
|
1
|
+
0.8.22
|
@@ -5,7 +5,7 @@
|
|
5
5
|
{{ if channel.status == :reconnecting }}
|
6
6
|
<div class="notices alert alert-info">
|
7
7
|
Connection Lost... {{ channel.error }}...
|
8
|
-
{{ if channel.reconnect_interval }} Reconnecting in {{ (channel.
|
8
|
+
{{ if channel.reconnect_interval }} Reconnecting in {{ (channel.reconnect_in / 1000.0).round }} sec{{ end }}
|
9
9
|
</div>
|
10
10
|
{{ end }}
|
11
11
|
{{ if page._reconnected }}
|
data/lib/volt.rb
CHANGED
@@ -48,57 +48,6 @@ module Volt
|
|
48
48
|
def in_browser?
|
49
49
|
@in_browser
|
50
50
|
end
|
51
|
-
|
52
|
-
# Get the user_id from the cookie
|
53
|
-
def user_id
|
54
|
-
if Volt.client?
|
55
|
-
user_id_signature = $page.cookies._user_id
|
56
|
-
else
|
57
|
-
# Check meta for the user id and validate it
|
58
|
-
meta_data = Thread.current['meta']
|
59
|
-
if meta_data
|
60
|
-
user_id_signature = meta_data['user_id']
|
61
|
-
else
|
62
|
-
user_id_signature = nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
if user_id_signature.nil?
|
67
|
-
return nil
|
68
|
-
else
|
69
|
-
index = user_id_signature.index(':')
|
70
|
-
user_id = user_id_signature[0...index]
|
71
|
-
|
72
|
-
if RUBY_PLATFORM != 'opal'
|
73
|
-
hash = user_id_signature[(index+1)..-1]
|
74
|
-
|
75
|
-
# Make sure the user hash matches
|
76
|
-
if BCrypt::Password.new(hash) != "#{Volt.config.app_secret}::#{user._id}"
|
77
|
-
# user id has been tampered with, reject
|
78
|
-
raise "user id or hash has been tampered with"
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
return user_id
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# True if the user is logged in and the user is loaded
|
88
|
-
def user?
|
89
|
-
!!user
|
90
|
-
end
|
91
|
-
|
92
|
-
# Return the current user.
|
93
|
-
def user
|
94
|
-
user_id = self.user_id
|
95
|
-
if user_id
|
96
|
-
return $page.store._users.find_one(_id: user_id)
|
97
|
-
else
|
98
|
-
return nil
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
51
|
end
|
103
52
|
end
|
104
53
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Volt
|
2
|
+
module Buffer
|
3
|
+
|
4
|
+
def save!
|
5
|
+
# Compute the erros once
|
6
|
+
errors = self.errors
|
7
|
+
|
8
|
+
if errors.size == 0
|
9
|
+
save_to = options[:save_to]
|
10
|
+
if save_to
|
11
|
+
if save_to.is_a?(ArrayModel)
|
12
|
+
# Add to the collection
|
13
|
+
promise = save_to.append(attributes)
|
14
|
+
else
|
15
|
+
# We have a saved model
|
16
|
+
promise = save_to.assign_attributes(attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
return promise.then do |new_model|
|
20
|
+
if new_model
|
21
|
+
# Set the buffer's id to track the main model's id
|
22
|
+
attributes[:_id] = new_model._id
|
23
|
+
options[:save_to] = new_model
|
24
|
+
end
|
25
|
+
|
26
|
+
nil
|
27
|
+
end.fail do |errors|
|
28
|
+
if errors.is_a?(Hash)
|
29
|
+
server_errors.replace(errors)
|
30
|
+
end
|
31
|
+
|
32
|
+
promise_for_errors(errors)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
fail 'Model is not a buffer, can not be saved, modifications should be persisted as they are made.'
|
36
|
+
end
|
37
|
+
else
|
38
|
+
# Some errors, mark all fields
|
39
|
+
promise_for_errors(errors)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# When errors come in, we mark all fields and return a rejected promise.
|
44
|
+
def promise_for_errors(errors)
|
45
|
+
mark_all_fields!
|
46
|
+
|
47
|
+
Promise.new.reject(errors)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a buffered version of the model
|
51
|
+
def buffer
|
52
|
+
model_path = options[:path]
|
53
|
+
|
54
|
+
# When we grab a buffer off of a plual class (subcollection), we get it as a model.
|
55
|
+
if model_path.last.plural? && model_path[-1] != :[]
|
56
|
+
model_klass = class_at_path(model_path + [:[]])
|
57
|
+
else
|
58
|
+
model_klass = class_at_path(model_path)
|
59
|
+
end
|
60
|
+
|
61
|
+
new_options = options.merge(path: model_path, save_to: self).reject { |k, _| k.to_sym == :persistor }
|
62
|
+
model = model_klass.new({}, new_options, :loading)
|
63
|
+
|
64
|
+
if state == :loaded
|
65
|
+
setup_buffer(model)
|
66
|
+
else
|
67
|
+
parent.then do
|
68
|
+
setup_buffer(model)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
model
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/volt/models/model.rb
CHANGED
@@ -4,6 +4,7 @@ require 'volt/models/model_helpers'
|
|
4
4
|
require 'volt/models/model_hash_behaviour'
|
5
5
|
require 'volt/models/validations'
|
6
6
|
require 'volt/models/model_state'
|
7
|
+
require 'volt/models/buffer'
|
7
8
|
require 'volt/reactive/reactive_hash'
|
8
9
|
|
9
10
|
module Volt
|
@@ -16,6 +17,7 @@ module Volt
|
|
16
17
|
include ModelHashBehaviour
|
17
18
|
include Validations
|
18
19
|
include ModelState
|
20
|
+
include Buffer
|
19
21
|
|
20
22
|
attr_reader :attributes
|
21
23
|
attr_reader :parent, :path, :persistor, :options
|
@@ -155,7 +157,6 @@ module Volt
|
|
155
157
|
# (maybe move it to persistor, though thats weird since buffers don't have a persistor)
|
156
158
|
clear_server_errors(attribute_name) if @server_errors
|
157
159
|
|
158
|
-
|
159
160
|
# Don't save right now if we're in a nosave block
|
160
161
|
if !defined?(Thread) || !Thread.current['nosave']
|
161
162
|
# Let the persistor know something changed
|
@@ -217,18 +218,6 @@ module Volt
|
|
217
218
|
end
|
218
219
|
end
|
219
220
|
|
220
|
-
def return_undefined_method(method_name)
|
221
|
-
# Methods called on nil capture an error so the user can know where
|
222
|
-
# their nil calls are. This error can be re-raised at a later point.
|
223
|
-
fail NilMethodCall.new("undefined method `#{method_name}' for #{self}")
|
224
|
-
rescue => e
|
225
|
-
result = e
|
226
|
-
|
227
|
-
# Cleanup backtrace
|
228
|
-
# TODO: this could be better
|
229
|
-
result.backtrace.reject! { |line| line['lib/models/model.rb'] || line['lib/models/live_value.rb'] }
|
230
|
-
end
|
231
|
-
|
232
221
|
def new_model(attributes, options)
|
233
222
|
class_at_path(options[:path]).new(attributes, options)
|
234
223
|
end
|
@@ -279,80 +268,7 @@ module Volt
|
|
279
268
|
end
|
280
269
|
|
281
270
|
def inspect
|
282
|
-
|
283
|
-
"<#{self.class}:#{object_id} #{attributes.inspect}>"
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
def save!
|
288
|
-
# Compute the erros once
|
289
|
-
errors = self.errors
|
290
|
-
|
291
|
-
if errors.size == 0
|
292
|
-
save_to = options[:save_to]
|
293
|
-
if save_to
|
294
|
-
if save_to.is_a?(ArrayModel)
|
295
|
-
# Add to the collection
|
296
|
-
promise = save_to.append(attributes)
|
297
|
-
else
|
298
|
-
# We have a saved model
|
299
|
-
promise = save_to.assign_attributes(attributes)
|
300
|
-
end
|
301
|
-
|
302
|
-
return promise.then do |new_model|
|
303
|
-
if new_model
|
304
|
-
# Set the buffer's id to track the main model's id
|
305
|
-
attributes[:_id] = new_model._id
|
306
|
-
options[:save_to] = new_model
|
307
|
-
end
|
308
|
-
|
309
|
-
nil
|
310
|
-
end.fail do |errors|
|
311
|
-
if errors.is_a?(Hash)
|
312
|
-
server_errors.replace(errors)
|
313
|
-
end
|
314
|
-
|
315
|
-
promise_for_errors(errors)
|
316
|
-
end
|
317
|
-
else
|
318
|
-
fail 'Model is not a buffer, can not be saved, modifications should be persisted as they are made.'
|
319
|
-
end
|
320
|
-
else
|
321
|
-
# Some errors, mark all fields
|
322
|
-
promise_for_errors(errors)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
# When errors come in, we mark all fields and return a rejected promise.
|
327
|
-
def promise_for_errors(errors)
|
328
|
-
mark_all_fields!
|
329
|
-
|
330
|
-
Promise.new.reject(errors)
|
331
|
-
end
|
332
|
-
|
333
|
-
# Returns a buffered version of the model
|
334
|
-
def buffer
|
335
|
-
model_path = options[:path]
|
336
|
-
|
337
|
-
# When we grab a buffer off of a plual class (subcollection), we get it as a model.
|
338
|
-
if model_path.last.plural? && model_path[-1] != :[]
|
339
|
-
model_klass = class_at_path(model_path + [:[]])
|
340
|
-
else
|
341
|
-
model_klass = class_at_path(model_path)
|
342
|
-
end
|
343
|
-
|
344
|
-
new_options = options.merge(path: model_path, save_to: self).reject { |k, _| k.to_sym == :persistor }
|
345
|
-
model = model_klass.new({}, new_options, :loading)
|
346
|
-
|
347
|
-
if state == :loaded
|
348
|
-
setup_buffer(model)
|
349
|
-
else
|
350
|
-
parent.then do
|
351
|
-
setup_buffer(model)
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
model
|
271
|
+
"<#{self.class}:#{object_id} #{attributes.inspect}>"
|
356
272
|
end
|
357
273
|
|
358
274
|
# Takes a block that when run, changes to models will not save inside of
|
@@ -68,6 +68,12 @@ module Volt
|
|
68
68
|
(@attributes || {}).each_with_object(*args, &block)
|
69
69
|
end
|
70
70
|
|
71
|
+
def each(&block)
|
72
|
+
# TODO: We shouldn't need to check the size for this to work
|
73
|
+
size
|
74
|
+
@array.each(&block)
|
75
|
+
end
|
76
|
+
|
71
77
|
def each_pair
|
72
78
|
@attributes.each_pair do |k,v|
|
73
79
|
yield(k,v) unless v.is_a?(Model) && v.nil?
|
@@ -81,7 +81,7 @@ module Volt
|
|
81
81
|
|
82
82
|
# TODORW: :parent => @value may change
|
83
83
|
item_context = SubContext.new({ _index_value: position, parent: @value }, @context)
|
84
|
-
item_context.locals[@item_name.to_sym] = proc { @value[item_context.locals[:_index_value]]
|
84
|
+
item_context.locals[@item_name.to_sym] = proc { @value[item_context.locals[:_index_value]]}
|
85
85
|
|
86
86
|
position_dependency = Dependency.new
|
87
87
|
item_context.locals[:index_dependency] = position_dependency
|
@@ -127,7 +127,7 @@ module Volt
|
|
127
127
|
@computation = nil
|
128
128
|
|
129
129
|
# Clear value
|
130
|
-
@value =
|
130
|
+
@value = []
|
131
131
|
|
132
132
|
if @added_listener
|
133
133
|
@added_listener.remove
|
@@ -103,7 +103,10 @@ module Volt
|
|
103
103
|
Computation.run_without_tracking do
|
104
104
|
# Remove existing template and call _removed
|
105
105
|
controller_send(:"#{@action}_removed") if @action && @controller
|
106
|
-
|
106
|
+
if @current_template
|
107
|
+
@current_template.remove
|
108
|
+
@current_template = nil
|
109
|
+
end
|
107
110
|
|
108
111
|
@options = options
|
109
112
|
|
data/lib/volt/page/channel.rb
CHANGED
@@ -9,7 +9,7 @@ module Volt
|
|
9
9
|
include ReactiveAccessors
|
10
10
|
include Eventable
|
11
11
|
|
12
|
-
reactive_accessor :connected, :status, :error, :reconnect_interval, :retry_count
|
12
|
+
reactive_accessor :connected, :status, :error, :reconnect_interval, :retry_count, :reconnect_in
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
@socket = nil
|
@@ -45,11 +45,10 @@ module Volt
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def opened
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@retry_count = 0
|
48
|
+
self.status = :open
|
49
|
+
self.connected = true
|
50
|
+
self.reconnect_interval = nil
|
51
|
+
self.retry_count = 0
|
53
52
|
@queue.each do |message|
|
54
53
|
send_message(message)
|
55
54
|
end
|
@@ -66,16 +65,14 @@ module Volt
|
|
66
65
|
def reconnect!
|
67
66
|
self.status = :reconnecting
|
68
67
|
self.reconnect_interval ||= 0
|
69
|
-
self.reconnect_interval += (
|
68
|
+
self.reconnect_interval += (1000 + rand(5000))
|
70
69
|
self.retry_count += 1
|
71
70
|
|
72
71
|
interval = self.reconnect_interval
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}, interval);
|
78
|
-
`
|
73
|
+
self.reconnect_in = interval
|
74
|
+
|
75
|
+
reconnect_tick
|
79
76
|
end
|
80
77
|
|
81
78
|
def message_received(message)
|
@@ -102,5 +99,21 @@ module Volt
|
|
102
99
|
this.socket.close();
|
103
100
|
`
|
104
101
|
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def reconnect_tick
|
106
|
+
if reconnect_in >= 1000
|
107
|
+
self.reconnect_in -= 1000
|
108
|
+
`
|
109
|
+
setTimeout(function() {
|
110
|
+
self['$reconnect_tick']();
|
111
|
+
}, 1000);
|
112
|
+
`
|
113
|
+
else
|
114
|
+
connect!
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
105
118
|
end
|
106
119
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'volt/spec/sauce_labs'
|
2
|
+
|
3
|
+
module Volt
|
4
|
+
class << self
|
5
|
+
def setup_capybara(app_path)
|
6
|
+
browser = ENV['BROWSER']
|
7
|
+
|
8
|
+
if browser
|
9
|
+
setup_capybara_app(app_path)
|
10
|
+
|
11
|
+
case browser
|
12
|
+
when 'phantom'
|
13
|
+
Capybara.default_driver = :poltergeist
|
14
|
+
when 'chrome', 'safari'
|
15
|
+
# Use the browser name, note that safari requires an extension to run
|
16
|
+
browser = browser.to_sym
|
17
|
+
Capybara.register_driver(browser) do |app|
|
18
|
+
Capybara::Selenium::Driver.new(app, browser: browser)
|
19
|
+
end
|
20
|
+
|
21
|
+
Capybara.default_driver = browser
|
22
|
+
when 'firefox'
|
23
|
+
Capybara.default_driver = :selenium
|
24
|
+
when 'sauce'
|
25
|
+
setup_sauce_labs
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup_capybara_app(app_path)
|
31
|
+
require 'capybara'
|
32
|
+
require 'capybara/dsl'
|
33
|
+
require 'capybara/rspec'
|
34
|
+
require 'capybara/poltergeist'
|
35
|
+
require 'volt/server'
|
36
|
+
|
37
|
+
Capybara.server do |app, port|
|
38
|
+
require 'rack/handler/thin'
|
39
|
+
Rack::Handler::Thin.run(app, Port: port)
|
40
|
+
end
|
41
|
+
|
42
|
+
Capybara.app = Server.new(app_path).app
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Volt
|
2
|
+
class << self
|
3
|
+
def setup_sauce_labs
|
4
|
+
require "sauce"
|
5
|
+
require "sauce/capybara"
|
6
|
+
|
7
|
+
Sauce.config do |c|
|
8
|
+
if ENV['OS']
|
9
|
+
# Use a specifc OS, BROWSER, VERSION combo (for travis)
|
10
|
+
c[:browsers] = [
|
11
|
+
[ENV['OS'], ENV['USE_BROWSER'], ENV['VERSION']]
|
12
|
+
]
|
13
|
+
else
|
14
|
+
# Run all
|
15
|
+
c[:browsers] = [
|
16
|
+
# ["Windows 7", "Chrome", "30"],
|
17
|
+
# ["Windows 8", "Firefox", "28"],
|
18
|
+
["Windows 8.1", "Internet Explorer", "11"],
|
19
|
+
["Windows 8.0", "Internet Explorer", "10"],
|
20
|
+
["Windows 7.0", "Internet Explorer", "9"],
|
21
|
+
# ["OSX 10.9", "iPhone", "8.1"],
|
22
|
+
# ["OSX 10.8", "Safari", "6"],
|
23
|
+
# ["Linux", "Chrome", "26"]
|
24
|
+
]
|
25
|
+
end
|
26
|
+
c[:start_local_application] = false
|
27
|
+
end
|
28
|
+
|
29
|
+
Capybara.default_driver = :sauce
|
30
|
+
Capybara.javascript_driver = :sauce
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/volt/spec/setup.rb
CHANGED
@@ -1,88 +1,19 @@
|
|
1
1
|
module Volt
|
2
|
-
|
3
|
-
|
2
|
+
class << self
|
3
|
+
def spec_setup(app_path = '.')
|
4
4
|
require 'volt'
|
5
|
-
|
6
|
-
|
7
|
-
ENV['VOLT_ENV'] = 'test'
|
5
|
+
unless RUBY_PLATFORM == 'opal'
|
6
|
+
require 'volt/spec/capybara'
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
require 'capybara/dsl'
|
12
|
-
require 'capybara/rspec'
|
13
|
-
require 'capybara/poltergeist'
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'volt'
|
17
|
-
require 'volt/boot'
|
18
|
-
|
19
|
-
# Require in app
|
20
|
-
Volt.boot(app_path)
|
21
|
-
|
22
|
-
if ENV['BROWSER']
|
23
|
-
require 'volt/server'
|
24
|
-
|
25
|
-
Capybara.server do |app, port|
|
26
|
-
require 'rack/handler/thin'
|
27
|
-
Rack::Handler::Thin.run(app, Port: port)
|
28
|
-
end
|
29
|
-
|
30
|
-
Capybara.app = Server.new(app_path).app
|
31
|
-
|
32
|
-
if ENV['BROWSER'] == 'phantom'
|
33
|
-
Capybara.default_driver = :poltergeist
|
34
|
-
elsif ENV['BROWSER'] == 'chrome'
|
35
|
-
Capybara.register_driver :chrome do |app|
|
36
|
-
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
37
|
-
end
|
38
|
-
|
39
|
-
Capybara.default_driver = :chrome
|
40
|
-
elsif ENV['BROWSER'] == 'firefox'
|
41
|
-
|
42
|
-
# require 'selenium/webdriver'
|
43
|
-
# # require 'selenium/client'
|
44
|
-
#
|
45
|
-
Capybara.default_driver = :selenium
|
8
|
+
ENV['SERVER'] = 'true'
|
9
|
+
ENV['VOLT_ENV'] = 'test'
|
46
10
|
|
47
|
-
|
48
|
-
# Capybara::Selenium::Driver.new(app, :browser => :firefox)
|
49
|
-
# end
|
50
|
-
# Capybara.current_driver = :selenium_firefox
|
51
|
-
elsif ENV['BROWSER'] == 'safari'
|
52
|
-
# Needs extension
|
53
|
-
Capybara.register_driver :safari do |app|
|
54
|
-
Capybara::Selenium::Driver.new(app, browser: :safari)
|
55
|
-
end
|
56
|
-
Capybara.default_driver = :safari
|
57
|
-
elsif ENV['BROWSER'] == 'sauce'
|
58
|
-
require "sauce"
|
59
|
-
require "sauce/capybara"
|
11
|
+
require 'volt/boot'
|
60
12
|
|
61
|
-
|
62
|
-
|
63
|
-
# Use a specifc OS, BROWSER, VERSION combo (for travis)
|
64
|
-
c[:browsers] = [
|
65
|
-
[ENV['OS'], ENV['USE_BROWSER'], ENV['VERSION']]
|
66
|
-
]
|
67
|
-
else
|
68
|
-
# Run all
|
69
|
-
c[:browsers] = [
|
70
|
-
# ["Windows 7", "Chrome", "30"],
|
71
|
-
# ["Windows 8", "Firefox", "28"],
|
72
|
-
["Windows 8.1", "Internet Explorer", "11"],
|
73
|
-
["Windows 8.0", "Internet Explorer", "10"],
|
74
|
-
["Windows 7.0", "Internet Explorer", "9"],
|
75
|
-
# ["OSX 10.9", "iPhone", "8.1"],
|
76
|
-
# ["OSX 10.8", "Safari", "6"],
|
77
|
-
# ["Linux", "Chrome", "26"]
|
78
|
-
]
|
79
|
-
end
|
80
|
-
c[:start_local_application] = false
|
81
|
-
end
|
13
|
+
# Require in app
|
14
|
+
Volt.boot(app_path)
|
82
15
|
|
83
|
-
|
84
|
-
Capybara.javascript_driver = :sauce
|
85
|
-
end
|
16
|
+
setup_capybara(app_path)
|
86
17
|
end
|
87
18
|
end
|
88
19
|
end
|
data/lib/volt/volt/users.rb
CHANGED
@@ -1,18 +1,80 @@
|
|
1
1
|
module Volt
|
2
|
+
class << self
|
3
|
+
# Get the user_id from the cookie
|
4
|
+
def user_id
|
5
|
+
user_id_signature = self.user_id_signature
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
7
|
+
if user_id_signature.nil?
|
8
|
+
return nil
|
9
|
+
else
|
10
|
+
index = user_id_signature.index(':')
|
11
|
+
user_id = user_id_signature[0...index]
|
6
12
|
|
7
|
-
|
8
|
-
|
13
|
+
if RUBY_PLATFORM != 'opal'
|
14
|
+
hash = user_id_signature[(index+1)..-1]
|
9
15
|
|
10
|
-
|
11
|
-
|
16
|
+
# Make sure the user hash matches
|
17
|
+
if BCrypt::Password.new(hash) != "#{Volt.config.app_secret}::#{user._id}"
|
18
|
+
# user id has been tampered with, reject
|
19
|
+
raise "user id or hash has been tampered with"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
return user_id
|
25
|
+
end
|
12
26
|
end
|
13
|
-
end
|
14
27
|
|
15
|
-
|
16
|
-
|
28
|
+
# True if the user is logged in and the user is loaded
|
29
|
+
def user?
|
30
|
+
!!user
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return the current user.
|
34
|
+
def user
|
35
|
+
user_id = self.user_id
|
36
|
+
if user_id
|
37
|
+
return $page.store._users.find_one(_id: user_id)
|
38
|
+
else
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Login the user, return a promise for success
|
44
|
+
def login(username, password)
|
45
|
+
UserTasks.login(username, password).then do |result|
|
46
|
+
|
47
|
+
# Assign the user_id cookie for the user
|
48
|
+
$page.cookies._user_id = result
|
49
|
+
|
50
|
+
# Pass nil back
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def logout
|
56
|
+
$page.cookies.delete(:user_id)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# Fetches the user_id+signature from the correct spot depending on client
|
63
|
+
# or server, does not verify it.
|
64
|
+
def user_id_signature
|
65
|
+
if Volt.client?
|
66
|
+
user_id_signature = $page.cookies._user_id
|
67
|
+
else
|
68
|
+
# Check meta for the user id and validate it
|
69
|
+
meta_data = Thread.current['meta']
|
70
|
+
if meta_data
|
71
|
+
user_id_signature = meta_data['user_id']
|
72
|
+
else
|
73
|
+
user_id_signature = nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
user_id_signature
|
78
|
+
end
|
17
79
|
end
|
18
80
|
end
|
data/volt.gemspec
CHANGED
@@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency 'sass', '~> 3.2.5'
|
27
27
|
spec.add_dependency 'mongo', '~> 1.9.0'
|
28
28
|
spec.add_dependency 'rake', '~> 10.0.4'
|
29
|
-
spec.add_dependency 'listen', '~> 2.
|
30
|
-
spec.add_dependency 'uglifier', '
|
29
|
+
spec.add_dependency 'listen', '~> 2.8.0'
|
30
|
+
spec.add_dependency 'uglifier', '>= 2.4.0'
|
31
31
|
spec.add_dependency "configurations", "~> 2.0.0.pre"
|
32
|
-
spec.add_dependency 'yui-compressor', '
|
32
|
+
spec.add_dependency 'yui-compressor', '>= 0.12.0'
|
33
33
|
spec.add_dependency 'opal', '~> 0.6.0'
|
34
34
|
spec.add_dependency 'opal-jquery', '~> 0.2.0'
|
35
35
|
spec.add_dependency 'rspec-core', '~> 3.1.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.22
|
4
|
+
version: 0.8.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -114,26 +114,26 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.
|
117
|
+
version: 2.8.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
124
|
+
version: 2.8.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: uglifier
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: 2.4.0
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 2.4.0
|
139
139
|
- !ruby/object:Gem::Dependency
|
@@ -154,14 +154,14 @@ dependencies:
|
|
154
154
|
name: yui-compressor
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: 0.12.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 0.12.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
@@ -473,6 +473,7 @@ files:
|
|
473
473
|
- lib/volt/extra_core/true_false.rb
|
474
474
|
- lib/volt/models.rb
|
475
475
|
- lib/volt/models/array_model.rb
|
476
|
+
- lib/volt/models/buffer.rb
|
476
477
|
- lib/volt/models/cursor.rb
|
477
478
|
- lib/volt/models/model.rb
|
478
479
|
- lib/volt/models/model_hash_behaviour.rb
|
@@ -556,6 +557,8 @@ files:
|
|
556
557
|
- lib/volt/server/rack/source_map_server.rb
|
557
558
|
- lib/volt/server/socket_connection_handler.rb
|
558
559
|
- lib/volt/server/socket_connection_handler_stub.rb
|
560
|
+
- lib/volt/spec/capybara.rb
|
561
|
+
- lib/volt/spec/sauce_labs.rb
|
559
562
|
- lib/volt/spec/setup.rb
|
560
563
|
- lib/volt/store/mongo.rb
|
561
564
|
- lib/volt/tasks/dispatcher.rb
|
@@ -700,9 +703,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
700
703
|
version: '0'
|
701
704
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
702
705
|
requirements:
|
703
|
-
- - "
|
706
|
+
- - ">="
|
704
707
|
- !ruby/object:Gem::Version
|
705
|
-
version:
|
708
|
+
version: '0'
|
706
709
|
requirements: []
|
707
710
|
rubyforge_project:
|
708
711
|
rubygems_version: 2.2.2
|